Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ cmath expm1() function is used to return e raised to the power of specified number minus 1, i.e., ex-1. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282.

Syntax

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

Parameters

x Specify the exponent of e.

Return Value

Returns e raised to the power of specified number minus 1, i.e., ex-1.

Example:

In the below example, expm1() function is used to calculate e raised to the power of specified number minus one.

#include <iostream>
#include <cmath>

using namespace std;
 
int main (){
  cout<<expm1(2)<<"\n";
  cout<<expm1(-2)<<"\n";
  cout<<expm1(1.5)<<"\n";
  cout<<expm1(-1.5)<<"\n";  
  return 0;
}

The output of the above code will be:

6.38906
-0.864665
3.48169
-0.77687

❮ C++ <cmath> Library