English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ log10Usage and examples of () function

C++ Library Function <cmath>

C ++The log10The () function returns the common logarithm of the parameter (base10logarithm to the base).

This function calculates<cmath>defined in the header file.

log10x = log10(x)

log10() prototype [from C ++ 11Standard library begins]

double log10 (double x);
float log10 (float x);
long double log10 (long double x);
double log10 (T x);  //is of integer type

log10() parameter

log10The () function uses a range of[0, ∞]is a single required parameter.

If the value is less than 0, then log10The () returns NaN (not a number).

log10The return value of ()

log10The () function returns the logarithm of a number to the base10logarithm to the base.

parameter (x)returns VALUE
x > 1Positive
x = 10
0 > x > 1Negative
x = 0-∞ (-infinity)
x < 0nan (not a number)

Example1log10How does it work?

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
	double x = 13.056, result;
	result = log10(x);
	cout << "log10(x) = " << result << endl;
	x = -3.591;
	result = log10(x);
	cout << "log10(x) = " << result << endl;
	return 0;
}

When running the program, the output is:

log10(x) = 1.11581
log10(x) = nan

Example2log with integer type10()

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
	int x = 2;
	double result;
	result = log10(x);
	cout << "log10(x) = " << result << endl;
	return 0;
}

When running the program, the output is:

log10(x) = 0.30103

C++ Library Function <cmath>