[Issue 17436] Weird `cast(double) i != cast(double) i` on 32-bit hosts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 4 23:07:16 UTC 2020


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> ---
What's happening here is the conversion of ulong.max to double is done by the
x87. The computed value is cached in the x87, rather than rounded to double,
and reused. Hence, it is different than when stored to an intermediary double
and reloaded.

This does not occur on 64 bit targets because those do the calculation in 64
bit XMM registers, not the 80 bit x87 registers.

The compiler could force a round-to-64 after all operations by writing to
memory and then reloading it, but this would be execrably and unacceptably
slow. When you need and can afford the load/store, use:

https://dlang.org/phobos/core_math.html#.toPrec

wontfix

--


More information about the Digitalmars-d-bugs mailing list