Current location - Education and Training Encyclopedia - Graduation thesis - How does modern computer calculate pi?
How does modern computer calculate pi?
Can be calculated in a programming language. The following is the python language:

pi=0.0

N= 100

foriinrange(N):

pi+=( 1/pow( 16,i)*(? 4/(8 * I+ 1)-2/(8 * I+4)- 1/(8 * I+5)- 1/(8 * I+6)))?

Print ('pi is {:. 10f})。 Format (pi))

Please copy the above code to the python language development environment and run it, and the result is as follows (the following figure shows the result of running the above code using python development environment Spyder): pi is 3. 14 15926536.

In daily life, we usually use 3. 14 to express pi for approximate calculation. The fractional part 3. 14 1592654 is enough for general calculation. Even if engineers or physicists want to make more accurate calculations, they only need to take the values to a few hundred decimal places at best.

1965, the British mathematician john wallis published a mathematical monograph, in which he deduced a formula and found that pi is equal to the product of infinite fractions.

References:

Baidu encyclopedia -pi