<分区>
如何将默认 float 精度切换为另一个精度,也许是自定义精度?我需要这个,因为我做了一些计算,我发现我应该提高默认的浮点精度。
<分区>
如何将默认 float 精度切换为另一个精度,也许是自定义精度?我需要这个,因为我做了一些计算,我发现我应该提高默认的浮点精度。
最佳答案
我最近不得不处理这个问题和 mpmath很完美。它是纯 Python,遵循 BSD 许可。
Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work
它并没有慢很多,而且它可以利用 gmpy如果安装了库(支持快速多精度算术的 C 编码 Python 扩展模块
)。
关于python - 提高 float 的准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13442531/