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

Math Expm1 Function

BLUF: Mastering Math Expm1 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 Expm1 Function

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

C++ Math expm1

The function calculates the value of the mathematical constant 'e' raised to the power of a specified number minus one.

Suppose a number is 'x'

Example

expm1(x) = e<sup>x</sup> - 1;

Syntax

Example

float expm1(float x);
double expm1(double x);
long double expm1(long double x);
double expm1(integral x);

Note: The return_type can be float, double or long double.

Parameter

x : It is the value of the exponent.

Return value

It returns 'e' raised to the power x minus -1.

Example 1

Let's see a simple example

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
   int x=6;
   std::cout << "Value of x is : " <<x <<std::endl;
   cout<<"expm1(x) = "<<expm1(x);
   return 0;
}

Output:

Output

Value of x is : 6
expm1(x) = 402.429

In this instance, the variable x is set to 6. The expm1 method calculates the result of 'e' raised to the power of 6 minus one.

Example 2

Let's see another simple example

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=9.8;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"expm1(x) = "<<expm1(x);
    return 0;
}

Output:

Output

Value of x is : 9.8
expm1(x) = 18032.7

In this instance, the value assigned to x is 9.8. The expm1 method calculates the result of 'e' raised to the power of 9.8 minus one.

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