@@ -842,22 +842,7 @@ constexpr auto operator+(decimal32 lhs, decimal32 rhs) noexcept -> decimal32
842842 }
843843 #endif
844844
845- bool lhs_bigger {lhs > rhs};
846- if (lhs.isneg () && rhs.isneg ())
847- {
848- lhs_bigger = !lhs_bigger;
849- }
850-
851- // Ensure that lhs is always the larger for ease of implementation
852- if (!lhs_bigger)
853- {
854- detail::swap (lhs, rhs);
855- }
856-
857- if (!lhs.isneg () && rhs.isneg ())
858- {
859- return lhs - abs (rhs);
860- }
845+ const bool abs_lhs_bigger {abs (lhs) > abs (rhs)};
861846
862847 auto sig_lhs {lhs.full_significand ()};
863848 auto exp_lhs {lhs.biased_exponent ()};
@@ -867,8 +852,9 @@ constexpr auto operator+(decimal32 lhs, decimal32 rhs) noexcept -> decimal32
867852 auto exp_rhs {rhs.biased_exponent ()};
868853 detail::normalize (sig_rhs, exp_rhs);
869854
870- return detail::add_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg (),
871- sig_rhs, exp_rhs, rhs.isneg ());
855+ return detail::d32_add_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg (),
856+ sig_rhs, exp_rhs, rhs.isneg (),
857+ abs_lhs_bigger);
872858}
873859
874860template <typename Integer>
@@ -885,45 +871,23 @@ constexpr auto operator+(decimal32 lhs, Integer rhs) noexcept
885871 }
886872 #endif
887873
888- bool lhs_bigger {lhs > rhs};
889- if (lhs.isneg () && (rhs < 0 ))
890- {
891- lhs_bigger = !lhs_bigger;
892- }
893-
894874 // Make the significand type wide enough that it won't overflow during normalization
895875 auto sig_rhs {static_cast <promoted_significand_type>(detail::make_positive_unsigned (rhs))};
896- bool abs_lhs_bigger {abs (lhs) > sig_rhs};
876+ const bool abs_lhs_bigger {abs (lhs) > sig_rhs};
897877
898878 auto sig_lhs {lhs.full_significand ()};
899879 auto exp_lhs {lhs.biased_exponent ()};
900880 detail::normalize (sig_lhs, exp_lhs);
901- auto lhs_components {detail::decimal32_components{sig_lhs, exp_lhs, lhs.isneg ()}};
902881
903882 exp_type exp_rhs {0 };
904883 detail::normalize (sig_rhs, exp_rhs);
905884
906885 // Now that the rhs has been normalized it is guaranteed to fit into the decimal32 significand type
907- auto unsigned_sig_rhs {static_cast <typename detail::decimal32_components::significand_type>(detail::make_positive_unsigned (sig_rhs))};
908- auto rhs_components {detail::decimal32_components{unsigned_sig_rhs, exp_rhs, (rhs < 0 )}};
909-
910- if (!lhs_bigger)
911- {
912- detail::swap (lhs_components, rhs_components);
913- abs_lhs_bigger = !abs_lhs_bigger;
914- }
886+ const auto final_sig_rhs {static_cast <typename detail::decimal32_components::significand_type>(detail::make_positive_unsigned (sig_rhs))};
915887
916- if (!lhs_components.sign && rhs_components.sign )
917- {
918- return detail::sub_impl<decimal32>(lhs_components.sig , lhs_components.exp , lhs_components.sign ,
919- rhs_components.sig , rhs_components.exp , rhs_components.sign ,
888+ return detail::d32_add_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg (),
889+ final_sig_rhs, exp_rhs, (rhs < 0 ),
920890 abs_lhs_bigger);
921- }
922- else
923- {
924- return detail::add_impl<decimal32>(lhs_components.sig , lhs_components.exp , lhs_components.sign ,
925- rhs_components.sig , rhs_components.exp , rhs_components.sign );
926- }
927891}
928892
929893template <typename Integer>
0 commit comments