!!! 2.1, 2.2, 2.2.1, PYTHON BUGS ????

David K. Trudgett dkt at registriesltd.com.au
Thu May 30 20:13:30 EDT 2002


On Thursday 2002-05-30 at 14:22:47 +0000, Michael Hudson wrote:

> Read this:
> 
> http://www.python.org/doc/2.2.1/tut/node14.html
> 
> (the fact that I can type this URL from memory should be some
> indication that you could have answered your query yourself with a
> little effort).

Obviously, something has changed since Python 1.5.2:

Python 1.5.2
>>> 0.1
0.1
>>> 3.1*2
6.2
>>> sum = 0.0
>>> for i in range(10):
...     sum = sum + 0.1
...
>>> sum
1.0



Perl:

bash$ perl -e 'print 3.1*2 . "\n"'
6.2

bash$ perl -e '$sum = 0;foreach(1..10){$sum += 0.1}; print "$sum\n";'
1



Python 2.1.3

>>> 0.1
0.10000000000000001
>>>

>>> 3.1*2
6.2000000000000002
>>>

>>> sum = 0.0
>>> for i in range(10):
...     sum = sum + 0.1
... 
>>> sum
0.99999999999999989
>>>


Personally, I expect a scripting language to give me the right answer,
not the "correct" answer. For "correctness" I can use C.

I suppose arguments could be made on both sides...

David Trudgett








More information about the Python-list mailing list