# C programming log10 ,log10f and log10l math.h

In C programming the <math.h> log ,logf and logl compute base-10 logarithm of the parameter.The declaration of the functions are given below.

1 float log10(float x);
2 double log10(double x);
3 long double log10(long double x);
4 float log10f(float x);
5 long double log10l(long double x);

Parameters:
x -A floating point value whose base-10 logarithmic value is to be computed.

Return type
floating point -The base-10 logarithm of x.

All the functions are the same,they compute the base-10 logarithm of the parameter.The 1st,2nd and the 3rd function have the same name i.e.’log10′.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) log10(x) is same as log10(10).

ii) If ‘x’ is negative value domain error occur.

iii) If ‘x’ is 0 range error occur.

iv)If NAN is passed ‘nan’ is returned ,if INFINITY is passed ‘inf’ is returned.

Code example

double d=5 , x1=-20 ;

float f=5 ;

long double ld=5 ;

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

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

Output in Visual Studio,

0.698970
0.698970
0.698970
-nan(ind)
-nan(ind)

If NAN(macro for NaN value) or negative value is passed as argument the returned value is ‘-nan(ind)’,this value means ‘not representable value’ or simply ‘NaN’.

#### log10f

The ‘log10f‘ 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 ‘log10f‘ stands for float and it signify the parameter and return type of the function.

Code example

float x=130 ;

printf(“%f”, log10( x ) ); //Calls the 1st version
printf(“\n%f”, log10f( 130 ) ); Calls the 4th version

Output in Visual Studio,

2.113943
2.113943

#### log10l

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

Code example

long double x=130 ;

printf(“%Lf”, log10( x ) ); //Calls the 3rd version
printf(“\n%Lf”, log10l( 130 ) ); Calls the 5th version

Output,

2.113943
2.113943