13-3 Computing the Digits of pi

This program demonstrates arbitrary-precision arithmetic by computing the digits of pi using the Borwein iteration algorithm first published by Jonathan Borwein and Peter Borwein in 1985:

Iteration #1 produces 8 correct decimal digits, iteration #2 produces 41 digits, iteration #3 produces 171 digits, iteration #4 produces 694 digits, and each subsequent iteration increases the number of correct digits by more than a factor of four. Because it needs to test for convergence, the program will do one more iteration than necessary.

This program computes the digits of pi in several phases, and each phase can consist of several tasks. It displays the current phase and task, the elapsed time hh:mm:ss of the previous phase, and the total elapsed time hh:mm:ss. (The total elapsed time does not include the time to display the digits of pi).

To ensure the accuracy of the last digits, the program computes with a scale equal to 0.5% more than the specified number of decimal digits.

To run the demo:

  1. Enter the number of decimal digits of pi to compute.
  2. Press the Run button.
  3. Press the Stop button at any time to stop the computation.

The original Java Applets do not run in modern browsers, but you can download the Java code and run it locally on your desktop. Check back for JavaScript and Python versions - coming soon!


Download Demos in Java