[Issue 23856] The problem of accuracy loss in double division
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 24 14:44:57 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23856
--- Comment #3 from mzfhhhh at foxmail.com ---
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