@@ -18,7 +18,7 @@ namespace decimal {
1818namespace detail {
1919
2020template <typename ReturnType, typename T, typename U>
21- BOOST_DECIMAL_FORCE_INLINE constexpr auto new_sub_impl (T lhs_sig, U lhs_exp, bool lhs_sign,
21+ BOOST_DECIMAL_FORCE_INLINE constexpr auto d32_sub_impl (T lhs_sig, U lhs_exp, bool lhs_sign,
2222 T rhs_sig, U rhs_exp, bool rhs_sign,
2323 bool abs_lhs_bigger) noexcept -> ReturnType
2424{
@@ -83,74 +83,6 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto new_sub_impl(T lhs_sig, U lhs_exp, boo
8383 return {res_sig, new_exp, new_sign};
8484}
8585
86- template <typename ReturnType, typename T, typename U>
87- BOOST_DECIMAL_FORCE_INLINE constexpr auto sub_impl (T lhs_sig, U lhs_exp, bool lhs_sign,
88- T rhs_sig, U rhs_exp, bool rhs_sign,
89- bool abs_lhs_bigger) noexcept -> ReturnType
90- {
91- using sub_type = std::int_fast32_t ;
92-
93- auto delta_exp {lhs_exp > rhs_exp ? lhs_exp - rhs_exp : rhs_exp - lhs_exp};
94- auto signed_sig_lhs {detail::make_signed_value (lhs_sig, lhs_sign)};
95- auto signed_sig_rhs {detail::make_signed_value (rhs_sig, rhs_sign)};
96-
97- if (delta_exp > detail::precision + 1 )
98- {
99- // If the difference in exponents is more than the digits of accuracy
100- // we return the larger of the two
101- //
102- // e.g. 1e20 - 1e-20 = 1e20
103- return abs_lhs_bigger ? ReturnType{lhs_sig, lhs_exp, false } :
104- ReturnType{rhs_sig, rhs_exp, true };
105- }
106-
107- // The two numbers can be subtracted together without special handling
108-
109- auto & sig_bigger {abs_lhs_bigger ? signed_sig_lhs : signed_sig_rhs};
110- auto & exp_bigger {abs_lhs_bigger ? lhs_exp : rhs_exp};
111- auto & sig_smaller {abs_lhs_bigger ? signed_sig_rhs : signed_sig_lhs};
112- auto & smaller_sign {abs_lhs_bigger ? rhs_sign : lhs_sign};
113-
114- if (delta_exp == 1 )
115- {
116- sig_bigger *= 10 ;
117- --delta_exp;
118- --exp_bigger;
119- }
120- else
121- {
122- if (delta_exp >= 2 )
123- {
124- sig_bigger *= 100 ;
125- delta_exp -= 2 ;
126- exp_bigger -= 2 ;
127- }
128-
129- if (delta_exp > 1 )
130- {
131- sig_smaller /= pow10 (delta_exp - 1 );
132- delta_exp = 1 ;
133- }
134-
135- if (delta_exp == 1 )
136- {
137- detail::fenv_round (sig_smaller, smaller_sign);
138- }
139- }
140-
141- // Both of the significands are less than 9'999'999, so we can safely
142- // cast them to signed 32-bit ints to calculate the new significand
143- const auto new_sig = (rhs_sign && !lhs_sign) ?
144- static_cast <sub_type>(signed_sig_lhs) + static_cast <sub_type>(signed_sig_rhs) :
145- static_cast <sub_type>(signed_sig_lhs) - static_cast <sub_type>(signed_sig_rhs);
146-
147- const auto new_exp {abs_lhs_bigger ? lhs_exp : rhs_exp};
148- const auto new_sign {new_sig < 0 };
149- const auto res_sig {detail::make_positive_unsigned (new_sig)};
150-
151- return {res_sig, new_exp, new_sign};
152- }
153-
15486template <typename ReturnType, BOOST_DECIMAL_INTEGRAL T, BOOST_DECIMAL_INTEGRAL U>
15587constexpr auto d64_sub_impl (T lhs_sig, U lhs_exp, bool lhs_sign,
15688 T rhs_sig, U rhs_exp, bool rhs_sign,
0 commit comments