What this calculator does
This tool approximates the mathematical constant pi (π) using the classical method of Archimedes. For a circle of diameter 1, the circumference is exactly π. A regular polygon drawn snugly around the circle (circumscribed) has a perimeter slightly larger than π, while a regular polygon drawn inside the circle (inscribed) has a perimeter slightly smaller than π. By repeatedly doubling the number of sides, both perimeters squeeze toward π from above and below.
How to use it
Pick a starting polygon — a square (4-gon) or a hexagon (6-gon). Enter the number of doubling loops n; after n loops the polygon has \(4\cdot 2^{n}\) sides (square branch) or \(6\cdot 2^{n}\) sides (hexagon branch). Choose how many digits to display. The calculator stops early once the bounds agree to machine precision, so a large n is perfectly safe.
The formula explained
Let a be the circumscribed-polygon perimeter and b the inscribed-polygon perimeter. Each iteration applies $$a = \frac{2\,a\,b}{a+b},$$ the harmonic mean of the previous a and b, then $$b = \sqrt{a\,b},$$ the geometric mean of the new a and the old b. The square branch starts at \(a_0=4\) and \(b_0=2\sqrt{2}\approx 2.8284271\); the hexagon branch starts at \(a_0=2\sqrt{3}\approx 3.4641016\) and \(b_0=3\). At all times \(b < \pi < a\).
Worked example
Starting from a square: \(a_0=4\), \(b_0=2.82842712\). First loop gives $$a_1=\frac{2\cdot 4\cdot 2.82842712}{6.82842712}=3.31370850$$ and $$b_1=\sqrt{3.31370850\cdot 2.82842712}=3.06146746.$$ Second loop yields \(a_2\approx 3.18259788\), \(b_2\approx 3.12144515\). After about 25 doublings the bracket collapses to \(3.141592653589793\), the full double-precision value of π.
FAQ
Why a circle of diameter 1? Because then the circumference equals π exactly, so the polygon perimeters are direct estimates of π with no scaling.
Why does it stop before n loops? Standard double-precision arithmetic carries about 15–16 significant figures. Once a and b are identical to that precision, more loops cannot improve the answer, so iteration ends early.
Square or hexagon — which is better? Both converge to the same value. The hexagon starts closer to π, so it reaches a given accuracy in slightly fewer doublings.