C++ Math exp()

Last Updated : 20 May 2026

Math exp() Function

In C++, the exp() function is defined in the <cmath> or <math.h> header file and is used to calculate the exponential value of a number. It computes the value of e raised to the power of the given number, where e is Euler’s number approximately equal to 2.71828.

The exp() function accepts integer, float, double, and long double values as input and returns the exponential result in the same floating-point type.

Suppose a number is x:

exp() = ex

Syntax

It has the following syntax.

Parameters

x: The value whose exponential value is to be calculated.

Return value

It returns the exponential value of type float, double or long double.

If value is too large, the function returns HUGE_VAL

Examples of the List exp() Function

Here, we are going to discuss several examples to demonstrate the List exp() Function Function.

Example 1: Calculate the Exponential Value of a Positive Number Using exp()

This example demonstrates how to calculate the exponential value when the input number is positive.

Output:

Value of x is : 0.2
Exponential value of x is : 1.2214

Explanation:

In this example, exp() function calculates the exponential value of x when the value of x is positive.

Example 2: Calculate the Exponential Value of a Negative Number Using exp()

This example demonstrates how to calculate the exponential value when the input number is negative.

Output:

Value of x is : -5.3
Exponential value of x is : 0.00499159

Explanation:

In this example, exp() function calculates the exponential value of x when the value of x is negative.

Example 3: Calculate the Exponential Value of Zero Using exp()

This example demonstrates how to calculate the exponential value of zero using the exp() function. The value of exp(0) is always equal to 1.

Output:

Value of x is : 0