[Issue 18927] Regression: Number with real suffix "L" sometimes fails to compile

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 31 12:07:06 UTC 2018


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras at gmail.com
         Resolution|---                         |INVALID

--- Comment #2 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Beyond 16777216, not all integers are representable in a float, and
9007199254740992L is the same threshold for a double. This is because of how
the floating-point formats are designed, and not a language issue. Previous
behavior loses information and is bug prone, and a failure to compile gives
immediate feedback that the programmer is doing something wrong, and does not
generate invalid code.

For workarounds, T n = cast(T)20_000_001; works, as does 20_000_001.0, as
you've pointed out.

This test shows the actual limits:

unittest{
    static assert( __traits(compiles, { float a = 16777216; }));
    static assert(!__traits(compiles, { float b = 16777217; }));
    static assert( __traits(compiles, { double d = 9007199254740992L; }));
    static assert(!__traits(compiles, { double d = 9007199254740993L; }));
}

--


More information about the Digitalmars-d-bugs mailing list