expm1 Function

Calculates the exponential function of x, minus 1 (e raised to the power 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. On an overflow, expm1 returns inf and on an underflow expm1 returns 0.

Remarks

A range error occurs if the magnitude of x is too large.

Example

#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