The ancients generally used the tangent circle method to calculate pi. In other words, the circumference of a circle is approximated by a regular polygon inscribed or circumscribed. Archimedes used a regular 96-sided polygon to get the precision of three decimal places of pi; Liu Hui uses a regular 3072 polygon to get a precision of 5 digits; Ludolph Van Ceulen obtained 35-bit accuracy by using regular 262-sided polygons. This geometry-based algorithm is computationally intensive, slow and thankless. With the development of mathematics, mathematicians have found many formulas for calculating pi intentionally or unintentionally in mathematical research. Here are some classic commonly used formulas. In addition to these classical formulas, there are many other formulas and formulas derived from these classical formulas, so I won't list them one by one.
Mackin formula This formula was discovered by John Mackin, a British astronomy professor, in 1706. He used this formula to calculate the pi of 100. Machin formula can get 1.4 decimal precision every time it is calculated. Because its multiplicand and dividend are not greater than long integers in the calculation process, it is easy to program on the computer.
Machin.c source program also has many arctangent formulas similar to Machin formula. Among all these formulas, Mackin's formula seems to be the fastest. Nevertheless, if we want to calculate more numbers, such as tens of millions, McKin's formula is not enough. The algorithm described below takes about one day to calculate on PC, and the precision of pi exceeding 1 100 million bits can be obtained. These algorithms are more complicated to implement with programs. Because the calculation process involves multiplication and division of two large numbers, FFT (Fast Fourier Transform) algorithm should be used. FFT can shorten the multiplication and division time of two large numbers from O(n2) to O(nlog(n)).
Ramanujan formula 19 14 Indian mathematician Srinivasa Ramanujan published a series of formulas for calculating pi in his paper, which is one of them. This formula can get the precision of 8 decimal places for each calculation. 1985, Gosper used this formula to calculate the digits of17,500,000 of pi. David, 1989