[Issue 14958] New: Casting a double to ulong sometimes produces wrong results
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Aug 24 09:48:47 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14958
Issue ID: 14958
Summary: Casting a double to ulong sometimes produces wrong
results
Product: D
Version: D2
Hardware: All
OS: Windows
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: marcioapm at gmail.com
import std.stdio;
void main() {
double x = 1.2;
writeln(cast(ulong)(x * 10.0));
double y = 1.2 * 10.0;
writeln(cast(ulong)y);
}
Output:
11
12
to!ulong instead of the cast does the right thing, and is a viable work-around.
--
More information about the Digitalmars-d-bugs
mailing list