Today is March 14th, which means that it’s PI day!  So I’m going to talk about computing the number PI.

Years ago I wanted to use my computer to calculate the number PI and I assumed that it was just a matter of getting a formula for PI and just running through a loop that computed each digit for as many digits as I wanted.  Nope.  Not that easy.  The problem is that PI is not computed from left to right, it’s computed with a formula, like everything else in this world and you must create numbers and math functions that work with as many digits as you want to represent PI into.  For instance: If you wanted 1 million digits of PI, you need to be able to handle 1 million digit numbers.  This includes the math functions such as add, multiply, subtract and whatever functions you’ll need to compute PI.

Recently I rediscovered the method of calculating PI and I stumbled across this article: How to calculate 1 million digits of pi.  What’s nice about this article is that it discusses the method of computing PI using C#.  Dot Net includes a large number package called System.Numerics.BigInteger that can be set to use any number of digits and that’s what is used in the article.  I copied the code and compiled it and ran for different sizes of PI which computed in the following times:

5000 digits = 0.05 seconds

10,000 digits = 0.2 seconds

100,000 digits = 17.748 seconds

1,000,000 digits = 31.5 seconds

Next I wanted to know how long it would take to compute PI to 10 million or 100 million digits.  So I plotted all my time estimates onto a graph in Excel and performed a curve fit (using the power curve):

I purposely left out the 1,000,000 digit estimate and I set the “Forecast” to 1,000,000 to see if it came out to 31.5 seconds.  As you can see from the above diagram the number of seconds is about 1900, which is 31.66 minutes. The curve fitting formula is: y=3E-09x^1.9495.

Now, for:

10,000,000 digits = 36 hours

100,000,000 digits = 136 days

1 billion digits = 33 years

Oh what fun!  33 years!  I’m pretty sure I’ll have a faster computer long before that time is up.  I can’t even imagine running a personal computer 136 days straight.  I would have to “enhance” the program so that it can save intermediate values to the hard drive every once in a while so I can switch it off if I needed to, or to recover if the machine crashed or lost power.  Anyway, here’s 1 million digits of PI: pi_one_million_digits