log10(), log10f(), log10l() — Calculate base 10 logarithm

Standards

Standards / Extensions C or C++ Dependencies
ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99
both  

Format

#include <math.h>

double log10(double x);
float log10(float x);                  /* C++ only */
long double log10(long double x);      /* C++ only */
float log10f(float x);
long double log10l(long double x);

General description

Calculates the base 10 logarithm of the positive value of x.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

Returns the computed value.

If x is negative, the function sets errno to EDOM and returns -HUGE_VAL. If x is 0, the function returns -HUGE_VAL, and sets errno to ERANGE. If the correct value would cause an underflow, 0 is returned and the value ERANGE is stored in errno.

Special behavior for IEEE: If successful, the function returns the base 10 logarithm of the positive value of x.

If x is negative, the function sets errno to EDOM and returns NaNQ. If x is 0, the function returns -HUGE_VAL and errno remains unchanged.
Note: When environment variable _EDC_SUSV3 is set to 2, and if x is 0, the function returns -HUGE_VAL and sets errno to ERANGE.

Example

CELEBL09
/* CELEBL09                                      

   This example calculates the base 10 logarithm of 1000.0.                     
                                                                                
 */                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double x = 1000.0, y;                                                        
                                                                                
   y = log10(x);                                                                
                                                                                
   printf("The base 10 logarithm of %lf is %lf\n", x, y);                       
}                                                                               
Output
The base 10 logarithm of 1000.000000 is 3.000000

Related information