C
数值 | Numerics

log10f

log10, log10f, log10l

在头文件中定义
float log10f( float arg (1)(since C99)
double log10( double arg (2)
long double log10l( long double arg (3)(since C99)
Defined in header <tgmath.h>
#define log10( arg )(4)(since C99)

1-3)计算公共(基数为10)的对数arg

4)类型 - 通用宏:如果arg有类型long doublelog10l被调用。否则,如果arg有整数类型或类型doublelog10则调用。否则,log10f被调用。

参数

arg-floating point value

返回值

如果没有错误发生,则以(log 10)的常见(以10为底)对数arg

10(arg)或lg(arg))。

如果发生域错误,则返回实现定义的值(NaN,如果支持)。

如果发生极错误-HUGE_VAL-HUGE_VALF-HUGE_VALL返回。

错误处理

按照math_errhandling中的指定报告错误。

如果arg小于零,则会发生域错误。

如果arg为零,则可能出现极点错误。

如果实现支持IEEE浮点运算(IEC 60559),

  • 如果参数为±0,则返回-∞并FE_DIVBYZERO引发。

#include <stdio.h> #include <math.h> #include <float.h> #include <errno.h> #include <fenv.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" }

可能的输出:

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

参考

  • C11标准(ISO / IEC 9899:2011):