diff --git a/include/Nazara/Math/Algorithm.inl b/include/Nazara/Math/Algorithm.inl index 612cdf952..e50385c78 100644 --- a/include/Nazara/Math/Algorithm.inl +++ b/include/Nazara/Math/Algorithm.inl @@ -98,7 +98,13 @@ namespace Nz return 0; } - template /*constexpr*/ std::enable_if_t::value || !std::is_integral::value, bool> NumberEquals(T a, T b, T maxDifference) + template /*constexpr*/ std::enable_if_t::value, bool> NumberEquals(T a, T b, T maxDifference) + { + T diff = std::abs(a - b); + return diff <= maxDifference; + } + + template /*constexpr*/ std::enable_if_t::value || (!std::is_integral::value && !std::is_floating_point::value), bool> NumberEquals(T a, T b, T maxDifference) { if (b > a) std::swap(a, b); @@ -112,13 +118,8 @@ namespace Nz if (b > a) std::swap(a, b); - if ((b < 0) && (a > std::numeric_limits::max() + b)) - return false; - - if ((b > 0) && (a < std::numeric_limits::min() + b)) - return false; - - return std::abs(a - b) <= maxDifference; + using UnsignedT = std::make_unsigned_t; + return static_cast(a) - static_cast(b) <= static_cast(maxDifference); } } @@ -487,7 +488,7 @@ namespace Nz template constexpr T Lerp(const T& from, const T& to, const T2& interpolation) { - return from + interpolation * (to - from); + return static_cast(from + interpolation * (to - from)); } /*!