.hypot()
Published Oct 20, 2022
Contribute to Docs
The Math.hypot()
method returns the hypotenuse of a right-angled triangle. The hypotenuse is the square root of x2 + y2, where x
and y
(of type double
) are the sides that form the right angle. It does not return intermediate overflow or underflow, which means the .hypot()
method will not fail due to overflow or underflow of a x2 or y2 value.
Syntax
Math.hypot(x, y)
- The return type for
.hypot()
isdouble
. - If either the
x
ory
parameter is infinite, the result is positive infinity. - If neither argument is infinite, but one or both parameters are
NaN
, the result isNaN
.
Example
The following example demonstrates using .hypot()
to find the hypotenuse of a right-angled triangle:
// Test.javapublic class Test {public static void main(String args[]) {double base_x = 8;double height_y = 10;System.out.println(Math.hypot(base_x, height_y));}}
This results in the following output:
12.806248474865697
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.