How to get largest possible precision? (Python - Decimal)

后端 未结 4 1027
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 11:04

I\'m using the Decimal class for operations that requires precision.

I would like to use \'largest possible\' precision. With this, I mean as precise as the system o

4条回答
  •  感动是毒
    2020-12-06 11:32

    The maximum precision of the Decimal class is a function of the memory on the device, so there's no good way to set it for the general case. Basically, you're allocating all of the memory on the machine to one variable to get the maximum precision.

    If the mathematical operation supports it, long integers will give you unlimited precision. However, you are limited to whole numbers.

    Addition, subtraction, multiplication, and simple exponents can be performed exactly with long integers.

    Prior to Python 3, the built-in long data type would perform arbitrary precision calculations. https://docs.python.org/2/library/functions.html#long

    In Python >=3, the int data type now represents long integers. https://docs.python.org/3/library/functions.html#int

    One example of a 64-bit integer math is implementation is bitcoind, where transactions calculations require exact values. However, the precision of Bitcoin transactions is limited to 1 "Satoshi"; each Bitcoin is defined as 10^8 (integer) Satoshi.

    The Decimal class works similarly under the hood. A Decimal precision of 10^-8 is similar to the Bitcoin-Satoshi paradigm.

提交回复
热议问题