Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Elixir

Idiom #200 Return hypotenuse

Compute the hypotenuse h of the triangle where the sides adjacent to the square angle have lengths x and y.

import :math
def sq(x) do
  x*x
end

def hypo(a,b) do
  sqrt(sq(a) + sq(b))
end
#include <cmath>
auto h = std::hypot(x, y);

h, x, y may have types float, double, long double

New implementation...
< >
Bart