Always false float comparisons

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat May 21 08:30:19 PDT 2016


On 20.05.2016 08:25, Walter Bright wrote:
> On 5/19/2016 12:49 AM, Max Samukha wrote:
>> People are trying to get across that, if they wanted to maximize
>> accuracy, they
>> would request the most precise type explicitly. D has 'real' for that.
>> This
>> thread has shown unequivocally that the semantics you are insisting on
>> is bound
>> to cause endless confusion and complaints.
>
> C++ programs do the same thing, and have for decades, and such behavior
> is allowed by the C++ Standard.
> ...

And reported as a gcc bug regularly, and there seems to be a flag to 
turn x87-induced strangeness off completely. Also, the C99 standard 
rules out compiler-specific results. (And allows the program to query 
whether it is being compiled with the set of flags it requires: 
https://en.wikipedia.org/wiki/C99#IEEE.C2.A0754_floating_point_support .)

> People have been confused by and complained about floating point
> behavior at least since I started programming 40 years ago.
> ...

That's mostly an incidental problem. (Sharing language syntax with 
non-rounding operations, needing to map to mis-designed hardware, etc.)

> I have not invented anything new here.
>

You may not have invented anything new, but the old invention is broken 
and in the (slow and painful) process of getting fixed. There is no 
reason to build new things that use the same principle, as there is 
already a better way available.


More information about the Digitalmars-d mailing list