please dont rip this site

Math Methods for Pi

Pi: the ratio of the circumference to the diameter of a circle. The number in decimal form apparently has no end and never repeats. It can only be approximated.

One can approximate to four decimal places (PI=3.1416 ) or to 8 decimal places PI=3.14159265 . The first approximation uses a denominator of 10000 and the second a denominator of 100,000,000

PI ~= 31416 / 10000 = 3.1416

PI ~= 314159265359 / 100000000000 = 3.14159265359

The denominator for the approximation does not have to be a power of 10. 22/7 is a good approximation; the denominator is 7. 355/113 is another good one.

PI ~= 22 / 7 = 3.142857142857

or

PI ~= 355 / 113 = 3.141592920354

355 / 113 is correct to six decimal places. PI can actually be approximated using any number in the denominator, and in general a larger number in the denominator allows you to make a better approximation.

For a computer, it is easist to work in powers of two. Using a denominator of 256 or 65536, the size of byte or word variables, simplifys the calculations required. The best approximations to PI with 65536 as the denominator is,

PI ~= 205888 / 65536 = 3 + 9280 / 65536 = 3.1416015625

which is 8.90891e-06 too high, or

PI ~= 205887/65536 = 3 + 9279/65536 = 3.141586303711

which is 6.349879e-06 too low, and therefore a little bit better. These are not as good an approximation as 355/113, but still good to several decimal places.

With a denominator of 256 the best we can hope for is:

PI ~= 804 / 256=3 + 36 / 256 = 3.140625

The point here is that we can divide by 256 by simply dropping the last byte of our value. We can divide by 65535 by dropping the last two bytes. So, if we have a math library that can multiply two 16 bit integer numbers and return a 32 bit integer result, we can find X*Pi by simply finding (X*3) + (X*9279) / 65535. Trying to find (X*205887)/65535 will not work because 205887 is larger than 16 bits. Trying to find X * (205887/65535) will not work because only integer math is involved; we would effectivly be asking for X * 3.

Of course, you can do the same thing with many other fractions or values having a fractional part.

Also:


file: /Techref/method/pi.htm, 2KB, , updated: 2008/6/10 16:16, local time: 2024/11/22 17:40,
TOP NEW HELP FIND: 
3.141.38.5:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/Techref/method/pi.htm"> Math Methods, Pi</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .