首页 > 解决方案 > 在 Python 中处理大数(16 位)的对数和反对数操作

问题描述

a = math.log(123456789123456789)
b = exp(a)
print(int(round(abs(b))))

输出:

123456789123457168

做anitlog后有数据丢失请告诉我如何避免它

标签: python

解决方案


您可以使用Decimalfromdecimal模块来处理大量数字:

from decimal import Decimal


a = Decimal(123456789123456789).ln()
b = a.exp()
print(int(round(abs(b))))

Output:

123456789123456789

推荐阅读