hypot()函數計算直角三角形的斜邊長度。斜邊的計算公式如下:
h=sqrt(x2 y2),其中x和y是直角三角形的另外兩邊
例如,如果x=3,y=4,那麼hypot(x,y)=5,即sqrt(32 42) = sqrt(25) =5
此函數總是傳回一個浮點數。
hypot ( float $x , float $y ) : float
#序號 | #參數與說明 |
---|---|
#1 | x直角三角形的一邊 |
直角三角形的另一邊
傳回值<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y); ?>Output# ###This returns largest integer−###
hypot(3,4) = 5###Example####### Live Demo######Return value of hypot(x,y) function is equal to sqrt(x*x y*y ) as per pythogoras theorem. Following example confirms it−###
<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y) ."</p><p>"; echo "Hypotenuse calculated by Pythogoras equation = " . sqrt(pow($x,2)+pow($y,2)); ?>###輸出######這將傳回以下輸出−###
hypot(3,4) = 5 Hypotenuse calculated by Pythogoras equation = 5###
以上是PHP hypot() 函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!