The Python expm1 math function is to calculate the power of E (Where E is Euler’s number approximately equal to 2.71828) and subtracts One from it. In this section, we discuss how to use expm1 function with an example.
The syntax of the Python expm1 Function is
math.expm1(number);
Or we can simply say math.exp(number) – 1. Please refer to the exp and log functions for further reference.
Number: It can be a number or a valid numerical expression.
- If the number argument is a positive or negative number, it returns the output.
- If the number argument is not a number, the function return TypeError.
Python expm1 Function Example
The expm1 Function calculates the power of Euler’s number E and subtracts One from it. In this example, we use this one to find the power of e of different data types.
import math
Tup = (1.98, 20.26, 13.05, -40.95 , 0.45) # Tuple Declaration
Lis = [-10.98, 3.65, -9.59, -4.15 , 5.97] # List Declaration
print('EXPM1() Function on Positive Number = %.2f' %math.expm1(1))
print('EXPM1() Function on Negative Number = %.2f' %math.expm1(-1))
print('EXPM1() Function on Tuple Item = %.2f' %math.expm1(Tup[2]))
print('EXPM1() Function on List Item = %.4f' %math.expm1(Lis[2]))
print('EXPM1() Function on Multiple Number = %.4f' %math.expm1(10 + 20 - 15.65))
print('EXPM1() Function on String Value = ', math.expm1('3'))

In the last statement, We used it on the String value. And as we said before, it returns TypeError as output. Please refer to Tuple, List, and Math functions in Python.
Why use expm1() instead of exp(x) – 1?
If we are working with large numbers (away from zero), both the expm1() function and subtracting one from the exp() function return the same result. However, when we work with smaller numbers (near 0), the exp() function does not provide an accurate result.
In the following example, you can notice the precision value difference between expm1() and exp(x) – 1.
import math
x = 0.000000123
print(math.expm1(x))
print(math.exp(x) - 1)
1.230000075645003e-07
1.2300000751253037e-07
What is the inverse of expm1 in Python?
The inverse of the built-in expm1() function is the math log1p() function.
- The expm1() function e to the power of the given number minus 1 with high precision of the given parameter near 0. In short, expm1(x) = exp(x) + 1.
- log1p() function calculates the logarithmic value of the given number plus 1 with high precision for the given parameter near 0.
In the following example, we declared a floating-point number near 0. Next, we find e to the power of the given number (0.987). Next, utilized the log1p() function to reverse the exponential value.
import math
x = 0.987
y = math.expm1(x)
print(y)
lx = math.log1p(y)
print(lx)
1.6831728673858626
0.9870000000000001