Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xcodeNewbie

macrumors member
Original poster
Jul 1, 2011
65
0
I want to make an app that calculates pi to any decimal place, even 1,000,000. I don't care how long it takes the computer. I know the formula for pi is as follows:
pi / 4 = 4 * tan-1(1 / 5) - tan-1(1 / 239)
However, I am at a loss of how to do this.
 
You won't be able to use the standard C types such as double for this. You'll need an arbitrary-precision library like the GNU MP library http://gmplib.org/.

Have you search for code to do this? Surely it's been done before?
 
I want to make an app that calculates pi to any decimal place, even 1,000,000. I don't care how long it takes the computer. I know the formula for pi is as follows:
pi / 4 = 4 * tan-1(1 / 5) - tan-1(1 / 239)
However, I am at a loss of how to do this.

Using that formula, you'd first have to figure out how to calculate arctangents to arbitrarily long precision.

You might be better off using a series that converges to pi. Example google search terms:
pi series
pi convergent series

And the first step is probably to read the Wikipedia article on pi, which mentions series and even gives a simple example (Gregory series), which converges very slowly:
http://en.wikipedia.org/wiki/Pi

Also see:
http://en.wikipedia.org/wiki/Approximations_of_π
 
Last edited:
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.