Calculate Pi

Discussion in 'iOS Programming' started by xcodeNewbie, Jul 12, 2011.

  1. xcodeNewbie macrumors member

    Jul 1, 2011
    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.
  2. jiminaus macrumors 65816


    Dec 16, 2010
    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

    Have you search for code to do this? Surely it's been done before?
  3. chown33, Jul 12, 2011
    Last edited: Jul 12, 2011

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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:

    Also see:π
  4. Loge macrumors 68030


    Jun 24, 2004

Share This Page