小编osc*_*avo的帖子

math.exp(2)和math.e**之间的区别2

编程时,我注意到math.exp(2)和math.e**2的结果之间存在差异.如下所示,计算e ^ 1时不会出现这种差异.

不是一个经验丰富的程序员,我想知道为什么这有所不同?我认为它与四舍五入有关.python文档说math.exp(x)返回e**x,但这看起来并不完全正确.那么math.exp(x)操作怎么会不同math.e**x呢?

>>> math.exp(1)
2.718281828459045
>>> math.e**1
2.718281828459045
>>> math.exp(1)==math.e**1
True
>>> math.exp(2)
7.38905609893065
>>> math.e**2
7.3890560989306495
>>> math.exp(2)==math.e**2
False
>>> math.exp(100)
2.6881171418161356e+43
>>> math.e**100
2.6881171418161212e+43
>>> math.exp(100)==math.e**100
False
Run Code Online (Sandbox Code Playgroud)

python math exponent

8
推荐指数
2
解决办法
4900
查看次数

标签 统计

exponent ×1

math ×1

python ×1