Skip to content
class method

Math.hypot

(::Math::double x, ::Math::double y) -> ::Float
Math.hypot(a, b) → float

Returns sqrt(a**2 + b**2), which is the length of the longest side c (the hypotenuse) of the right triangle whose other sides have lengths a and b.

  • Domain of a: [-INFINITY, INFINITY].

  • Domain of +ab: [-INFINITY, INFINITY].

  • Range: [0, INFINITY].

Examples:

Example
hypot(0.0, 1.0)       # => 1.0
hypot(1.0, 1.0)       # => 1.4142135623730951 # sqrt(2.0)
hypot(3.0, 4.0)       # => 5.0
hypot(5.0, 12.0)      # => 13.0
hypot(1.0, sqrt(3.0)) # => 1.9999999999999998 # Near 2.0

Note that if either argument is INFINITY or -INFINITY, the result is Infinity.

See also .gamma .ldexp .frexp .lgamma also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0