首页 > 文章列表 > PHP log10() 函数

PHP log10() 函数

172 2023-08-20

Definition and Usage

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

Syntax

log10 ( float $arg ) : float

参数

序号参数与描述
1arg

要计算其以10为底的对数的数字

返回值

PHP log10() 函数返回 arg 的以10为底的对数。

PHP 版本

此函数在 PHP 4.x、PHP 5.x 和 PHP 7.x 版本中可用。

示例

 在线演示

以下示例计算100的以10为底的对数

<?php
   $arg=100;
   echo "log10(" . $arg. ")=" . log10($arg) . "

"; ?>

Output

This will produce following result −

log10(100)=2

Example

 演示

以下代码计算自然对数的底数10的对数M_E。结果等于预定义常量M_LOG10E

<?php
   $arg=M_E;
   echo "log10(" . $arg. ")=" . log10($arg) . "

";    echo "predefined constant M_LOG10E=" . M_LOG10E; ?>

Output

This will produce following result −

log10(2.718281828459)=0.43429448190325
predefined constant M_LOG10E=0.43429448190325

Example

 Live Demo

Following example calculates log100 and returns -infinity. −

<?php
   $arg=0;
   echo "log10(" . $arg. ")=" . log10($arg) . "

"; ?>

Output

This will produce following result −

log10(0)=-INF

Example

 演示

同样,sqrt(-1)的结果是NAN。因此它的log10()也返回NAN−

<?php
   $arg=sqrt(-1);
   echo "log10(" . $arg. ")=" . log10($arg) . "

"; ?>

Output

This will produce following result −

log10(NAN)=NAN