Hypot v0.1.0

Source
Returns the length of the hypotenuse of a right triangle with legs x and y.

Package: Math

Signature

func Hypot(x: float64, y: float64) -> float64;
func Hypot(x: float32, y: float32) -> float32;

Parameters

NameTypeDescription
xfloat64 / float32One leg of the triangle.
yfloat64 / float32The other leg.

Returns

√(x² + y²), computed without the overflow that squaring a large argument would cause, without the underflow that squaring a small one would, and without the extra rounding of forming x*x + y*y directly. Hypot is infinite if either argument is infinite, even when the other is a NaN; otherwise a NaN in either argument produces a NaN.

Example

import Math::Hypot;

func Main() -> int {
    let a = Hypot(3.0, 4.0); // 5.0
    return 0;
}

See also

  • Math — the package overview
  • Sqrt — the square root Hypot is built on
  • Abs — magnitude of a single value