6.11.53 expm1 Function

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

Include

<math.h>

Prototype

double expm1(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_VAL 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)
{
  double x, y;

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

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

  errno = 0;
  x = -1E3;
  y = expm1(x);
  if (errno)
    perror("Error");
  printf("The exponential of %f is %f\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