@@ -38,7 +38,21 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto equality_impl(DecimalType lhs, Decimal
3838 }
3939 #endif
4040
41- // Step 3: Check signs
41+ // Step 2: Fast path
42+ if (lhs.bits_ == rhs.bits_ )
43+ {
44+ return true ;
45+ }
46+
47+ // Step 3: Check -0 == +0
48+ auto lhs_sig {lhs.full_significand ()};
49+ auto rhs_sig {rhs.full_significand ()};
50+ if (lhs_sig == 0 && rhs_sig == 0 )
51+ {
52+ return true ;
53+ }
54+
55+ // Step 4: Check signs
4256 const auto lhs_neg {lhs.isneg ()};
4357 const auto rhs_neg {rhs.isneg ()};
4458
@@ -47,27 +61,19 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto equality_impl(DecimalType lhs, Decimal
4761 return false ;
4862 }
4963
50- // Step 4 : Check the exponents
64+ // Step 5 : Check the exponents
5165 // If the difference is greater than we can represent in the significand than we can assume they are different
5266 const auto lhs_exp {lhs.biased_exponent ()};
5367 const auto rhs_exp {rhs.biased_exponent ()};
5468
55- auto lhs_sig {lhs.full_significand ()};
56- auto rhs_sig {rhs.full_significand ()};
57-
5869 const auto delta_exp {lhs_exp - rhs_exp};
5970
60- if (lhs_sig == 0 && rhs_sig == 0 )
61- {
62- // The difference in exponent is irrelevant here
63- return true ;
64- }
6571 if (delta_exp > detail::precision_v<DecimalType> || delta_exp < -detail::precision_v<DecimalType>)
6672 {
6773 return false ;
6874 }
6975
70- // Step 5 : Normalize the significand and compare
76+ // Step 6 : Normalize the significand and compare
7177 // Instead of multiplying the larger number, divide the smaller one
7278 if (delta_exp >= 0 )
7379 {
0 commit comments