Floating point (in)accuracy?

Grant Edwards grante at visi.com
Wed Apr 25 14:31:14 EDT 2001


In article <9c6vmq02kec at news2.newsguy.com>, Alex Martelli wrote:

>> Apparently the python mailiing lists on python.org are blocked, so let
>> me ask here. Is there any good reason for the following behaviour to
>> be different on Python 1.5.2 and 2.0?
>    [snip]
>>   >>> 3.14
>>   3.14
>    [snip]
>>   >>> 3.14
>>   3.1400000000000001
>
>Yes: repr(x) where x is a float used to HIDE some digits
>(trying to provide a 'prettier' look), but that violates the
>mission of repr, which is to give you as much info as it can.

I presume that on typical platforms, it can't be guaranteed
that float(repr(x)) == x.

If you pickle a float and then un-pickle it on the same
platform are you guaranted to end up with the same binary
representation?

-- 
Grant Edwards                   grante             Yow!  People humiliating
                                  at               a salami!
                               visi.com            



More information about the Python-list mailing list