PHP pi() 函数
pi() 是 PHP 中的重要数学函数,用于解决数学问题。它返回 PI 的近似值。
我们可以使用 M_PI 常量作为 pi() 的结果。
语法
float pi ( void )
示例1
<?php
echo "By using 'pi()' Function the value of PI : ".(pi());
?>
输出:
By using 'pi()' Function the value of PI : 3.1415926535898
示例2
<?php
echo "By using 'M_PI' constant the value of PI : ".M_PI_2;
?>
输出:
By using 'M_PI' constant the value of PI : 1.5707963267949
示例3
<?php
echo "By using 'M_PI_2' constant the value of PI : ".M_PI_2; // pi/2
echo "<br>"."By using 'M_PI_4' constant the value of PI : ".M_PI_4; // pi/4
?>
输出:
By using 'M_PI_2' constant the value of PI : 1.5707963267949
By using 'M_PI_4' constant the value of PI : 0.78539816339745
示例4
<?php
echo "By using 'M_SQRTPI' constant the value of PI : ".M_SQRTPI; //sqrt(pi)
?>
输出:
By using 'M_SQRTPI' constant the value of PI : 1.7724538509055
示例5
<?php
echo "By using 'M_2_SQRTPI' constant the value of PI : ".M_2_SQRTPI; // 2/sqrt(pi)
?>
输出:
By using 'M_2_SQRTPI' constant the value of PI : 1.1283791670955