Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating Point Stability

Say I have two rational fractions a/b and c/d that are equal. a, b, c, and d can all be represented as 32 bit signed integers. if i do division with 64 bit floating point numbers will a/b == c/d always?

like image 882
benmmurphy Avatar asked May 22 '26 11:05

benmmurphy


1 Answers

There are cases where compiler optimizations will prevent the equality from being true even if the results are guaranteed identical. The original x86 floating point operations are performed on 80-bit registers; if you compare one of those to a stored 64-bit value it will probably compare unequal.

like image 188
Mark Ransom Avatar answered May 25 '26 07:05

Mark Ransom