Logo

Programming-Idioms

  • VB
  • C#

Idiom #200 Return hypotenuse

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

double hypo(double x, double y)
{
    return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
}
#include <cmath>
auto h = std::hypot(x, y);

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

New implementation...
< >
Bart