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

Reply via email to