Decimal类可以处理的最大数字是多少?
最大的幅度是无穷大:
>>> from decimal import Decimal>>> Decimal('Inf')Decimal('Infinity')
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')>>> dDecimal('9E+999999999999999999')
有效位数的数量取决于,
decimal.MAX_PREC例如,以
e给定的精度进行计算:
>>> from decimal import Context>>> Context(prec=60).exp(1)Decimal('2.71828182845904523536028747135266249775724709369995957496697')
常数(
MAX_EMAX,
MAX_PREC)仅与C实现有关。纯Python版本可以使用更大的值:
>>> 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')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)