exp(), expf(), expl() — Calculate exponential function

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double exp(double x);
float exp(float x);                  /* C++ only */
long double exp(long double x);      /* C++ only */
float expf(float x);
long double expl(long double x);

General description

Calculates the exponent of x, defined as e**x, where e equals 2.17128128….
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

If successful, the function returns the calculated value.

If an overflow occurs, the function returns HUGE_VAL. If an underflow occurs, it returns 0. Both overflow and underflow set errno to ERANGE.

Example

CELEBE06
⁄* CELEBE06                                      

   This example calculates y as the exponential function of x.                  
                                                                                
 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double x, y;                                                                 
                                                                                
   x = 5.0;                                                                     
   y = exp(x);                                                                  
                                                                                
   printf("exp( %f ) = %f\n", x, y);                                            
}                                                                               
Output
exp( 5.000000 ) = 148.413159

Related information