PHP hypot() Function
The PHP hypot() function returns square root of sum of squares of two arguments, i.e., sqrt(x2 +y2). In special cases it returns the following:
- If either argument is infinite, then the result is positive infinity.
- If either argument is NAN and neither argument is infinite, then the result is NAN.
Syntax
hypot(x, y)
Parameters
x |
Required. Specify a value. |
y |
Required. Specify a value. |
Return Value
Returns sqrt(x2 +y2).
Example:
In the example below, hypot() function returns sqrt(x2 +y2).
<?php echo "hypot(3, 4) = ".hypot(3, 4)."\n"; echo "hypot(5, 12) = ".hypot(5, 12)."\n"; echo "hypot(8, 15) = ".hypot(8, 15)."\n"; echo "hypot(8, -15) = ".hypot(8, -15)."\n"; echo "hypot(-8, -15) = ".hypot(-8, -15)."\n"; echo "hypot(3, INF) = ".hypot(3, INF)."\n"; echo "hypot(3, NAN) = ".hypot(3, NAN)."\n"; ?>
The output of the above code will be:
hypot(3, 4) = 5 hypot(5, 12) = 13 hypot(8, 15) = 17 hypot(8, -15) = 17 hypot(-8, -15) = 17 hypot(3, INF) = INF hypot(3, NAN) = NAN
❮ PHP Math Reference