Python/Mpmath:为什么大数除法时得不到小数点,而小数时却得到小数点

Python/Mpmath: Why don't I get any decimal points for large number division, but do for smaller numbers

为什么大数给我一个整数(或者至少没有小数点),而小数给我一堆小数点?我设置精度或声明变量的方式有误吗?

import math
from mpmath import *
mp.prec=1000

x = 5431526412865007456
print mpf((x)/6)

ACTUAL OUTPUT: 905254402144167909.0
WANTED OUTPUT: 905254402144167909.3333333333333333333333(…)

x = 5431526413
print mpf((x)/6.)

OUTPUT: 905254402.16666662693023681640625

尝试使用 mpf(x)/6mpf(x)/6.0。您的代码不起作用的原因是它使用 Python 的正常规则进行除法, 然后 将其转换为任意精度数字,而这首先将其转换所以除法是使用任意精度数学完成的。