My Python is failing math.
Kent Frazier
kentfrazier at gmail.com
Wed Jan 12 02:59:19 UTC 2005
OK, this is really strange. I am using Hoary updated daily and Python
2.4-0ubuntu4. I like to use Python as a nice and powerful calculator
sometimes, but for some reason, my Python is getting the wrong answers
for equations involving decimals. It seems to behave consistently
with itself, but the answers it is giving are blatantly wrong. I have
included a snippet below as an example of its craziness.
$ python
Python 2.4 (#2, Jan 10 2005, 09:15:54)
[GCC 3.3.5 (Debian 1:3.3.5-6ubuntu1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.0/2
0.5
>>> 1-.9
0.099999999999999978
>>> .05*20
1.0
>>> .05*22
1.1000000000000001
>>> 1.0/4
0.25
>>> .9-.8
0.099999999999999978
>>> 1.9-.9
0.99999999999999989
Does anyone know why it might be doing this? I don't see how this
could be user error, but if I did it, I would like to undo it. It has
been this way for the last several days, and I had never run across it
before that, but I just recently started using python, so I can't say
how long it has been like this. Anyone else experiencing this?
Kent
More information about the ubuntu-users
mailing list