www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17436] New: Weird `cast(double) i != cast(double) i` on

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

          Issue ID: 17436
           Summary: Weird `cast(double) i != cast(double) i` on 32-bit
                    hosts
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

```
import core.stdc.stdio;

void foo(I)(I x)
{
    const equal1 = (cast(double) x == cast(double) x);
    const f = cast(double) x;
    const equal2 = (f == x); // f == cast(double) x
    printf("%a, %a, equal1 = %d, equal2 = %d\n", f, cast(double) x, equal1 ? 1
: 0, equal2 ? 1 : 0);
}

void main()
{
    foo(long.max);  // 2^63-1 rounded up to 2^63
    foo(ulong.max); // 2^64-1 rounded up to 2^64
}
```

DMD 2.074 on Windows using `-m32` and `-m32mscoff` as well as on Linux x86
yield something like:

0x1p+63, 0x1p+63, equal1 = 1, equal2 = 0
0x1p+64, 0x1p+64, equal1 = 0, equal2 = 0

[Yep, the inconsistent results for long.max aren't a typo.]
With DMD 2.074 on Win64 and Linux x64 and with LDC on all of these platforms we
get the expected result:

0x1p+63, 0x1p+63, equal1 = 1, equal2 = 1
0x1p+64, 0x1p+64, equal1 = 1, equal2 = 1

Tracked down while investigating an LDC issue
(https://github.com/ldc-developers/ldc/issues/2086).

--
May 25