diff --git a/base/common/DecomposedFloat.h b/base/common/DecomposedFloat.h index 2f3fd90ea6c..078ba823c15 100644 --- a/base/common/DecomposedFloat.h +++ b/base/common/DecomposedFloat.h @@ -114,23 +114,28 @@ struct DecomposedFloat return rhs >= 0 ? -1 : 1; } + /// The case of the most negative integer + if constexpr (is_signed_v) + { + if (rhs == std::numeric_limits::lowest()) + { + assert(is_negative()); + + if (normalized_exponent() < static_cast(8 * sizeof(Int) - is_signed_v)) + return 1; + if (normalized_exponent() > static_cast(8 * sizeof(Int) - is_signed_v)) + return -1; + + if (mantissa() == 0) + return 0; + else + return -1; + } + } + /// Too large number: abs(float) > abs(rhs). Also the case with infinities and NaN. if (normalized_exponent() >= static_cast(8 * sizeof(Int) - is_signed_v)) - { - /// The case of most negative integer - it can be equal to float - if constexpr (is_signed_v) - { - if (rhs == std::numeric_limits::lowest() - && normalized_exponent() == static_cast(8 * sizeof(Int) - is_signed_v) - && is_negative() - && mantissa() == 0) - { - return 0; - } - } - return is_negative() ? -1 : 1; - } using UInt = make_unsigned_t; UInt uint_rhs = rhs < 0 ? -rhs : rhs;