The hypot()
method is a static method of the java.lang.Math
library. It takes two numbers and returns the square root of + without any intermediate underflow or overflow.
There are special cases regarding this function:
The result will be positiveinfinity
if any of the parameters are infinite.
The result will be NaN
if any of the parameters are NaN and none of them are infinite.
public static double hypot(double x, double y)
This method will take two numbers of primitive data type double
:
x
contains the first argument.y
contains the second argument.This function will return the answer of √( + ) without any overflow or underflow of double
type.
This code illustrates how to use the hypot()
method to compute sqrt ( + ).
num1= 32176.2
and num2= -298.77
, then called the function to perform the calculations.32177.5870
.import java.lang.*;public class EdPresso {public static void main(String[] args) {//initializng the variablesdouble num1 = 32176.2;double num2 = -298.77;//calling the hypot method//and printing the outputSystem.out.println("answer= " + Math.hypot(num1, num2));}}