# C programming exp2,exp2f and exp2l

In C programming the <math.h> exp2,exp2f and exp2l function compute thebase-2 exponential of the 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.

All the functions are the same,they compute the base-2 exponential of ‘x’.The 1st,2nd and the 3rd function have the same name i.e.’exp2′.The 4th and 5th function have different names.What does having a different names mean is explained in detail 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 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

double d=10 , x1=1025 ;

float f=10 ;

long double ld=10 ;

printf(“%lf”, exp2( d ) ) ; //calls the 2nd version
printf(“\n%f”, exp2( f ) ) ; //calls the 1st version
printf(“\n%Lf”, exp2( ld ) ) ;//calls the 3rd version

printf(“\n%lf”, exp2( x1 ) ) ;
printf(“\n%lf”, exp2(NAN) ) ;

Output in Visual Studio ,

1024.000000
1024.000000
1024.000000
inf
inf

For the argument value 1025 the returned value is ‘inf'(infinity),this means a range error has occurred.

#### exp2f

The ‘exp2f‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘exp2f‘ stands for float and it signify the parameter and return type of the function.

Code example

float x=70 ;

printf(“%f”, exp2( x ) ); //Calls the 1st version
printf(“\n%f”, exp2f( 70 ) ); Calls the 4th version

Output,

1180591620717411303424.000000
1180591620717411303424.000000

#### exp2l

The ‘exp2l‘ function is same as the 3rd function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘expl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double x= 70 ;

printf(“%Lf”, exp2( x ) ); //Calls the 3rd version
printf(“\n%Lf”, exp2l( 70 ) ); //Calls the 5th version

Output,

1180591620717411303424.000000
1180591620717411303424.000000