Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

shuks

Calculating PI

This topic is 5317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I was just curious to know how pi(3.1415....) is calculated. I always thought its 22/7.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I always thought its 22/7.

:-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
22/7 is a good aproximation I suppose, but 22/7 repeats whereas Pi is an irrational number. For all the calculations most people will do, using 22/7 will generally give you the same answer.

Share this post


Link to post
Share on other sites
There are a lot of ways of calculating PI, some geometrical and others analytical.

For instance you could work with n-polygons that are contained and containing a circle with radius 1. The greater n is, the better the proximity, and the closer the area of the two n-polygons will be to the area of that circle (which happens to be PI). Just compute the areas and you get an approximation of PI.

Or you could choose random numbers (a,b) between 0 and 1. You have pi/4 chances of a²+b² being smaller than 1. Just throw it 10000 times and you have a fair chance of having approximated pi to its 4th decimal.

Or you could use series that converge towards pi or values close to pi. If I remember correctly the sum of k² is PI²/6, the integral over R of exp( -x² ) is something like PI or sqrt(PI).

And you can use Stirling''s formula to have a quite fast convergent series towards sqrt(2PI). And I think Wallis integrals can help you as well.

Victor Nicollet, INT13 game programmer

Share this post


Link to post
Share on other sites
Fact is , PI = 22/7

anyway , it has an approximately decimal value as 3.14....

There is a value of first 15 million digit on PI value on the internet somewhere. I don''t know where either so you have to search it yourself.

^^''

Share this post


Link to post
Share on other sites
AP #3 : "22/7 repeats while PI is an irrational number"

You know, 22/7 being 22/7 (int/int) means it''s rational, no need for that repeating stuff

Share this post


Link to post
Share on other sites
PI=3 for sufficiently large values of 3.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
quote:
Original post by ToohrVyk
AP #3 : "22/7 repeats while PI is an irrational number"

You know, 22/7 being 22/7 (int/int) means it''s rational, no need for that repeating stuff


Ever heard about periodic values? Just because something is rational, that doesn''t mean there is a finite representation in the base of your choice (for example 1/3 is periodic in base 10 and 1/10 is periodic in base 2).
PI is a famously irrational number and, therefore, cannot be displayed by a fraction. 22/7 is an approximation for everyday life, not an exact value. If you want a more exact value, use n-polygon method described above or use on of the common mathematical definitions, like:
PI/2 := min{cos(x) = 0 AND x >= 0, x a real number}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!