floating point glitch

Piet van Oostrum piet at cs.uu.nl
Tue Sep 28 12:58:23 CEST 2004


>>>>> Paul Rubin <http://phr.cx@NOSPAM.invalid> (PR) wrote:

PR> Piet van Oostrum <piet at cs.uu.nl> writes:
PR> Nah, you can do that by printing everything as zero.
>> 
>> That would not maintain print/read consistency, i.e. if you read back the
>> printed value you don't get the original value.

PR> The current conversion doesn't have that property.

>>>> a=.66+1e-13
>>>> print a
PR>     0.66
>>>> b=0.66
>>>> a==b
PR>     False

That's because print uses str rather than repr:

>>> a=.66+1e-13
>>> a
0.66000000000010006
>>> print `a`
0.66000000000010006
>>> b=0.66000000000010006
>>> a==b
True

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list