log, logf, log10, log10f

计算对数。

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

参数

  • x
    将找到对数的值。

返回值

记录 函数返回该自然对数 (以 x "),如果成功。 log10 函数返回底) 的以 10 为底。 如果 x 为负,这些函数返回不确定,默认情况下。 如果 x 是 0,它们返回 INF (无穷大)。

输入

SEH 异常

Matherr 异常

± QNAN, IND

_DOMAIN

± 0

ZERODIVIDE

_SING

x AMP_LT 0

无效

_DOMAIN

记录log10 具有使用流 SIMD 扩展 2 的实现 (SSE2)。 请参见 _set_SSE2_enable 信息和使用限制这次将实现。

备注

C++ 允许重载,因此,您可以调用 记录log10重载。 在 c. 程序, 记录log10 始终采用并返回二进制文件。

要求

实例

必需的头

记录logflog10log10f

math.h

有关其他的兼容性信息,请参见中介绍的 兼容性

C 运行库的所有版本。

示例

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

Output

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

若要生成其他基础的对数,请使用数学关系:记录基本 b == 自然记录 (a)/自然记录 (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);
}

Output

Log base 2 of 65536.000000 is 16.000000

.NET Framework 等效项

请参见

参考

浮点支持

exp, expf

_matherr

pow, powf

_CIlog

_CIlog10