Hi Bob, I did use floating point numbers by using 4.0/1.0 - 4.0/3.0 etc., though I did not declare it explicitly. Do you think it's better form/practice to explicitly declare it?
Regards, Sagar On Mon, Oct 17, 2011 at 9:10 PM, bob gailer <bgai...@gmail.com> wrote: > 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: 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 > >
<<image/png>>
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor