The Wayback Machine - https://web.archive.org/web/20230830161940/https://www.geeksforgeeks.org/expm1-expm1f-expm1l-functions-in-c/
Related Articles
Open In App
Related Articles

expm1, expm1f, expm1l Functions in C

Improve Article
Improve
Save Article
Save
Like Article
Like

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:

FunctionParameter
expm1(x)x ⇒ float
expm1f(x)x ⇒ double
expm1l(x)x ⇒ long double

Return Values:

1. If no error occurs:

FunctionReturn 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:

FunctionReturn 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.

ParameterReturn Value
±0±0
NaNNaN
-∞-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.

Last Updated : 06 Feb, 2023
Like Article
Save Article
Similar Reads