我正在编写一个Python3 (64位)程序,使用64位Windows 10上的gmpy2模块计算pi到至少一百万位数字,我使用的是Chudnovsky算法。该系列算法是天才的,易于理解,易于实现。我遇到的问题是用gmpy2表示非常大的精确实数。
我把这个问题归结为一个非常简单的测试。
G 213
当我将mpfr转换为string和print时,我得到了类似的结果。
这里发生了什么,我如何从gmpy2中抽取一百万位数字的精度?
import gmpy2 # Get the gmpy2 library
print('max_precision =', gmpy2.get_max_precision())
print('emin_min =', gmpy2.get_emin_min())
print('emax_max =', gmpy2.get_emax_max())
gmpy2.get_context().precision = 1000000 + 3 # Set the precision context.
print(gmpy2.get_context())
million_string = 'million digits of pi. I didn't paste it here but you can get it from Eve Andersson's website here, http://www.eveandersson.com/pi/digits/1000000, you'll need to strip out the newlines'
print('string =', million_string)
million_pi = gmpy2.mpfr(million_string)
print('\n\nHere comes the mpfr...\n\n')
print(million_pi)在我的输出中,我得到了输出的最大值,mins,上下文,百万位pi字符串,以及大约300,000位π的数字(给予或接受)。我很想向您展示输出,但是系统指责我的格式很好的输出是代码,并且不允许我这样做。我想不出绕过它的方法。
发布于 2019-09-28 22:24:15
精度是以位而不是十进制数字指定的。每小数位都需要log(10)/log(2)位。1,000,003位将产生1000003*log(2)/log(10)或大约301,030.9位精确的十进制数字。
https://stackoverflow.com/questions/58124365
复制相似问题