C++ Standard Library C++ STL Library

C++ <cmath> - log10() Function



The C++ <cmath> log10() function returns the base-10 logarithm of a given number.

Syntax

double log10 (double x);
float log10 (float x);
long double log10 (long double x);
double log10 (double x);
float log10 (float x);
long double log10 (long double x);
//additional overloads for integral types 
double log10 (T x);                     

Parameters

x Specify the number.

Return Value

Returns the base-10 logarithm of a given number.
If the x is negative, domain error occurs.

Example:

In the example below, log10() function is used to calculate the base-10 logarithm of a given number.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<log10(10)<<"\n";
  cout<<log10(50)<<"\n";
  cout<<log10(100)<<"\n";
  return 0;
}

The output of the above code will be:

1
1.69897
2

❮ C++ <cmath> Library