The log10 () function calculates base-10 logarithm of a number.
Base-10 logarithm is also called common or sandard algorithm. The log10(x) function calculates log10x. It is related to natural algorithm by following equation −
log10x=logex/loge10 So that
log10100=loge100/loge10 = 2
In PHP, log10 is represented by log10() function
log10 ( float $arg ) : float
序号 | 参数与描述 |
---|---|
1 | arg 要计算其以10为底的对数的数字 |
PHP log10() 函数返回 arg 的以10为底的对数。
此函数在 PHP 4.x、PHP 5.x 和 PHP 7.x 版本中可用。
在线演示
以下示例计算100的以10为底的对数
<?php $arg=100; echo "log10(" . $arg. ")=" . log10($arg) . ""; ?>
This will produce following result −
log10(100)=2
演示
以下代码计算自然对数的底数10的对数M_E。结果等于预定义常量M_LOG10E−
<?php $arg=M_E; echo "log10(" . $arg. ")=" . log10($arg) . ""; echo "predefined constant M_LOG10E=" . M_LOG10E; ?>
This will produce following result −
log10(2.718281828459)=0.43429448190325 predefined constant M_LOG10E=0.43429448190325
Live Demo
Following example calculates log100 and returns -infinity. −
<?php $arg=0; echo "log10(" . $arg. ")=" . log10($arg) . ""; ?>
This will produce following result −
log10(0)=-INF
演示
同样,sqrt(-1)的结果是NAN。因此它的log10()也返回NAN−
<?php $arg=sqrt(-1); echo "log10(" . $arg. ")=" . log10($arg) . ""; ?>
This will produce following result −
log10(NAN)=NAN