C++ Math exp
The function calculates the value of the mathematical constant e raised to the power of the specified number.
Suppose a number is x:
Syntax
Consider a number 'x'. Syntax would be:
float exp(float x);
double exp(double x);
long double exp(long double x);
double exp(integral x);
Parameter
x : The value for which the exponential value needs to be computed.
Return value
It retrieves the exponential result of either a float, double, or long double data type.
If the value is excessively high, the function will yield HUGE_VAL.
Example 1
Let's examine a basic scenario where the value of x is greater than zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=0.2;
cout<<"Value of x is : "<<x<<'\n';
cout<<"Exponential value of x is : "<<exp(x);
return 0;
}
Output:
Value of x is : 0.2
Exponential value of x is : 1.2214
In this instance, the exp function computes the exponential result of x for positive x values.
Example 2
Let's examine a basic scenario where the value of x is below zero.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x= -5.3;
cout<<"Value of x is : "<<x<<'\n';
cout<<"Exponential value of x is : "<<exp(x);
return 0;
}
Output:
Value of x is : -5.3
Exponential value of x is : 0.00499159
In this instance, the exp function computes the exponential result of x in cases where x is a negative value.