當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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






相關用法


注:本文由純淨天空篩選整理自 PHP pi() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。