On Monday, 19 March 2012 at 12:50:02 UTC, bearophile wrote:
James Miller:
writeln(v1 == 1); //false
writeln(v1 == 1.0); //false
writeln(v1 == 1.0f); //false
writeln(v1+1 == 2.0f); //true
Maybe I'd like to deprecate and then statically forbid the use
of == among floating point values, and replace it with a
library-defined function.
Bye,
bearophile
I feel I should expand on bearophile's statement here. Checking
for equality in a float is usually wrong. After performing
operations on a float the accuracy if the number changes. So
performing any operations could result in your result being off
by a fraction
I.e. v1 could be (I'm not being acurate here as to what it, print
it out and see)
1.0000000000000000000001
0.9999999999999999999987
I think there is a std.math function called frequal or something.