Casting double to ulong weirdness
rumbu via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 24 10:49:12 PDT 2015
On Monday, 24 August 2015 at 17:26:12 UTC, Steven Schveighoffer
wrote:
>
> Note, this is NOT a D problem, this is a problem with floating
> ponit. And by problem, I mean feature-that-you-should-avoid :)
>
> -Steve
Visual C++ 19.00.23026, x86, x64:
int _tmain(int argc, _TCHAR* argv[])
{
double x = 1.2;
printf("%d\r\n", (unsigned long long)(x * 10.0));
double y = 1.2 * 10.0;
printf("%d\r\n", ((unsigned long long)y));
return 0;
}
Output:
12
12
Same output in debugger for an ARM Windows App.
C# 6.0:
static void Main(string[] args)
{
double x = 1.2;
WriteLine((ulong)(x * 10.0));
double y = 1.2 * 10.0;
WriteLine((ulong)y);
}
Output:
12
12
Same output in debugger for ARM in all flavours (Android, iOS,
Windows)
It seems like a D problem.
More information about the Digitalmars-d
mailing list