Question about creating and displaying mpf

Paul Zimmermann Paul.Zimmermann at loria.fr
Wed Sep 15 05:20:33 CEST 2010


> In Python I re-use the old Decimal interface, so I create gmpy.mpf
> objects like D('1.678')
> 
> When I print it out in C code, from the Python object, its printed as
> mpf('1.67800000000000000002e0')

remember MPF stores floating-point numbers in binary, and 1.678 is *not*
exactly representable in binary, which explains the "...2e0".

If you really want 1.678 to be exactly stored, you have to use *decimal*
floating-point arithmetic. See http://speleotrove.com/decimal/decnumber.html
for example.

Paul Zimmermann


More information about the gmp-discuss mailing list