[Issue 14958] Casting a double to ulong sometimes produces wrong results

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Aug 24 12:03:23 PDT 2015


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

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> ---
I'm not sure whether this is a bug or not, but the behavior comes down to the
conversion from real to double vs. to ulong.

This code can demonstrate:

import std.stdio;
void main() {
    double x = 1.2;
    double x2 = x * 10.0;
    real y = x * 10.0;
    real y2 = x2;
    double y3 = y;
    writefln("%a, %a, %a", y, y2, cast(real)y3);
}

This outputs:

0xb.ffffffffffffep+0, 0xcp+0, 0xcp+0

Showing that in real representation, the number is not exact, but when
converted to double, it does represent what is asked for. However, we know that
the conversion definitely is rounding somehow because the original number isn't
precise.

--


More information about the Digitalmars-d-bugs mailing list