您好,欢迎访问一九零五行业门户网

PHP hypot() 函数

定义和用法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
直角三角形的一边
2 y
直角三角形的另一边
返回值php hypot() 函数返回给定 x 和 y 值的直角三角形的斜边长度
php 版本此函数在 php 版本 4.x、php 5.x 和 php 7.x 中可用。
示例 在线演示
以下示例计算具有边长为 3 和 4 的直角三角形的斜边长度−
<?php $x = 3; $y = 4; echo "hypot(" . $x . "," . $y . ") = " . hypot($x, $y);?>
outputthis 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) ."
"; echo "hypotenuse calculated by pythogoras equation = " . sqrt(pow($x,2)+pow($y,2));?>
输出这将返回以下输出−
hypot(3,4) = 5hypotenuse calculated by pythogoras equation = 5
以上就是php hypot() 函数的详细内容。
其它类似信息

推荐信息