Java.lang.StrictMath.hypot() Method



Description

The java.lang.StrictMath.hypot() method returns sqrt(x2 + y2) without intermediate overflow or underflow.It include some cases −

  • 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.

Declaration

Following is the declaration for java.lang.StrictMath.hypot() method

public static double hypot(double x, double y)

Parameters

  • x − This is the value to be used.

  • y − This is the value to be used.

Return Value

This method returns sqrt(x2 + y2) without intermediate overflow or underflow.

Exception

NA

Example

The following example shows the usage of java.lang.StrictMath.hypot() method.

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      double d1 = 3, d2 = 4, d3 = 6;
   
      // returns sqrt(x2 + y2)
      double hypotValue = StrictMath.hypot(d1, d2); 
      System.out.println("hypotenuse value of d1 and d2 = " + hypotValue);
        
      hypotValue = StrictMath.hypot(d2, d3); 
      System.out.println("hypotenuse value of d2 and d3 = " + hypotValue);
   }
}

Let us compile and run the above program, this will produce the following result −

hypotenuse value of d1 and d2 = 5.0
hypotenuse value of d2 and d3 = 7.211102550927978
java_lang_strictmath.htm
Advertisements