This math scares me
Tim Churches
tchur at optushome.com.au
Tue Mar 13 13:39:06 EST 2001
Costas Menico wrote:
> >> Ok, I can see maybe division having problems. But why does addition of
> >> the two numbers below:
> >>
> >> 5.01+5.54
> >>
> >> give me this?
> >>
> >> 10.550000000000001
> >>
> >> I hope its some setting that can take care of this. I am using Python
> >> under Windows 98.
> >
> >It's worse than that. Try:
> >
> >>>> 5.01
> >5.0099999999999998
> >
I don't think anyone has mentioned Jurjen Bos' real-accurate module (see
ftp://ftp.python.org/pub/www.python.org/ftp/python/contrib-09-Dec-1999/DataStructures/).
Alas it doesn't fix the finite precision limitation which these
newfangled electric digital computer gizmos have when it comes to
floating point numbers, but it does make the limitation explicit, viz:
>>> import real
>>> a = real.r(5.01)
>>> b = real.r(5.54)
>>> a
5.010000000000000+-1
>>> b
5.540000000000000+-1
>>> a + b
10.549999999999997+-4
give-or-take-a-bit-ly y'rs - Tim C
More information about the Python-list
mailing list