Open In App

expm1, expm1f, expm1l Functions in C

Last Updated : 06 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Example:

double expm1(double arg);

float  expm1f(float arg);

long double expm1l(long double arg);

Syntax:

expm1(x);

exmp1f(x);

exmp1l(x);

Parameters:

Function Parameter
expm1(x) x ⇒ float
expm1f(x) x ⇒ double
expm1l(x) x ⇒ long double

Return Values:

1. If no error occurs:

Function Return Value
expm1(x) ex – 1 ⇒ float
expm1f(x) ex-1 ⇒ double
expm1l(x) ex – 1 ⇒ long double

2. If range error due to overflow occurs:

Function Return Value
expm1(x)  +HUGE_VAL
expm1f(x) +HUGE_VALF
expm1l(x) +HUGE_VALL

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.

Parameter Return Value
±0 ±0
NaN NaN
-∞ -1
+∞ +∞

Time Complexity: O(1)

Space Complexity: O(1)

Example 1: Below is the C program to implement exp1():

C




// C program to implement
// exp1()
#include <math.h>
#include <stdio.h>
 
// Driver code
int main()
{
    double arg = 2.2310233;
    printf("%lf\n",
            expm1(arg));
    return 0;
}


Output

8.309388

Example 2: Below is the C program to implement exp1f():

C




// C program to implement
// exp1f()
#include <math.h>
#include <stdio.h>
 
// Driver code
int main()
{
    float arg = 4.121;
    printf("%f\n",
            expm1f(arg));
    return 0;
}


Output

60.620819

Example 3: Below is the C program to implement exp1l():

C




// C program to implement
// exp1l()
#include <math.h>
#include <stdio.h>
 
// Driver code
int main()
{
    long double arg = 5.212323323441;
    printf("%Lf\n",
            expm1l(arg));
    return 0;
}


Output

182.519939

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads