Logo

Programming-Idioms

  • C
  • Lua

Idiom #200 Return hypotenuse

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

local h = math.sqrt(x^2 + y^2)
local h=(x^2+y^2)^0.5
#include <cmath>
auto h = std::hypot(x, y);

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

New implementation...
< >
Bart