©
本文档使用
php中文网手册 发布
在头文件<math.h>中定义 | ||
|---|---|---|
float logf( float arg ); | (1) | (since C99) |
double log( double arg ); | (2) | |
long double logl( long double arg ); | (3) | (since C99) |
Defined in header <tgmath.h> | ||
#define log( arg ) | (4) | (since C99) |
1-3)计算自然数(基e)的对数arg。
4)类型 - 通用宏:如果arg有类型long double,logl被调用。否则,如果arg有整数类型或类型double,log则调用。否则,logf被调用。如果arg是复杂的或虚,则宏调用相应的复变函数(clogf,clog,clogl)。
arg | - | 浮点值 |
|---|
如果没有发生错误,自然(base-e)的对数arg(ln(arg)日或志
e(arg))返回。
如果发生域错误,则返回实现定义的值(NaN,如果支持)。
如果发生极错误-HUGE_VAL,-HUGE_VALF或-HUGE_VALL返回。
按照math_errhandling中的指定报告错误。
如果arg小于零,则会发生域错误。
如果arg为零,则可能出现极点错误。
如果实现支持IEEE浮点运算(IEC 60559),
如果参数为±0,则返回-∞并FE_DIVBYZERO引发。
如果参数是1,则返回+0
如果参数是否定的,则返回并FE_INVALID提出NaN 。
如果参数是+∞,则返回+∞
如果参数是NaN,则返回NaN
#include <stdio.h>#include <math.h>#include <float.h>#include <errno.h>#include <fenv.h>#pragma STDC FENV_ACCESS ON
int main(void){ printf("log(1) = %f\n", log(1)); printf("base-5 logarithm of 125 = %f\n", log(125)/log(5)); // special values printf("log(1) = %f\n", log(1)); printf("log(+Inf) = %f\n", log(INFINITY)); //error handling
errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("log(0) = %f\n", log(0)); if(errno == ERANGE) perror(" errno == ERANGE"); if(fetestexcept(FE_DIVBYZERO)) puts(" FE_DIVBYZERO raised");}输出:
log(1) = 0.000000base-5 logarithm of 125 = 3.000000log(1) = 0.000000log(+Inf) = inflog(0) = -inf errno == ERANGE: Numerical result out of range FE_DIVBYZERO raised
C11标准(ISO / IEC 9899:2011):
7.12.6.7日志功能(p:244-245)
7.25类型通用数学<tgmath.h>(p:373-375)
F.10.3.7日志功能(p:522)
C99标准(ISO / IEC 9899:1999):
7.12.6.7日志功能(p:225)
7.22类型通用数学<tgmath.h>(p:335-337)
F.9.3.7日志功能(p:459)
C89 / C90标准(ISO / IEC 9899:1990):
4.5.4.4日志功能