Computers and π


In this exercise you will use a C++ program to redo, in a fraction of a second, the years of work of some of the worlds most famous mathematicians: calculate the value of π. You will then compare your result to one from a world class π calculating program, also written in C++.

This may seem like a silly trick, but it just one example of how much computers are doing every day to make our lives easier. It also shows the difference between a simple solution to a problem and a good solution. Much of Computer Science is concerned with this difference.


π, usually expressed as 3.14, should be a simple number. It is merely the ratio of the circumference of a circle to its diameter. Instead it is a complicated number that has long interested the smartest people on earth. Knowing the value to 7—10 places is enough for the most rigorous engineer. Knowing it to 20 places would satisfy most astrophysicists. And yet the brightest minds try to learn more from its infinitely unique digits. Perhaps answers to the mysteries of the universe are in there.

For a long time the only way to measure π was with geometry. This was a tedious and error prone process. Entire civilisations gave up and made do with a good guess: 3 or 3 1/8 (3.125).

One of our lab instructors who thinks he remembers Euclidean geometry tried this method. The best result after two hours of hard work was 3.124—he did not have a big enough compass, long enough ruler or large enough paper to do better.

Click to Enlarge

Later, the development of decimal notation, advanced algebra and calculus allowed people to discover much faster and precise ways to calculate π. One very famous and simple formula is the Machin formula, shown here. Many faster formulas exist.

Famous π Calculations
Archimedes3rd Century BCE

3.1419Greek Empire96 sided polygons - possibly killed by Roman soldiers while calculating a more precise value.
Ptolemy2nd Century CE

3.1417Roman Empire?
Zu Chongzhi & Zu Gengzhi5th Century CE

3.1415929 (355/113)Chinese Empire24,576 sided polygons
Madhava of Sangamagrama15th Century CE

13 placesIndiaMadhava series
al-Kashi15th Century CE

16 placesIran805 million sided polygons
Ludolf van Ceulen1610 CE

35 placesGermany32 billion sided polygons
William Shanks1873 CE

707 placesEnglandMachin's formula
D. F. Ferguson, Levi Smith, and John Wrench1949 CE

1,120 placesUSAMechanical calculator, Machin's formula plus a second one to double check (1 or 2 digits per day)
Reitwiesner, Neumann, and Metropolis1949 CE

2,037 placesUSAENIAC (1 or two digits per minute)
Takahashi, D., and Kanada, Dr. Y.1995 CE4,294,960,000 placesJapanGauss-Legendre (SUPER_PI uses their code but is limited to 33 million digits)
Takahashi, Dr. D.2009 CE2,576,980,377,524 placesJapanGauss-Legendre (SUPER_PI uses their code but is limited to 33 million digits)

William Shanks took 15 years to calculate his value for π, and it took 72 more years before D. F. Ferguson proved there was an error at the 527th digit using a mechanical calculator. Ferguson and his colleagues were the last people to calculate new digits of π without a programmable computer. The computer has made easy work of hard mathematics, but, as you will see in the exercise, technique still counts.


Fun Links


Blatner, D. (1997). The joy of [pi]. New York: Walker and Co.

Chris Hills. (2005). Calculate pi to one million decimal places. Retrieved 6/23, 2009, from

Smith, H. J. (2009). Computing pi. Retrieved 6/23, 2009, from (page expired).

Takahashi, D., & Kanada, Dr. Y. (1995). Super pi (Ver1.1e ed.). University of Tokyo: Retrieved from