Float compare broke!
Adam D. Ruppe
destructionator at gmail.com
Mon Jun 11 05:54:35 PDT 2012
It probably has to do with different rounding
with the constant and the assignment.
http://dlang.org/float.html
Check out the section: Floating Point Constant Folding
Different compiler settings, optimization
settings, and inlining settings can affect
opportunities for constant folding, therefore the
results of floating point calculations may differ
depending on those settings.
a == b is probably done by the bits at runtime which match
because it is the same assignment.
But a == i_f might be propagated down there as 80 bit compared
to 32 bit and thus be just slightly different.
When comparing floating point you want to consider a little
wiggle room to be ok due to little rounding error. This function
should help:
http://dlang.org/phobos/std_math.html#approxEqual
More information about the Digitalmars-d-learn
mailing list