#### Archived

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

# Calculating PI

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

## Recommended Posts

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

##### Share on other sites
I always thought its 22/7.

:-)

##### Share on other sites
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 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 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 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 on other sites
355/113 gives you some 6 decimal digits precision, so that''s about enough when you''re using 32bit float values anyway

http://www.cecm.sfu.ca/pi/

##### Share on other sites
I''ve seen people use atan(1)*4 for PI

##### 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 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}

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×