Casting double to ulong weirdness
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 24 11:21:34 PDT 2015
On 08/24/2015 11:06 AM, rumbu wrote:
> BTW, 1.2 and 12.0 are directly representable as double
12 is but 1.2 is not.
> In C++:
>
> printf("%.20f\r\n", 1.2);
> printf("%.20f\r\n", 12.0);
>
> will output:
>
> 1.20000000000000000000
> 12.00000000000000000000
>
> Either upcasting to real is the wrong decision here, either the writeln
> string conversion is wrong.
Output is one thing. The issue is with the representation of 1.2. You
need infinite digits. D's %a helps with visualizing it:
import std.stdio;
void main()
{
writefln("%a", 1.2);
writefln("%a", 12.0);
}
Outputs
0x1.3333333333333p+0
0x1.8p+3
Ali
More information about the Digitalmars-d
mailing list