Calculates the exponential function of x (e raised to the power x where x is a single precision floating-point value).
Include
<math.h>
Prototype
float expf (float x);
Argument
x
Return Value
Returns the exponential of x
. On an overflow,
expf
returns inf
and on an underflow expf
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)
{
float x, y;
errno = 0;
x = 1.0F;
y = expf(x);
if (errno)
perror("Error");
printf("The exponential of %f is %f\n", x, y);
errno = 0;
x = 1.0E3F;
y = expf(x);
if (errno)
perror("Error");
printf("The exponential of %f is %f\n", x, y);
errno = 0;
x = -1.0E3F;
y = expf(x);
if (errno)
perror("Error");
printf("The exponential of %f is %f\n", x, y);
}
Example Output
The exponential of 1.000000 is 2.718282
Error: range error
The exponential of 1000.000000 is inf
Error: range error
The exponential of -1000.000000 is 0.000000