<cmath> (math.h)

function
<cmath> <ctgmath>

log10

double log10 (double x);
     double log10  (double x);
      float log10f (float x);
long double log10l (long double x);
     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);
     double log10 (T x);           // additional overloads for integral types
Compute common logarithm
Returns the common (base-10) logarithm of x.

Header <tgmath.h> provides a type-generic macro version of this function.
This function is overloaded in <complex> and <valarray> (see complex log10 and valarray log10).
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations.

This function is also overloaded in <complex> and <valarray> (see complex log10 and valarray log10).

Parameters

x
Value whose logarithm is calculated.
If the argument is negative, a domain error occurs.

Return Value

Common logarithm of x.
If x is negative, it causes a domain error.
If x is zero, it may cause a pole error (depending on the library implementation).

If a domain error occurs, the global variable errno is set to EDOM.
If a pole error occurs, the global variable errno is set ERANGE.
If a domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

If a pole error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_DIVBYZERO is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* log10 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* log10 */

int main ()
{
  double param, result;
  param = 1000.0;
  result = log10 (param);
  printf ("log10(%f) = %f\n", param, result );
  return 0;
}


Output:

log10(1000.000000) = 3.000000

See also