[Issue 14958] Casting a double to ulong sometimes produces wrong results
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Aug 27 05:30:55 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14958
--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> ---
I understand that fp can vary based on compiler selection of instructions, and
this is one of those instances.
However, the type system doesn't reflect reality here. Even this prints 11:
writeln(cast(ulong)(cast(double)(x * 10.0)));
The cast to double is ignored because typeof(x * 10.0) *is* already double. But
it's not actually a double in generated code.
I think that's where I see there is an issue. Only when you actually assign it
to a double does it become concretely double.
The workaround (using to!ulong) may cease to work at some point also, because
inlining could remove that storage to a double.
--
More information about the Digitalmars-d-bugs
mailing list