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);

    Parameter:



  • The expm1() function takes a single argument and computes e^x -1.
  • Return:

  • The expm1() function returns e^x -1 if we pass x in the argument.

    Error and Exception:

  1. It is mandatory to give both the arguments otherwise it will give error no matching function for call to ‘expm1()’.
  2. If we pass string as argument we will get error no matching function for call to ‘expm1(const char [n]).
  3. If we pass std::numeric_limits::max() we will get -2147483648.

Examples:

Input : expm1(5.35)
Output : 209.608
Input : expm1(-5)
Output : -0.993262

# CODE 1

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

e^5.35 - 1 = 209.608

# CODE 2

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

e^-5 - 1 = -0.993262


My Personal Notes arrow_drop_up

pawanasipugmailcom

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.