float equality

spir denis.spir at gmail.com
Sat Feb 19 11:30:01 PST 2011


On 02/19/2011 02:41 PM, bearophile wrote:
> 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.

Right, but then what are we supposed to do?
For instance, if I have a whole binch of float actual results from a testsuite, 
how am I supoose to match them against expected results? (That's exactly the 
case which made me bump into the issue; thought my code was buggy, but the 
problem actually comes from float '=='.) How to solve that sensibly?

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list