[Issue 23856] The problem of accuracy loss in double division

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 24 14:49:32 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23856

--- Comment #4 from mzfhhhh at foxmail.com ---
(In reply to FeepingCreature from comment #1)
> Are you using the 32-bit version of dmd? The same thing happens with gcc if
> you -m32. I can't reproduce with the 64-bit version.

Test again, there are issues with both 32-bit and 64-bit

import std;

static void conv_err(double r)
{  
    ulong tmp = cast(ulong) ((cast(double) 50) / r);

    //dmd -m32 err.d , tmp = 19999
    //dmd -m64 err.d , tmp = 19999
    //ldc2 err err.d , tmp = 20000
    info(tmp);
}

static void conv_ok(double r)
{  
    double v = ((cast(double) 50) / r);
    ulong tmp = cast(ulong) v;

    //dmd -m32 err.d , tmp = 20000
    //dmd -m64 err.d , tmp = 20000
    //ldc2 err err.d , tmp = 20000
    info(tmp);
}

void main()
{ 
    double r = 0.0025; 
    conv_err(r);
    conv_ok(r);
}

--


More information about the Digitalmars-d-bugs mailing list