How does one write the Pythagoras Theorem in Scala?

后端 未结 4 1468
时光取名叫无心
时光取名叫无心 2020-12-03 01:27

The square of the hypotenuse of a right triangle is equal to the sum of the squares on the other two sides.

This is Pythagoras\'s Theore

4条回答
  •  天涯浪人
    2020-12-03 01:56

    There is a method in java.lang.Math:

    public static double hypot (double x, double y)
    

    for which the javadocs asserts:

    Returns sqrt(x2 +y2) without intermediate overflow or underflow.

    looking into src.zip, Math.hypot uses StrictMath, which is a native Method:

    public static native double hypot(double x, double y);
    

提交回复
热议问题