gmp_printf output

Décio Luiz Gazzoni Filho decio at decpp.net
Thu Oct 19 15:06:36 CEST 2006


On Oct 19, 2006, at 6:01 AM, piix wrote:

> Although i got no errors while 'make check' these results are clearly
> wrong. Has somebody the same problem or a solution,

Go read a book on numerical analysis before you run around spouting  
bullshit about stuff you're ignorant on.

 From the manual (http://www.swox.com/gmp/manual/Floating_002dpoint- 
Functions.html):

``The mantissa in stored in binary, as might be imagined from the  
fact precisions are expressed in bits. One consequence of this is  
that decimal fractions like 0.1 cannot be represented exactly. The  
same is true of plain IEEE double floats. This makes both highly  
unsuitable for calculations involving money or other values that  
should be exact decimal fractions. (Suitably scaled integers, or  
perhaps rationals, are better choices.)''

Also, how about you try the same in plain old C? Using `float' as the  
base type, I get this:

value: 0.809999942779541015625
value: 0.656099915504455566406
value: 0.43046709895133972168
value: 0.185301929712295532227
value: 0.0343368053436279296875
value: 0.00117901619523763656616
value: 1.39007920552103314549e-06
value: 1.93232018927402826591e-12
value: 3.73386128571060753925e-24

Using `double', I get:

value: 0.810000000000000053291
value: 0.656100000000000127542
value: 0.430467210000000155556
value: 0.185302018885184244246
value: 0.0343368382029251781318
value: 0.00117901845777386199594
value: 1.39008452377145591626e-06
value: 1.93233498322891526678e-12
value: 3.73391848741029191476e-24
value: 1.39421472706243633065e-47

But obviously that was too much work for you to try, right? Or you  
just assumed it was going to work OK, but you never tried, right?

Décio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20061019/8e0805bc/attachment.bin 


More information about the gmp-discuss mailing list