Skip to content

Commit 8a49018

Browse files
committed
Fix fast comparison of zero
1 parent 7129335 commit 8a49018

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

include/boost/decimal/detail/comparison.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto equality_impl(DecimalType lhs, Decimal
101101
template <BOOST_DECIMAL_FAST_DECIMAL_FLOATING_TYPE DecimalType>
102102
BOOST_DECIMAL_FORCE_INLINE constexpr auto fast_equality_impl(const DecimalType& lhs, const DecimalType& rhs) noexcept -> bool
103103
{
104+
if (lhs.significand_ == 0U && rhs.significand_ == 0U)
105+
{
106+
// -0 == +0
107+
return true;
108+
}
109+
104110
if (lhs.exponent_ != rhs.exponent_)
105111
{
106112
return false;
@@ -117,11 +123,6 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto fast_equality_impl(const DecimalType&
117123
}
118124
#endif
119125

120-
if (lhs.significand_ == 0U)
121-
{
122-
return true; // -0 == +0
123-
}
124-
125126
return lhs.sign_ == rhs.sign_;
126127
}
127128

0 commit comments

Comments
 (0)