C++ cmath log10,log10f and log10l function


The C++ <cmath> log10,log10f and log10l compute the 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.

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

/*Passing floating point value*/
cout<< “log10(4)=” << log10(4) << endl;

/*Passing -ve value */
cout<< “log10(-56)=” << log10(-56) << endl;

/*Passing 0 */
cout<< “log10(0)=” << log10(0) << endl;

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

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

Output

log10(4)= 0.60206
log10(-56)= nan
log10(0)= -inf
log10(NAN)= nan
log10(INFINITY)=inf



log10f and log10l

*Note

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

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

Code example

#include <typeinfo>

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

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

Output

*log10f
f
f
*log10l
e (means ‘long double’)
e (means ‘long double’)