C++ Standard Library C++ STL Library

C++ <cmath> - exp() Function



The C++ <cmath> exp() function returns e raised to the power of specified number, i.e., ex. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282.

Syntax

double exp (double x);
float exp (float x);
long double exp (long double x);
double exp (double x);
float exp (float x);
long double exp (long double x);
//additional overloads for integral types
double exp (T x);                             

Parameters

x Specify the exponent of e.

Return Value

Returns e raised to the power of specified number.

Example:

In the example below, exp() function is used to calculate e raised to the power of specified number.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<exp(2)<<"\n";
  cout<<exp(-2)<<"\n";
  cout<<exp(1.5)<<"\n";
  cout<<exp(-1.5)<<"\n";  
  return 0;
}

The output of the above code will be:

7.38906
0.135335
4.48169
0.22313

❮ C++ <cmath> Library

5