Always false float comparisons

Joakim via Digitalmars-d digitalmars-d at puremagic.com
Thu May 19 07:15:18 PDT 2016


On Thursday, 19 May 2016 at 12:00:33 UTC, Joseph Rushton Wakeling 
wrote:
> On Thursday, 19 May 2016 at 11:33:38 UTC, Joakim wrote:
>> The example he refers to is laughable because it also checks 
>> for equality.
>
> With good reason, because it's intended to illustrate the point 
> that two calculations that _look_ identical in code, that 
> intuitively should produce identical results, actually don't, 
> because of under-the-hood precision differences.

And that's my point too, that floating point will always subvert 
your expectations, particularly such simplistic notions of 
equality, which is why you should always use approxEqual or it's 
analogues.


More information about the Digitalmars-d mailing list