A belated Happy Pi Day!

Honestly, is there any better way to spend a day (or two) on Pi Day (March 14 = “3.14”) than to write some code to compute the value of Pi?!

You may remember from your math coursework Newton’s Formula, which is easy to implement:

\pi = 6 \sum\limits_{n=0}^{\infty}\frac{(2n)!}{(2^{4n+1})(n!)^{2} (2n+1)}

Or, you may have seen the Monte Carlo method. You could “speed this up” using a CUDA GPU implementation, e.g., http://cacs.usc.edu/education/cs596/src/cuda/pi.cu:

Unfortunately, while these are easy to implement, they are terrible algorithms, converging on the value of Pi very, very slowly indeed–even using the parallelism of GPUs. Although I’ve read about Chudnovsky’s Formula, I never tried it, probably because I had my priorities wrong. Beside, all of these require an arbitrary precision math package, which I didn’t have.

But, it turns out there are some: MPIR (Multiple Precision Integers and Rationals), MPIR.NET, and LongCalc

So, I wish everybody a belated Pi Day with a simple C# program that uses LongCalc (Mpir.NET/MPIR).

3.1415926535897932384626433...

Leave a comment

Your email address will not be published.