log, logf, log10, log10f
Calcula los logaritmos.
double log(
double x
);
float log(
float x
); // C++ only
long double log(
long double x
); // C++ only
float logf(
float x
);
double log10(
double x
);
float log10(
float x
); // C++ only
long double log10(
long double x
); // C++ only
float log10f (
float x
);
Parámetros
- x
Valor cuyo logaritmo debe encontrar.
Valor devuelto
Las funciones de log devuelve el logaritmo natural (base e) de x si correctamente. Las funciones log10 devuelve el logaritmo base-10. Si x es negativo, estas funciones devuelven un definido, de forma predeterminada. Si x es 0, devuelve los INF (infinitos).
Entrada |
Excepción SEH |
Excepción de Matherr |
---|---|---|
± QNAN,IND |
ninguno |
_DOMAIN |
± 0 |
ZERODIVIDE |
_SING |
x < 0 |
INVALID |
_DOMAIN |
log y log10 tiene una implementación que utilice las extensiones 2 (SSE2) de Streaming SIMD. Vea _set_SSE2_enable para la información y las restricciones de utilizar la implementación SSE2.
Comentarios
C++ permite la sobrecarga, por lo que puede llamar a sobrecargas de log y de log10. En un programa de c., log y log10 toman y devuelven siempre un doble.
Requisitos
Rutina |
Encabezado necesario |
---|---|
log, logf, log10, log10f |
<math.h> |
Para obtener información adicional de compatibilidad, vea Compatibilidad en la Introducción.
Bibliotecas
Todas las versiones de las bibliotecas en tiempo de ejecución de C.
Ejemplo
// crt_log.c
/* This program uses log and log10
* to calculate the natural logarithm and
* the base-10 logarithm of 9,000.
*/
#include <math.h>
#include <stdio.h>
int main( void )
{
double x = 9000.0;
double y;
y = log( x );
printf( "log( %.2f ) = %f\n", x, y );
y = log10( x );
printf( "log10( %.2f ) = %f\n", x, y );
}
Resultados
log( 9000.00 ) = 9.104980
log10( 9000.00 ) = 3.954243
Para generar los logaritmos para otras bases, utilice la relación matemática: registrar b base de un logaritmo natural == (a)/logaritmo natural (b).
// logbase.cpp
#include <math.h>
#include <stdio.h>
double logbase(double a, double base)
{
return log(a) / log(base);
}
int main()
{
double x = 65536;
double result;
result = logbase(x, 2);
printf("Log base 2 of %lf is %lf\n", x, result);
}
Resultados
Log base 2 of 65536.000000 is 16.000000