Skip to content

Commit 14067a4

Browse files
committed
Refactor name and remove old implementation
1 parent 58cddc9 commit 14067a4

File tree

3 files changed

+9
-77
lines changed

3 files changed

+9
-77
lines changed

include/boost/decimal/decimal32.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ constexpr auto operator-(decimal32 lhs, decimal32 rhs) noexcept -> decimal32
954954
auto exp_rhs {rhs.biased_exponent()};
955955
detail::normalize(sig_rhs, exp_rhs);
956956

957-
return detail::new_sub_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg(),
957+
return detail::d32_sub_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg(),
958958
sig_rhs, exp_rhs, rhs.isneg(),
959959
abs_lhs_bigger);
960960
}
@@ -984,7 +984,7 @@ constexpr auto operator-(decimal32 lhs, Integer rhs) noexcept
984984
detail::normalize(sig_rhs, exp_rhs);
985985
auto final_sig_rhs {static_cast<decimal32::significand_type>(sig_rhs)};
986986

987-
return detail::new_sub_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg(),
987+
return detail::d32_sub_impl<decimal32>(sig_lhs, exp_lhs, lhs.isneg(),
988988
final_sig_rhs, exp_rhs, (rhs < 0),
989989
abs_lhs_bigger);
990990
}
@@ -1014,7 +1014,7 @@ constexpr auto operator-(Integer lhs, decimal32 rhs) noexcept
10141014
auto exp_rhs {rhs.biased_exponent()};
10151015
detail::normalize(sig_rhs, exp_rhs);
10161016

1017-
return detail::new_sub_impl<decimal32>(final_sig_lhs, exp_lhs, (lhs < 0),
1017+
return detail::d32_sub_impl<decimal32>(final_sig_lhs, exp_lhs, (lhs < 0),
10181018
sig_rhs, exp_rhs, rhs.isneg(),
10191019
abs_lhs_bigger);
10201020
}

include/boost/decimal/decimal32_fast.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,11 @@ constexpr auto operator-(decimal32_fast lhs, decimal32_fast rhs) noexcept -> dec
820820
}
821821
#endif
822822

823-
return detail::new_sub_impl<decimal32_fast>(
823+
return detail::d32_sub_impl<decimal32_fast>(
824824
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
825825
rhs.significand_, rhs.biased_exponent(), rhs.sign_,
826826
abs(lhs) > abs(rhs)
827-
);
827+
);
828828
}
829829

830830
template <typename Integer>
@@ -849,7 +849,7 @@ constexpr auto operator-(decimal32_fast lhs, Integer rhs) noexcept
849849
detail::normalize(sig_rhs, exp_rhs);
850850
auto final_sig_rhs {static_cast<decimal32_fast::significand_type>(detail::make_positive_unsigned(sig_rhs))};
851851

852-
return detail::new_sub_impl<decimal32_fast>(
852+
return detail::d32_sub_impl<decimal32_fast>(
853853
lhs.significand_, lhs.biased_exponent(), lhs.sign_,
854854
final_sig_rhs, exp_rhs, (rhs < 0),
855855
abs_lhs_bigger);
@@ -876,11 +876,11 @@ constexpr auto operator-(Integer lhs, decimal32_fast rhs) noexcept
876876
detail::normalize(sig_lhs, exp_lhs);
877877
auto final_sig_lhs {static_cast<decimal32_fast::significand_type>(detail::make_positive_unsigned(sig_lhs))};
878878

879-
return detail::new_sub_impl<decimal32_fast>(
879+
return detail::d32_sub_impl<decimal32_fast>(
880880
final_sig_lhs, exp_lhs, (lhs < 0),
881881
rhs.significand_, rhs.biased_exponent(), rhs.sign_,
882882
abs_lhs_bigger
883-
);
883+
);
884884
}
885885

886886
constexpr auto operator*(decimal32_fast lhs, decimal32_fast rhs) noexcept -> decimal32_fast

include/boost/decimal/detail/sub_impl.hpp

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace decimal {
1818
namespace detail {
1919

2020
template <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-
15486
template <typename ReturnType, BOOST_DECIMAL_INTEGRAL T, BOOST_DECIMAL_INTEGRAL U>
15587
constexpr 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

Comments
 (0)