PHP 8.5.8 Released!

exp

(PHP 4, PHP 5, PHP 7, PHP 8)

exp计算 e 的指数

说明

function exp(float $num): float

返回 enum 次方值。

注意:

用"e"作为自然对数的底数,大约为 2.718282。

参数

num

要处理的参数

返回值

'e' raised to the power of num

示例

示例 #1 exp() 示例

<?php
echo exp(12), PHP_EOL;
echo exp(5.7);
?>

以上示例会输出:

162754.791419
298.86740096706

参见

发现了问题?

了解如何改进此页面提交拉取请求报告一个错误
+添加备注

用户贡献的备注 1 note

up
4
zooly at globmi dot com
15 years ago
PHP does not have the following math function in any extensions:
frexp() - Extract Mantissa and Exponent of the Floating-Point Value
I've digged many C source codes, and found the simplest implementation as follows:
<?php
function frexp ( $float ) {
 $exponent = ( floor(log($float, 2)) + 1 );
 $mantissa = ( $float * pow(2, -$exponent) );
 return(
 array($mantissa, $exponent)
 );
}
print_r(frexp(0.0345));
print_r(frexp(21.539));
?>

Array
(
 [0] => 0.552
 [1] => -4
)
Array
(
 [0] => 0.67309375
 [1] => 5
)
I have compared the results using a lot of floats against C's frexp function - they are the same.
Note that C and PHP uses different float precisions, for example "4619.3" gives:
C: 0.56387939453125, 13
PHP: 0.563879394531, 13
/Assuming default configurations./
+添加备注

AltStyle によって変換されたページ (->オリジナル) /