Java Math hypot() method with Example
Last Updated :
06 Apr, 2018
java.lang.Math.hypot() function is an inbuilt math function in Java that returns the Euclidean norm,
. The function returns sqrt(x
2 + y
2) without intermediate overflow or underflow.
- 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 :
public static double hypot(double x, double y)
Parameter :
x and y are the values.
Returns :
sqrt(x
2 +y
2) without intermediate overflow or underflow.
Example 1 : To show working of java.lang.Math.hyptot() method.
import java.lang.Math;
class Gfg {
public static void main(String args[])
{
double x = 3 ;
double y = 4 ;
double result = Math.hypot(x, y);
System.out.println(result);
double positiveInfinity =
Double.POSITIVE_INFINITY;
double negativeInfinity =
Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
result = Math.hypot(nan, y);
System.out.println(result);
result = Math.hypot(positiveInfinity,
negativeInfinity);
System.out.println(result);
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...