# expf Function

Calculates the exponential function of x ( e x, where x is a single precision floating-point value).

Include

<math.h>

Prototype

float expf(float x);

Argument

 x floating-point value for which to return the exponential

Return Value

Returns the exponential of x. Infinity is returned on overflow; 0 is returned on underflow.

Remarks

A range error occurs if the magnitude of x is too large, and errno will be set to ERANGE.

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.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