Namespaces
Variants
Views
Actions

log10

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
log10
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       log10f( float arg );
(since C99)
double      log10( double arg );
long double log10l( long double arg );
(since C99)

Computes the common (base 10) logarithm of arg.

Contents

[edit] Parameters

arg - floating point value

[edit] Return value

Base 10 logarithm of arg.

Domain error occurs if arg is negative. NAN is returned in that case.

Range error occurs if arg is 0. -HUGE_VAL is returned in that case.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    printf("log10(10.0)     = %.1f\n", log10(10.0));
    printf("pow(10.0,1.0)   = %.1f\n", pow(10.0,1.0));        /* inverse of log10 */
    printf("log10(1.0)      = %.1f\n", log10(1.0));
    printf("log10(INFINITY) = %.1f\n", log10(INFINITY));
    printf("log10(NAN)      = %.1f\n", log10(NAN));
    printf("\n");
 
    /* domain error                       */
    /* "invalid" floating-point exception */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("log10(-1.0)   = %f\n", log10(-1.0));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
    printf("\n");
 
    /* pole error                                */
    /* "divide-by-zero" floating-point exception */
    /* same for log10(-0.0)                      */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("log10(0.0)    = %f\n", log10(0.0));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
 
    return 0;
}

Possible output:

log10(10.0)     = 1.0
pow(10.0,1.0)   = 10.0
log10(1.0)      = 0.0
log10(INFINITY) = inf
log10(NAN)      = nan
 
 
log10(-1.0)   = nan
Numerical argument out of domain
current exceptions raised:  FE_INVALID
 
log10(0.0)    = -inf
Numerical result out of range
current exceptions raised:  FE_DIVBYZERO

[edit] See also

computes natural (base e) logarithm (to base e) (ln(x))
(function) [edit]
raises a number to the given power (xy)
(function) [edit]