Always false float comparisons

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon May 16 03:57:00 PDT 2016


On 5/16/2016 3:14 AM, Joseph Rushton Wakeling wrote:
> 1.2999999523162841796875
> 1.3000000000000000444089209850062616169452667236328125

Note the increase in correctness of the result by 10 digits.


> ... which is unintuitive, to say the least;

It isn't any less intuitive than:

    f + f + 1.3f

being calculated in 64 or 80 bit precision, which is commonplace, or for that 
matter:

    ubyte b = 200;
    ubyte c = 100;
    writeln(b + c);

giving an answer of 300 (instead of 44), which every C/C++/D compiler does.



More information about the Digitalmars-d mailing list