expm1() in C++
The expm1(x) function returns ex – 1 where x is an argument and e is mathematical constant with value equal to 2.71828. Syntax:
double expm1() (double x); float expm1() (float x); long double expm1() (long double x);
- The expm1() function takes a single argument and computes e^x -1.
- The expm1() function returns e^x -1 if we pass x in the argument.
- It is mandatory to give both the arguments otherwise it will give error no matching function for call to ‘expm1()’.
- If we pass string as argument we will get error no matching function for call to ‘expm1(const char [n]).
- If we pass std::numeric_limits::max() we will get -2147483648.
Time Complexity: O(1)
Auxiliary Space: O(1)
Examples:
Input : expm1(5.35) Output : 209.608
Input : expm1(-5) Output : -0.993262
# CODE 1
CPP
// CPP implementation of the // above function #include <cmath> #include <iostream> using namespace std; int main() { double x = 5.35, answer; answer = expm1(x); cout << "e^" << x << " - 1 = " << answer << endl; return 0; } |
Output
e^5.35 - 1 = 209.608
# CODE 2
CPP
// CPP implementation of the // above function #include <cmath> #include <iostream> using namespace std; int main() { int x = -5; double answer; answer = expm1(x); cout << "e^" << x << " - 1 = " << answer << endl; return 0; } |
Output
e^-5 - 1 = -0.993262
Contact Us