Always false float comparisons

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Sun May 15 14:36:00 PDT 2016


On Sunday, 15 May 2016 at 21:01:14 UTC, Walter Bright wrote:
>> Err... these kind of problems only applies to D.
>
> Nope. They occur with every floating point implementation in 
> every programming language. FP math does not adhere to 
> associative identities.

No. ONLY D give different results for the same pure function call 
because you bind the result to a "const float" rather than a 
"float".

Yes. Algorithms can break because of it.

> Ironically, the identity is more likely to hold with D's 
> extended precision for intermediate values than with other 
> languages.

No, it is not more likely to hold with D's hazard game. I don't 
know of a single language that doesn't heed a request to 
truncate/round the mantissa if it provides the means to do it.

I care about algorithms working they way I designed them to work 
and what I have tested them for. If I request rounding to a 24 
bit mantissa then I _expect_ the rounding to take place. And yes, 
it can break algorithms if you don't.



More information about the Digitalmars-d mailing list