# Compute π in Java

` M. Gallant 10/17/97    3/14/2022`

The trancendental number π (pi) which geometrically is the ratio of a circle circumference to the diameter, has been calculated to billions of digits (1991 Chudnovsky brothers USA) and more recently to 62.8 trillion digits (6/ 2021 Switzerland researchers) using various algorithms based on the rapidly convergent series and iterative procedures and supercomputers. π Day was founded in 1988 by Larry Shaw to celebrate this famous number.

The Greek letter π was first used to represent the exact perimeter to diameter ratio value of a circle by the mathematician William Jones in 1706. It was not known until Ferdinand von Lindemann's proof in 1882 that π is a trancendental number comprising a never ending sequence of numbers. One of the most significant very early advances in calculating π was achieved by John Machin (1706) who cleverly manipulated identities based on a series for the inverse tangent function (ATN) to arrive at:

π = 16ATN(1/5) - 4ATN(1/239)

and combining this identity with the series definition for ATN:

ATN(x) = x - x^3/3 + x^5/5 - x^7/7 ....

one can easily calculate π to high precision. Since the ATN function converges in a well-behaved and predictable way, π can be easily calculated to extended precision provided that one has access to large math arithmetic routines. JDK1.1 provides this basic capability in the java.Math.BigDecimal class.

The image below shows the standard system-output from a standalone Java application for calculating π to 500 significant digits (10 seconds on a 486dx2/66 and 1 second on a Pentium GXPro200; Using a Dell XPS 15 9510 Intel Core i7-11800H processor with 16GB ram, 5000 digits of π are calculated in about 1 sec). The user is prompted for the digits of precision to be used in the computation.

References:

Go Home ET