expm1, expm1f, expm1l Functions in C
expm1(), expm1f(), expm1l() were introduced with C99, and are available under the <math.h> header file. These are used to calculate the Euler’s Number, e (2.7182818) raised to a power equal to the provided parameter minus 1.0, i.e ex – 1.
expm1(x), expm1f(x), exmp1l(x) = ex – 1
double expm1(double arg);
float expm1f(float arg);
long double expm1l(long double arg);
|expm1(x)||x ⇒ float|
|expm1f(x)||x ⇒ double|
|expm1l(x)||x ⇒ long double|
1. If no error occurs:
|expm1(x)||ex – 1 ⇒ float|
|expm1f(x)||ex-1 ⇒ double|
|expm1l(x)||ex – 1 ⇒ long double|
2. If range error due to overflow occurs:
3. If range error due to underflow occurs: If a range error occurs due to underflow, the rounded result is returned.
4. Exceptional cases: The errors reported are handled as specified in math_errhandling.
Example 1: Below is the C program to implement exp1():
Example 2: Below is the C program to implement exp1f():
Example 3: Below is the C program to implement exp1l():
Why use expm1, expm1f, expm1l?
- These functions are more accurate than the expression ex – 1if x → 0.
- They are very useful for financial calculations, like calculating (small) interest rates, and for calculating the inverse of hyperbolic functions.