My Python is failing math.
Klaus Alexander Seistrup
kseistrup at gmail.com
Wed Jan 12 03:33:44 UTC 2005
It's been like that for "ages", perhaps starting with v2.1. Please
see the explanation in the Python FAQ:
http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate
On Tue, 11 Jan 2005 20:59:19 -0600, Kent Frazier <kentfrazier at gmail.com> wrote:
> 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?
--
Klaus Alexander Seistrup
SubZeroNet · Copenhagen · Denmark
More information about the ubuntu-users
mailing list