Compartilhar via


log, logf, log10, log10f

Calcula 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 cujo logaritmo é a ser localizado.

Valor de retorno

O log funções retornam o logaritmo natural (base e) de x se for bem sucedida.As funções de log10 retornam o logaritmo de base 10.Se x é negativa, essas funções retornam um indefinido, por padrão.Se x é 0, elas retornam INF (infinitas).

Entrada

Exceção SEH

Exceção de Matherr

± QNAN, IND.

Nenhum

_DOMAIN

± 0

ZERODIVIDE

_SING

x < 0

INVÁLIDO

_DOMAIN

log e log10 tem uma implementação que usa o Streaming SIMD Extensions 2 (SSE2).Consulte _set_SSE2_enable para obter informações e restrições usando a implementação do SSE2.

Comentários

C++ permite sobrecarga, portanto, você pode chamar métodos sobrecarregados de log e log10.Em um programa em C, log e log10 sempre levar e retornar um double.

Requisitos

Rotina

Cabeçalho necessário

log, logf, log10,log10f

<math.h>

Para obter informações adicionais de compatibilidade, consulte compatibilidade na introdução.

Bibliotecas

Todas as versões da bibliotecas de tempo de execução c.

Exemplo

// 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 );
}

Saída

log( 9000.00 ) = 9.104980
log10( 9000.00 ) = 3.954243

Para gerar logaritmos para outras bases, use a relação matemática: faça b base de um = = log natural (a) / natural fazer logon (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);
}

Saída

Log base 2 of 65536.000000 is 16.000000

Equivalência do .NET Framework

Consulte também

Referência

Suporte de ponto flutuante

EXP, expf

_matherr

pow, powf

_CIlog

_CIlog10