FP equality tests

so so at so.do
Tue Jan 18 08:47:25 PST 2011


> double x = 0.0;
> // ... code that may modify x
> if (x == 0.0) { ...
>
> So I test x to have the original exact value I have put inside it, but  
> this kind of code is not so safe.
>
> Having == among FP values in C isn't a strong enough justification. What  
> are the use cases to keep allowing == between built-in FP values in D2?

It is perfectly safe if you are aware of what you are asking.
We can't just judge it here with two lines, hard to see your intention.
Say you have a precomputed value and after some point you want to check if  
it is the value you are after, you need an exact comparison here.

Problem is using floating point without knowing that it is not accurate,  
and expecting mathematically correct results.
Even if we know it, there are still unsolved problems with it. High  
quality collision detection and response is one example.


More information about the Digitalmars-d mailing list