This function is defined in <cmath> header file.
[Mathematics] ex = exp(x) [C++ Programming]
exp() prototype [As of C++ 11 standard]
double exp(double x); float exp(float x); long double exp(long double x); double exp(T x); // For integral type
The exp() function takes a single argument and returns exponential value in type double
, float
or long double
type.
Note: To learn more about float and double in C++, visit C++ float and double.
exp() Parameters
The exp() function takes a single mandatory argument and can be any value i.e. negative, positive or zero.
exp() Return value
The exp() function returns the value in the range of [0, ∞].
If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL with the proper sign, and an overflow range error occurs.
Example 1: How exp() function works in C++?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 2.19, result;
result = exp(x);
cout << "exp(x) = " << result << endl;
return 0;
}
When you run the program, the output will be:
exp(x) = 8.93521
Example 2: exp() function with integral type
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long int x = 13;
double result;
result = exp(x);
cout << "exp(x) = " << result << endl;
return 0;
}
When you run the program, the output will be:
exp(x) = 442413