www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: log2 buggy or is a real thing?

reply bearophile <bearophileHUGS lycos.com> writes:
Do you know why is this program:

import std.stdio;
void main() {
    real r = 9223372036854775808UL;
    writefln("%1.19f", r);
}

Printing:
9223372036854775807.8000000000000000000

Instead of this?
9223372036854775808.0000000000000000000

Bye,
bearophile
Apr 04 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 04/04/2012 01:46 PM, bearophile wrote:
 Do you know why is this program:

 import std.stdio;
 void main() {
      real r = 9223372036854775808UL;
      writefln("%1.19f", r);
 }

 Printing:
 9223372036854775807.8000000000000000000

 Instead of this?
 9223372036854775808.0000000000000000000

 Bye,
 bearophile

Works correctly here. (x64 linux)
Apr 04 2012
prev sibling parent Don Clugston <dac nospam.com> writes:
On 04/04/12 13:46, bearophile wrote:
 Do you know why is this program:

 import std.stdio;
 void main() {
      real r = 9223372036854775808UL;
      writefln("%1.19f", r);
 }

 Printing:
 9223372036854775807.8000000000000000000

 Instead of this?
 9223372036854775808.0000000000000000000

 Bye,
 bearophile

Poor float->decimal conversion in the C library ftoa() function.
Apr 04 2012