On 10/17/2011 11:55 AM, Sagar Shankar wrote:

The "real" value of 4/3.0  is 1 followed by an unending number of 3's.

Each successive fraction's floating point value will be "off" by some
relatively small value. Those errors will probably add up.

Another limitation of floating point numbers is that there is a maximum and
a minimum exponent. Eventually the fractions will be too small to convert to
float, raising an overflow exception.

Allof this raises the question - what computer algorithms successively
approximate pi exactly?

--
Bob Gailer
919-636-4239
Chapel Hill NC



There are two separate problems with doing this operation in floats. One is that the final answer can be no closer than a float knows how to represent. But the second is the cumulative error caused by adding a bunch of values of differing magnitudes.

You can at least reduce the second by adding them in reverse order. In other words, build a list of floats for the terms of the series, then reverse the list and sum it.

--

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to