diff --git a/src/Core/AccurateComparison.h b/src/Core/AccurateComparison.h index e09993289a9..d96ddda89c4 100644 --- a/src/Core/AccurateComparison.h +++ b/src/Core/AccurateComparison.h @@ -26,9 +26,8 @@ bool lessOp(A a, B b) return a < b; /// anything vs NaN - if constexpr (std::is_floating_point_v || std::is_floating_point_v) - if (isNaN(a) || isNaN(b)) - return false; + if (isNaN(a) || isNaN(b)) + return false; /// int vs int if constexpr (is_integer_v && is_integer_v) @@ -40,10 +39,10 @@ bool lessOp(A a, B b) /// different signedness if constexpr (is_signed_v && !is_signed_v) - return a < 0 || static_cast(a) < b; + return a < 0 || static_cast>(a) < b; if constexpr (!is_signed_v && is_signed_v) - return b >= 0 && a < static_cast(b); + return b >= 0 && a < static_cast>(b); } /// int vs float @@ -176,8 +175,8 @@ inline bool NO_SANITIZE_UNDEFINED convertNumeric(From value, To & result) } } - if (accurate::greaterOp(value, std::numeric_limits::max()) - || accurate::greaterOp(std::numeric_limits::lowest(), value)) + if (greaterOp(value, std::numeric_limits::max()) + || lessOp(value, std::numeric_limits::lowest())) { return false; } diff --git a/src/Core/tests/gtest_accurate_comparison.cpp b/src/Core/tests/gtest_accurate_comparison.cpp index 11a9ff97b2e..a5ac89e98de 100644 --- a/src/Core/tests/gtest_accurate_comparison.cpp +++ b/src/Core/tests/gtest_accurate_comparison.cpp @@ -53,6 +53,10 @@ GTEST_TEST(AccurateComparison, Tests) ASSERT_TRUE(accurate::equalsOp(static_cast(9223372036854775808ULL), static_cast(9223372036854775808ULL))); + /// Integers + ASSERT_TRUE(accurate::lessOp(static_cast(255), 300)); + + /* Float32 f = static_cast(9223372000000000000ULL); UInt64 u = static_cast(9223372000000000000ULL); DecomposedFloat32 components(f);