Math errors in python
Chris S.
chrisks at NOSPAM.udel.edu
Sun Sep 19 04:00:03 EDT 2004
Gary Herron wrote:
> 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?
Sqrt is a fair criticism, but Pi equals 22/7, exactly the form this
arithmetic is meant for. Any decimal can be represented by a fraction,
yet not all fractions can be represented by decimals. My point is that
such simple accuracy should be supported out of the box.
> 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.
So are our brains, yet we somehow manage to compute 12.10 + 8.30
correctly using nothing more than simple skills developed in
grade-school. You could theoretically compute an infinitely long
equation by simply operating on single digits, yet Python, with all of
its resources, can't overcome this hurtle?
However, I understand Python's limitation in this regard. This
inaccuracy stems from the traditional C mindset, which typically
dismisses any approach not directly supported in hardware. As the FAQ
states, this problem is due to the "underlying C platform". I just find
it funny how a $20 calculator can be more accurate than Python running
on a $1000 Intel machine.
More information about the Python-list
mailing list