hypot():hypotenuse of a right-angle triangle

Calculate a right-triangle hypotenuse

hypot() calculates the hypotenuse length from the two perpendicular sides of a right triangle.

$a = 3;
$b = 4;
echo hypot($a, $b); // 5

hypot() also gives the distance from the point ($x, $y) to the origin and handles negative side values by magnitude.

<?Php
echo hypot(4,3); // Output is 5
echo "<br>";
echo hypot(2,3); // Output 3.605551275464
echo "<br>";
echo hypot(4,5); // Output 6.4031242374328
echo "<br>";
echo hypot(8,10); // Output is 12.806248474866
echo "<br>";
echo hypot(12,13); // Output is 17.691806012954
?>
Syntax
float hypot(float $x, float $y)
ParameterDESCRIPTION
$xRequired : Length of first side.
$xRequired : Length of second side.
The return value is the hypotenuse length, equivalent to sqrt($x * $x + $y * $y).

Rounding the output to two decimal place by using round()
echo round(hypot(9,10),2); // Output is 13.45

Example: Calculating Hypotenuse of a Right Triangle

$a = 3;
$b = 4;
echo hypot($a, $b);  // Output: 5 (Pythagorean theorem: sqrt(3^2 + 4^2))

Example: Using Negative Values

$a = -3;
$b = 4;
echo hypot($a, $b);  // Output: 5 (Negative values are squared, so the result is positive)

These examples show that hypot() works with positive or negative coordinate values because the result represents a distance.


Math Functions sqrt(): square root pow(): powers and exponents


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer