While programming I noticed a difference between the result of math.exp(2) and math.e**2. As you can see below, this difference does not arise when calculating e^1.
Not being an experienced programmer, I wondered why this differs?
I assume it has something to do with rounding up. The python docs say that math.exp(x)
return e**x
, but this appears not to be precisely correct. So how come that the math.exp(x)
operation differs from 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