# C++ cmath expm1,expm1f and expm1l function

The C++ cmath expm1,expm1f and expm1l function compute the exponential of the argument minus 1.The declaration of the functions are given below.

1 float expm1(float x);
2 double expm1(double x);
3 long double expm1(long double x);
4 float expm1f(float x);
5 long double expm1l(long double x);

Parameters:
x – A floating point value.

Return type
Floating point -The base-e exponential of x minus 1.

Some points to note:
i) expm1(x) is same as ex-1.

ii)If x is very large range error occur.In MinGW 6.1 and VS 2015,if x=> 710 the range error seem to occur.

iii)If x is small , x=<-15 the function returns -1.

iv) If NAN is passed ‘nan’ is returned.If INFINITY is passed ‘infinity’ is returned.

v)If integer or character is passed the second version is called-the double version.

Code example

http://localhost:81/wordpress/?p=870&preview=true

/*Passing floating point value*/
cout<< “expm1(3)=” << expm1(3) << endl ;

/*Passing x=710 value*/
cout<< “expm1(710)=” << expm1(710) << endl ;

/*Passing x=-15 value*/
cout<< “expm1(-15)=” << expm1(-15) << endl ;

/*Passing NAN value*/
cout<< “expm1(NAN)=” << expm1(NAN) << endl ;

/*Passing INFINITY value*/
cout<< “expm1(INFINITY)=” << expm1(INFINITY) << endl ;

Output

expm1(3)= 19.0855
expm1(710)= inf
expm1(-15)= -1
expm1(NAN)= nan
expm1(INFINITY)= infinity

#### expm1f and expm1l

*Note

i)The 4th version expm1f is same as the 1st version float expm1(float).The ‘f‘ character stands for ‘float’ which signify the argument and return type of the function.

ii)The 5th version expm1l is same as the 3rd version long double expm1(long double).The ‘l‘ character stands for ‘long double’ which signify the argument and return type of the function.

Code example

#include <typeinfo>

/*expm1f */
cout<< “*expm1f\n”;
float f=2;
cout<< typeid( expm1f(2) ).name() << endl /*identify type of expm1f retunred value */
<< typeid( expm1(f) ).name() << endl; /*identify type of expm1(float) returned value */

/*expm1l*/
cout<< “*expm1l\n”;
long double ld=2;
cout<< typeid( expm1l(2) ).name() << endl /*indentify type of expm1l returned value */
<< typeid( expm1(ld) ).name() << endl; /*identify type of expm1(long double) returned value*/

Output

*expm1f
f
f
*expm1l
e (means ‘long double’)
e (means ‘long double’)

*Side Note

If BOOST library is used and the precision is set to 50 ,the smallest value expm1() can compiled is -37.For smaller values the returned value is always -1.