[Issue 9937] CTFE floats don't overflow correctly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 25 17:57:40 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9937



--- Comment #16 from bearophile_hugs at eml.cc 2013-04-25 17:57:36 PDT ---
(In reply to comment #8)
> There's a nice discussion here:
> 
> http://www.exploringbinary.com/double-rounding-errors-in-floating-point-conversions/

That's a nice article. I have converted his two examples to a single D program:


import std.stdio;

void main() {
    real   r = 0.5000000894069671353303618843710864894092082977294921875L;
    double d = 0.5000000894069671353303618843710864894092082977294921875;
    float  f = 0.5000000894069671353303618843710864894092082977294921875f;
    float fd = 0.5000000894069671353303618843710864894092082977294921875;

    writefln("r =  %a", r);
    writefln("d =  %a", d);
    writefln("f =  %a", f);
    writefln("fd = %a", fd);

    double r2 = 0.5000000298023224154508881156289135105907917022705078125L;
    double d2 = 0.5000000298023224154508881156289135105907917022705078125;
    float  f2 = 0.5000000298023224154508881156289135105907917022705078125f;
    float fd2 = 0.5000000298023224154508881156289135105907917022705078125;

    writefln("r2  = %a", r2);
    writefln("d2  = %a", d2);
    writefln("f2  = %a", f2);
    writefln("fd2 = %a", fd2);
}


It seems dmd on Windows lacks both rounding problems discussed there. Output
(the gdc and ldc tests are done on dpaste):

dmd 32 bit Windows:
r =  0x1.000002fffffffbfep-1
d =  0x1.000003p-1
f =  0x1.000002p-1
fd = 0x1.000002p-1
r2  = 0x1.000001p-1
d2  = 0x1.000001p-1
f2  = 0x1.000002p-1
fd2 = 0x1.000002p-1

GDC 2.060 64 bit Linux:
r = 0x8.000017ffffffep-4
d = 0x1.000003p-1
f = 0x1.000002p-1
fd = 0x1.000002p-1
r2 = 0x1.000001p-1
d2 = 0x1.000001p-1
f2 = 0x1.000002p-1
fd2 = 0x1.000002p-1

LDC 2.060 64 bit Linux:
r = 0x8.000017ffffffep-4
d = 0x1.000003p-1
f = 0x1.000004p-1
fd = 0x1.000004p-1
r2 = 0x1.000001p-1
d2 = 0x1.000001p-1
f2 = 0x1p-1
fd2 = 0x1p-1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list