[Tutor] A better way to estimate the value of Pi?

bob gailer bgailer at gmail.com
Mon Oct 17 17:40:39 CEST 2011


On 10/17/2011 6:31 AM, Sagar Shankar wrote:
> Hi, this is my first question to this group. I'm a beginner to 
> computer science and programming in Python. Am currently using John 
> Zelle's book - Python Programming: An introduction to computer science 
> to teach myself.
>
> In the book, there is an exercise to create a program that 
> approximates the value of Pi by using the series image.png

It is not crucial here - but you must recognize that your program uses 
floating point numbers, which  almost always are an approximation to the
"real" value.

For example (assuming decimal numbers):

 >>> 4/3.0
1.3333333333333333 (followed by an unending number of 0's).

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111017/9e7a92f7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 1843 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20111017/9e7a92f7/attachment-0001.png>


More information about the Tutor mailing list