math.expm1(x)
The math.expm1 function returns the number e (2.718281...) raised to the power indicated as an argument after subtracting 1 from the result obtained.
As indicated in the Python documentation, for small values of x the result obtained by math.expm1(x) is much more accurate than that obtained by math.exp(x) -1.
- x: Power to raise the number e. The function will return that result minus 1.
The math.expm1 function returns a real number.
We can calculate (e ** 2) -1 with the following code:
math.expm1(2)
6.38905609893065
For the value of x in the previous example, we can verify that the result of the math.expm1 function is equivalent to that obtained using the math.exp function (and subtracting 1) with the following code:
math.isclose(math.expm1(2), math.exp(2) -1)
True