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


PHP math acos()用法及代碼示例

acos() 函數是用於計算三角問題的有用的預定義 PHP 函數。它用於以弧度為單位查找數字的反餘弦值。

注意:acos(-1) 返回 Pi 的值。

用法:

acos(number);
參數 描述 必需/可選
Number 在 -1 到 1 範圍內指定一個數字。 Required

示例 1

<?php
$num=0;
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
?>

輸出:

Your number is:0
By using 'acos()' function your number is:1.5707963267949

例2

<?php
$num=1;
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
?>

輸出:

Your number is:1
By using 'acos()' function your number is:0

例3

<?php
$num=2;
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
echo "<br>"." Note:Your number is outside the range [-1,1]";
?>

輸出:

Your number is:2
By using 'acos()' function your number is:NAN
Note:Your number is outside the range [-1,1]

例4

<?php
$num=(0.64);
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
?>

輸出:

Your number is:0.64
By using 'acos()' function your number is:0.87629806116834

例5

<?php
$num=(-0.4);
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
?>

輸出:

Your number is:-0.4
By using 'acos()' function your number is:1.9823131728624

例6

<?php
$num=(-1);
echo "Your number is:".$num;
echo "<br>"."By using 'acos()' function your number is:".(acos($num));
?>

輸出:

Your number is:-1
By using 'acos()' function your number is:3.1415926535898






相關用法


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