Math errors in python

Gary Herron gherron at islandtraining.com
Sun Sep 19 09:39:23 CEST 2004


On Sunday 19 September 2004 12:18 am, Chris S. wrote:
> Jeremy Bowers wrote:
> > On Sat, 18 Sep 2004 16:50:16 +0000, Radioactive Man wrote:
> >>In python 2.3 (IDLE 1.0.3) running under windows 95, I get the
> >>following types of errors whenever I do simple arithmetic:
> >
> > Specifically (building on DogWalker's reply),
> > http://www.python.org/doc/faq/general.html#why-are-floating-point-calcula
> >tions-so-inaccurate
>
> Perhaps there's a simple explanation for this, but why do we go to the
> trouble of computing fractions when our hardware can't handle the
> result? If the decimal value of 1/3 is can't be represented in binary,
> then don't. We should use an internal representation that stores the
> numerator and denominator as separate integers.

That's called rational arithmetic, and I'm sure you can find a package
that implements it for you.  However what would you propose for
irrational numbers like sqrt(2) and transcendental numbers like PI?

While I'd love to compute with all those numbers in infinite
precision, we're all stuck with FINITE sized computers, and hence with
the inaccuracies of finite representations of numbers.

Dr. Gary Herron





More information about the Python-list mailing list