float equality

bearophile bearophileHUGS at lycos.com
Sat Feb 19 05:41:23 PST 2011


spir:

> Well, about consistency, I meant cases 2 vs 3.

Floating point values are not the real values you are used in mathematics. They are approximations, and generally for them associative and distributive properties don't hold:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Here you find more than enough about FPs:
http://cr.yp.to/2005-590/goldberg.pdf


> I guess what people mean in 99% cases is "conceptual" equality, right?

D is designed to behave like C when you write code that's compatible with C syntax. So you need to turn the normal equality into a syntax error and add another one if you want to change something.


> They don't care about internal representation if they are not forced to.

In a system language you are often supposed to care for the internal implementations too.


> And we may have a binEqual just for floats when someone really needs 
> binary repr equality? (I cannot impagine a use case, but well...)

There are few use cases, but they are not many.


> I any case, what value should one use as tolerance range for approxEqual?

I presume there are no good defaults for the number of shared bits.

Bye,
bearophile


More information about the Digitalmars-d mailing list