diff --git a/BAN/include/BAN/Math.h b/BAN/include/BAN/Math.h index 1a054927..50f7c480 100644 --- a/BAN/include/BAN/Math.h +++ b/BAN/include/BAN/Math.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -470,7 +471,17 @@ namespace BAN::Math template inline constexpr T hypot(T x, T y) { - return sqrt(x * x + y * y); + x = abs(x); + y = abs(y); + + if (x < y) + swap(x, y); + + if (y == (T)0.0) + return x; + + const T r = y / x; + return x * sqrt((T)1.0 + r * r); } #ifdef BAN_MATH_POP_OPTIONS