# C++ cmath exp2 function

The C++ <cmath> exp2,exp2f and exp2l compute the base-2 exponential of the given value.The declaration of the functions are given below.

1 float exp2(float x);
2 double exp2(double x);
3 long double exp2(long double x);
4 float exp2f(float x);
5 long double exp2l(long double x);

Parameters:
x – A floating point value.

Return type
floating point -The base-2 exponential value of x.

Some points to note:

i) exp2(x) is same as 2x.

ii) A range error may occur if the x value is very large.In MinGW 6.1 and VS 2015,if x=>1024 the range error seem to occur;I haven’t checked the value in Linux,if you are using it check the value.

iii) If the value of x=< -1075, the returned value is 0.

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

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

Code example

/*Passing floating point value and character*/
cout<< “exp2(7)=” << exp2(7) << endl ;

/*Passing x=>1024 */
cout<< “exp2(1024)=” << exp2(1024) << endl ;

/*Passing x=<-1075 */
cout<< “exp2(-1075)=” << exp2(-1075) << endl ;

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

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

Output

exp2(7)= 128
exp2(1024)= inf
exp2(-1075)= 0
exp2(NAN)= nan
exp2(INFINITY)= inf

#### exp2f and exp2l

*Note

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

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

Code example

#include <typeinfo>

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

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

Output

*exp2f
f
f
*exp2l
e (means ‘long double’)
e (means ‘long double’)