Casting double to ulong weirdness
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 24 18:37:45 PDT 2015
On Monday, 24 August 2015 at 16:52:54 UTC, Márcio Martins wrote:
> I'm posting this here for visibility. This was silently
> corrupting our data, and might be doing the same for others as
> well.
>
> 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.
>
> Issue: https://issues.dlang.org/show_bug.cgi?id=14958)
http://www.smbc-comics.com/?id=2999
More information about the Digitalmars-d
mailing list