Increasing floating point precision in Python

南楼画角 提交于 2019-12-05 07:35:23
albusshin

Try using Decimal.

Read Arbitrary-precision elementary mathematical functions (Python)original for more information

Python's float type maps to whatever your platform's C compiler calls a double (see http://en.wikipedia.org/wiki/IEEE_floating_point_number).

The Python standard library also comes with an arbitrary-precision decimal module, called decimal: http://docs.python.org/2/library/decimal.html

NPE

With Python's float, you get 15–17 digits of precision (if you are seeing fewer, you may need to use a different format specifier when printing).

If you need more, you'll need to use a different method (one that only uses integer arithmetic), or a different way to represent floating-point numbers.

See Python floating point arbitrary precision available?

Tim Peters

The Leibniz formula converges extremely slowly - honestly, you won't live long enough for it get 12 digits of accuracy. Click here for one way to accelerate it enormously.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!