Why the nonsense number appears?

Ben O'Steen bosteen at maysubdivide.org
Mon Oct 31 11:01:55 CET 2005


On Mon, October 31, 2005 9:39, Sybren Stuvel said:
> Johnny Lee enlightened us with:
>> Why are there so many nonsense tails? thanks for your help.
>
> Because if the same reason you can't write 1/3 in decimal:
>
> http://docs.python.org/tut/node16.html
>
> Sybren
> --
> The problem with the world is stupidity. Not saying there should be a
> capital punishment for stupidity, but why don't we just take the
> safety labels off of everything and let the problem solve itself?
>                                              Frank Zappa
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I think that the previous poster was asking something different. I think
he was asking something like this:

If

>>> t1 = 0.500
>>> t2 = 0.461
>>> print t1-t2
0.039

Then why:

>>> t1 += 12345678910
>>> t2 += 12345678910
>>> # Note, both t1 and t2 have been incremented by the same amount.
>>> print t1-t2
0.0389995574951

It appears Yu-Xi Lim beat me to the punch. Using decimal as opposed to
float sorts out this error as floats are not built to handle the size of
number used here.

Ben




More information about the Python-list mailing list