# expm1l Function

Calculates the exponential function of x, minus 1, where x is a long double precision floating-point value).

Include

<math.h>

Prototype

long double expm1(long double x);

Argument

 x value for which to return the exponential

Return Value

Returns the exponential of x, minus 1 ( e x- 1). On a range overflow, expm1 returns the value of the HUGE_VALL macro.

Remarks

A range error occurs if x is too large, and errno will be set to ERANGE. This function may produce more accurate results compared to the expression exp(x) - 1 when the argument has a small magnitude.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
long double x, y;

errno = 0;
x = 1.0;
y = expm1l(x);
if (errno)
perror("Error");
printf("The exponential of %Lf is %Lf\n", x, y);

errno = 0;
x = 1E3;
y = expm1l(x);
if (errno)
perror("Error");
printf("The exponential of %Lf is %Lf\n", x, y);

errno = 0;
x = -1E3;
y = expm1l(x);
if (errno)
perror("Error");
printf("The exponential of %Lf is %Lf\n", x, y);
}

Example Output

The exponential of 1.000000 is 1.718282
Error: range error
The exponential of 1000.000000 is inf
Error: range error
The exponential of -1000.000000 is -1.000000