PHP exp() 函数
exp() 函数用于计算e的指数。它返回e的x次方(ex),其中’e’是自然对数的基数,x是传递给函数的数字。
语法
exp(x);
Name | Description | Return type |
---|---|---|
x | Specifies the exponent | float |
示例1
<?php
v1= 0;v2=1;
v3=2.5;res1=exp(v1);res2=exp(v2);res3=exp(v3);
echo "exponent ofv1 is = res1<br />";
echo "exponent ofv2 is = res2<br />";
echo "exponent ofv3 is = $res3<br />";
?>
输出:
exponent of 0 is = 1
exponent of 1 is = 2.718281828459
exponent of 2.5 is = 12.182493960703
注意:’e’是自然对数的底数,约为2.718282。
示例2
<?php
for(i=-3;i<=3;i++)
echo 'The exponent value of e^'.i.' = '.exp($i)."<br>";
?>
输出:
The exponent value of e^-3 = 0.049787068367864
The exponent value of e^-2 = 0.13533528323661
The exponent value of e^-1 = 0.36787944117144
The exponent value of e^0 = 1
The exponent value of e^1 = 2.718281828459
The exponent value of e^2 = 7.3890560989307
The exponent value of e^3 = 20.085536923188