Namespaces
Variants

log10, log10f, log10l

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
log10
(C99)
(C99) (C23)
(C23)
(C23)
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definido en el encabezado <math.h>
float log10f ( float arg ) ;
(1) (desde C99)
double log10 ( double arg ) ;
(2)
long double log10l ( long double arg ) ;
(3) (desde C99)
Definido en el encabezado <tgmath.h>
#define log10( arg )
(4) (desde C99)
1-3) Calcula el logaritmo común (base- 10 ) de arg .
4) Macro genérica de tipos: Si arg tiene tipo long double , log10l es llamado. De lo contrario, si arg tiene tipo entero o el tipo double , log10 es llamado. De lo contrario, log10f es llamado.

Contenidos

Parámetros

arg - valor de punto flotante

Valor de retorno

Si no ocurren errores, se devuelve el logaritmo común (base- 10 ) de arg ( log 10 (arg) o lg(arg) ).

Si ocurre un error de dominio, se devuelve un valor definido por la implementación (NaN donde esté soportado).

Si ocurre un error de polo, -HUGE_VAL , -HUGE_VALF , o -HUGE_VALL es devuelto.

Manejo de errores

Los errores se reportan como se especifica en math_errhandling .

Error de dominio ocurre si arg es menor que cero.

Puede ocurrir un error de polo si arg es cero.

Si la implementación soporta aritmética de punto flotante IEEE (IEC 60559),

  • Si el argumento es ±0, se devuelve -∞ y FE_DIVBYZERO se activa.
  • Si el argumento es 1, se devuelve +0
  • Si el argumento es negativo, se devuelve NaN y FE_INVALID se activa.
  • Si el argumento es +∞, se devuelve +∞
  • Si el argumento es NaN, se devuelve NaN.

Ejemplo

#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("log10(1000) = %f\n", log10(1000));
    printf("log10(0.001) = %f\n", log10(0.001));
    printf("base-5 logarithm of 125 = %f\n", log10(125) / log10(5));
    // special values
    printf("log10(1) = %f\n", log10(1));
    printf("log10(+Inf) = %f\n", log10(INFINITY));
    // error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("log10(0) = %f\n", log10(0));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_DIVBYZERO))
        puts("    FE_DIVBYZERO raised");
}

Salida posible:

log10(1000) = 3.000000
log10(0.001) = -3.000000
base-5 logarithm of 125 = 3.000000
log10(1) = 0.000000
log10(+Inf) = inf
log10(0) = -inf
    errno == ERANGE: Numerical result out of range
    FE_DIVBYZERO raised

Referencias

  • Estándar C23 (ISO/IEC 9899:2024):
  • 7.12.6.8 Las funciones log10 (p: TBD)
  • 7.25 Matemáticas genéricas de tipos <tgmath.h> (p: TBD)
  • F.10.3.8 Las funciones log10 (p: TBD)
  • Estándar C17 (ISO/IEC 9899:2018):
  • 7.12.6.8 Las funciones log10 (p: 179)
  • 7.25 Matemáticas genéricas de tipos <tgmath.h> (p: 272-273)
  • F.10.3.8 Las funciones log10 (p: 380)
  • Estándar C11 (ISO/IEC 9899:2011):
  • 7.12.6.8 Las funciones log10 (p: 245)
  • 7.25 Matemáticas genéricas de tipo <tgmath.h> (p: 373-375)
  • F.10.3.8 Las funciones log10 (p: 522)
  • Estándar C99 (ISO/IEC 9899:1999):
  • 7.12.6.8 Las funciones log10 (p: 225-226)
  • 7.22 Matemáticas genéricas de tipo <tgmath.h> (p: 335-337)
  • F.9.3.8 Las funciones log10 (p: 459)
  • Estándar C89/C90 (ISO/IEC 9899:1990):
  • 4.5.4.5 La función log10

Véase también

(C99) (C99)
calcula el logaritmo natural (base- e ) ( ln(x) )
(función)
(C99) (C99) (C99)
calcula el logaritmo en base 2 ( log 2 (x) )
(función)
(C99) (C99) (C99)
calcula el logaritmo natural (base- e ) de 1 más el número dado ( ln(1+x) )
(función)