Math Exp Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Exp Function

Math Exp Function

BLUF: Mastering Math Exp Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Exp Function

C++ is renowned for its efficiency. Learn how Math Exp Function enables low-level control and high-performance computing in the tutorial below.

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:

Example

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.

Example

#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:

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.

Example

#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:

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.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience