What is the largest number a decimal class can handle?
The largest value is infinity:
>>> from decimal import Decimal >>> Decimal('Inf') Decimal('Infinity')
The largest representable final number on this platform depends on decimal.MAX_EMAX :
>>> from decimal import Context, MAX_EMAX >>> d = Context(Emax=MAX_EMAX, prec=1).create_decimal('9e'+str(MAX_EMAX)) >>> d.is_finite() True >>> d.next_plus() Decimal('Infinity') >>> d Decimal('9E+999999999999999999')
The number of significant digits depends on decimal.MAX_PREC , for example, to calculate e with a given accuracy:
>>> from decimal import Context >>> Context(prec=60).exp(1) Decimal('2.71828182845904523536028747135266249775724709369995957496697')
The constants ( MAX_EMAX , MAX_PREC ) are only applicable for the implementation of C. The Pure Python version can use larger values:
>>> from decimal import Context, MAX_EMAX >>> Context(Emax=MAX_EMAX+1, prec=1).create_decimal('9e'+str(MAX_EMAX+1)) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: valid range for Emax is [0, MAX_EMAX] >>> from _pydecimal import Context, MAX_EMAX >>> Context(Emax=MAX_EMAX+1, prec=1).create_decimal('9e'+str(MAX_EMAX+1)) Decimal('9E+1000000000000000000')
source share