6.11.54 expm1f Function
Calculates the exponential function of x
, minus 1, where
x
is a single precision floating-point value).
Include
<math.h>
Prototype
float expm1(float x);
Argument
x
- value for which to return the exponential
Return Value
Returns the exponential of x
, minus 1 (x
- 1). On a range overflow,
expm1
returns the value of the HUGE_VALF
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)
{
float x, y;
errno = 0;
x = 1.0;
y = expm1f(x);
if (errno)
perror("Error");
printf("The exponential of %f is %f\n", x, y);
errno = 0;
x = 1E3;
y = expm1f(x);
if (errno)
perror("Error");
printf("The exponential of %f is %f\n", x, y);
errno = 0;
x = -1E3;
y = expm1f(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