Skip to content

Commit c97212c

Browse files
committed
Use new impl with decimal128
1 parent 58d8d29 commit c97212c

File tree

1 file changed

+5
-59
lines changed

1 file changed

+5
-59
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,23 +1533,6 @@ constexpr auto operator+(decimal128 lhs, decimal128 rhs) noexcept -> decimal128
15331533
}
15341534
#endif
15351535

1536-
bool lhs_bigger {lhs > rhs};
1537-
if (lhs.isneg() && rhs.isneg())
1538-
{
1539-
lhs_bigger = !lhs_bigger;
1540-
}
1541-
1542-
// Ensure that lhs is always the larger for ease of impl
1543-
if (!lhs_bigger)
1544-
{
1545-
detail::swap(lhs, rhs);
1546-
}
1547-
1548-
if (!lhs.isneg() && rhs.isneg())
1549-
{
1550-
return lhs - abs(rhs);
1551-
}
1552-
15531536
auto lhs_sig {lhs.full_significand()};
15541537
auto lhs_exp {lhs.biased_exponent()};
15551538
detail::normalize<decimal128>(lhs_sig, lhs_exp);
@@ -1558,15 +1541,9 @@ constexpr auto operator+(decimal128 lhs, decimal128 rhs) noexcept -> decimal128
15581541
auto rhs_exp {rhs.biased_exponent()};
15591542
detail::normalize<decimal128>(rhs_sig, rhs_exp);
15601543

1561-
#ifdef BOOST_DECIMAL_DEBUG_ADD_128
1562-
std::cerr << "\nlhs sig: " << static_cast<detail::uint128_t>(lhs_sig)
1563-
<< "\nlhs exp: " << lhs_exp
1564-
<< "\nrhs sig: " << static_cast<detail::uint128_t>(rhs_sig)
1565-
<< "\nrhs exp: " << rhs_exp << std::endl;
1566-
#endif
1567-
15681544
return detail::d128_add_impl<decimal128>(lhs_sig, lhs_exp, lhs.isneg(),
1569-
rhs_sig, rhs_exp, rhs.isneg());
1545+
rhs_sig, rhs_exp, rhs.isneg(),
1546+
abs(lhs) > abs(rhs));
15701547
}
15711548

15721549
template <typename Integer>
@@ -1582,50 +1559,19 @@ constexpr auto operator+(decimal128 lhs, Integer rhs) noexcept
15821559
}
15831560
#endif
15841561

1585-
bool lhs_bigger {lhs > rhs};
1586-
if (lhs.isneg() && (rhs < 0))
1587-
{
1588-
lhs_bigger = !lhs_bigger;
1589-
}
15901562
auto sig_rhs {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
15911563
bool abs_lhs_bigger {abs(lhs) > sig_rhs};
15921564

15931565
auto sig_lhs {lhs.full_significand()};
15941566
auto exp_lhs {lhs.biased_exponent()};
15951567
detail::normalize<decimal128>(sig_lhs, exp_lhs);
1596-
auto lhs_components {detail::decimal128_components{sig_lhs, exp_lhs, lhs.isneg()}};
15971568

15981569
exp_type exp_rhs {0};
15991570
detail::normalize<decimal128>(sig_rhs, exp_rhs);
1600-
auto rhs_components {detail::decimal128_components{sig_rhs, exp_rhs, (rhs < 0)}};
1601-
1602-
if (!lhs_bigger)
1603-
{
1604-
detail::swap(lhs_components, rhs_components);
1605-
lhs_bigger = !lhs_bigger;
1606-
abs_lhs_bigger = !abs_lhs_bigger;
1607-
}
1608-
1609-
#ifdef BOOST_DECIMAL_DEBUG_ADD
1610-
std::cerr << "Lhs sig: " << lhs_components.sig
1611-
<< "\nLhs exp: " << lhs_components.exp
1612-
<< "\nRhs sig: " << rhs_components.sig
1613-
<< "\nRhs exp: " << rhs_components.exp << std::endl;
1614-
#endif
16151571

1616-
if (!lhs_components.sign && rhs_components.sign)
1617-
{
1618-
return detail::d128_sub_impl<decimal128>(
1619-
lhs_components.sig, lhs_components.exp, lhs_components.sign,
1620-
rhs_components.sig, rhs_components.exp, rhs_components.sign,
1621-
abs_lhs_bigger);
1622-
}
1623-
else
1624-
{
1625-
return detail::d128_add_impl<decimal128>(
1626-
lhs_components.sig, lhs_components.exp, lhs_components.sign,
1627-
rhs_components.sig, rhs_components.exp, rhs_components.sign);
1628-
}
1572+
return detail::d128_add_impl<decimal128>(sig_lhs, exp_lhs, lhs.isneg(),
1573+
sig_rhs, exp_rhs, (rhs < 0),
1574+
abs_lhs_bigger);
16291575
}
16301576

16311577
template <typename Integer>

0 commit comments

Comments
 (0)