# Calculating PI to n-decimal places anyone?

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

## Recommended Posts

Hey I would like to know of a method to calculate PI to n-decimal places. Does anyone know a way an algorithm to do this? (PS: Please try and use as simple terms as I am still in highschool as it were(Standard 9/Grade 11). This is not homework!) Thank you in advance.

##### Share on other sites
the only method i know i to do the following.

PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11... ad infinitum.

in order to calculate PI to an arbitrary digit this way youd need arbitrary + something accurate floats though, and besides i doubt this is the fastest way.

id recommend mathworld, its bound to have a detailled explanation on this stuff.

##### Share on other sites
The problem with most methods is that they can converge quite slowly. I think some of the greatest methods for "fastest" methods for finding PI to any decimal place were perhaps due to Ramanujan. (feel free to correct me, i'm not saying i KNOW this to be in fact true, it's just my impression from reading stuff)

Take a look at the following links. They might get you going on some methods. The first link might be a little hard for you to read since you're still in highschool, bu the others are more "light".

http://en.wikipedia.org/wiki/Pi#Numerical_approximations_of_.26pi.3B

http://mathforum.org/library/drmath/view/58286.html

http://www.lbl.gov/Science-Articles/Archive/pi-algorithm.html
(http://www.lacim.uqam.ca/~plouffe/articles/Miraculous.pdf)

##### Share on other sites
Why do you want to be able to do this, could you not find a value off the internet and store it in a constant?

IIRC:

pi = circumference of a circle/diameter of a circle

so you could draw yourself a circle and measure the circ and diameter and the bung them in the formula.

##### Share on other sites
Thanks. I have the answer I needed to know

I just wanted to know the answer, in order to know it and then program it. I don't even care how fast it is. There is no point in having the fastest as the record is 51,539,600,000 decimal digits of PI. This is easy to program in java as there are classes which can handle numbers with any number of digits.
(BigInteger and BigDecimal)

Thanks.

##### Share on other sites
Quote:
 PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11... ad infinitum.

Note that this is:

4 * arctan(1)

##### Share on other sites
Quote:
Quote:
 PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11... ad infinitum.

Note that this is:

4 * arctan(1)

there are numerous ways to calculate Pi, the problem is finding one with arbitrary accuracy.

##### Share on other sites
The relevance is that arctan(x)=x-x^3/3+x^5/5-x^7/7+... so if you plug x=1 in all the x^n's become 1. That can lead you to p(n)=(8/[(4n-1)*(4n-3)]) * ([192n-44]/[5^(4n-1)] - [114240n-28559]/[239^(4n-1)]) by using it for 4*arctan(1/5)-arctan(1/239). That expansion will get you about three digits per term which is a little faster.

##### Share on other sites
If you have a way of calculating Sin() to arbitrary precision, which isnt all that hard (taylor expansion..) then this handy algorithm works quite well:

x[0] = 3
x[n+1] = x[n] + sin(x[n])

x starts as a first rough guess and converges on pi pretty rapidly.. 3 iterations will fill a 64-bit IEEE float with pi

certainly not the fastest method, but a lot faster than the 'old school' expansion methods - and its quite simple.

- Rockoon

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013747
×