利用Python的特殊功能,简单实现万位高精度圆周率计算。
啥也别说了,直接给代码:
# -*- coding: UTF-8 -*-
# calculating PI with a simple series
# Author: Idealguy,Shanghai,2018
# pi=2*(1+1/3+1/3*2/5+1/3*2/5+3/7+...)
#
n=10000+4
p=2*10**n
a=p//3; p+=a
i=2
while a>0:
a=a*i//(i*2+1); i+=1
p+=a
p//=10000
print ("PI=",p)
计算结果(on Python 3.6.3 )
>>> ==================== RESTART: D:\Python\math\Pi-Simp2.py ====================
PI=
3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
9821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819
6442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127
3724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609
。。。。。。
4159613185434754649556978103829309716465143840700707360411237359984345225161050702705623526601