English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ exp() function usage and example

C++ Library Function <cmath>

C ++in the exp() function

This function calculates and returns e raised to the power of x<cmath>defined in the header file.

ex = exp(x)

exp() prototype [from C ++ 11Standard starts]

double exp(double x);
float exp(float x);
long double exp(long double x);
double exp(T x); //For integer

The exp() function has only one parameter and returns an exponent value of type double, float, or long double.

exp() parameter

The exp() function takes a mandatory parameter and can be any value, i.e., negative, positive, or zero.

exp() return value

The exp() function returns values in the range [0, ∞].

If the size of the result is too large to be represented by the return type value, the function will return HUGE_VAL with the correct sign and an overflow range error will occur.

Example1: How the exp() function works in C ++in operation?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double x = 2.19, result;
	result = exp(x);
	cout << "exp(x) = " << result << endl;
	return 0;
}

The output when running the program is:

exp(x) = 8.93521

Example2: The exp() function with integer 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;
}

The output when running the program is:

exp(x) = 442413

C++ Library Function <cmath>