The function is defined in <cmath> header file.
[Mathematics] ex - 1 = expm1(x) [C++ Programming]
expm1() prototype [As of C++ 11 standard]
double expm1(double x); float expm1(float x); long double expm1(long double x); double expm1(T x); // Here T is an integral type.
expm1() Parameters
The expm1() function takes a single mandatory argument (can be positive, negative or 0).
expm1() Return Value
The expm1() function returns the value in the range of [-1, ∞].
If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL
with the proper sign, and an overflow range error occurs.
Example 1: How expm1() works?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 2.19, result;
result = expm1(x);
cout << "e^" << x << " - 1 = " << result << endl;
return 0;
}
When you run the program, the output will be:
e^2.19 - 1 = 7.93521
Example 2: expm1() With Integral Type
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x = 4;
double result;
result = expm1(x);
cout << "e^" << x << " - 1 = " << result << endl;
return 0;
}
When you run the program, the output will be:
e^4 - 1 = 53.5982