# C++ cmath exp2 , exp2f , exp2l 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.

Parameters:
x – A floating point value.

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

The first function is called if the argument is float type.

The second function is called if the argument is double type.

The third function is called if the argument is long double type.

The 4th and 5th function arfe discussed below.

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 case of the 2nd function and using the MinGW/Gcc 8.1 and VS 2015, if x=>1024 the Range error seems to occur; I haven’t checked the value in Linux if you are using it check the value. For exp2f and exp2l the value where Range error occurs vary. Their respective values are given later.

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.

```/*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

## C++ exp2f

The 4th function 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.

The exp2f accept only float type argument. If the argument is not a float type then it is converted to float type.

The Rnage error occurs when the argument is larger than 127 in exp2f.

```cout<< exp2f( 23 ) << endl ;

cout<< exp2f( 127 )
<< "\n" << exp2f( 128 ) ;
```

Output,

8.38861e+06
1.70141e+38
inf

## C++ exp2l

The 5th function 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.

The exp2l accept only long double type argument. If the argument is not a long double type then it is converted to long double type.

The Rnage error occurs when the argument is larger than 16383 in exp2l.

```cout<< exp2l( 13 ) << endl ;

cout<< exp2l( 16383 )
<< "\n" << exp2l( 16384 ) ;
```

Output,

8192
5.94866e+4931
inf