J
James Kanze
On 2008-01-28 21:05:53, James Kanze wrote:
Which boils down to "never use (in)equality comparison with
floating point numbers".
No, it doesn't boil down to that. It boils down to the fact
that you have to understand floating point, and how it works, to
use it correctly, and that simple testing isn't always
sufficient to be sure that the algorithm works.
OTOH, abs(((a + b) + c) - (a + (b + c))) < epsilon can be safe, with
appropriate choice of epsilon.
Comparing for exact equality can also be appropriate, in certain
cases. Similarly, the above won't necessarily help in many
cases.