Skip to content

Commit 2f86419

Browse files
committed
Use generic impl instead of incorrect custom impl
1 parent d194c07 commit 2f86419

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
147147
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType>
148148
friend constexpr auto detail::to_chars_hex_impl(char* first, char* last, const TargetDecimalType& value) noexcept -> to_chars_result;
149149

150+
template <typename DecimalType, typename T>
151+
friend constexpr auto detail::generic_div_impl(const T& lhs, const T& rhs) noexcept -> DecimalType;
152+
150153
public:
151154
constexpr decimal_fast32_t() noexcept = default;
152155

@@ -991,43 +994,7 @@ constexpr auto div_impl(const decimal_fast32_t lhs, const decimal_fast32_t rhs,
991994
static_cast<void>(r);
992995
#endif
993996

994-
#ifdef BOOST_DECIMAL_DEBUG
995-
std::cerr << "sig lhs: " << sig_lhs
996-
<< "\nexp lhs: " << exp_lhs
997-
<< "\nsig rhs: " << sig_rhs
998-
<< "\nexp rhs: " << exp_rhs << std::endl;
999-
#endif
1000-
1001-
using local_signed_exponent_type = std::common_type_t<std::int_fast32_t, int>;
1002-
1003-
static_assert(sizeof(local_signed_exponent_type) >= 4, "Error in local exponent type definition");
1004-
1005-
// We promote to uint64 since the significands are currently 32-bits
1006-
// By appending enough zeros to the LHS we end up finding what we need anyway
1007-
constexpr auto ten_pow_precision {detail::pow10(static_cast<std::uint_fast64_t>(detail::precision_v<decimal32_t>))};
1008-
const auto big_sig_lhs {static_cast<std::uint_fast64_t>(lhs.significand_) * ten_pow_precision};
1009-
auto res_sig {big_sig_lhs / static_cast<std::uint_fast64_t>(rhs.significand_)};
1010-
local_signed_exponent_type res_exp {static_cast<local_signed_exponent_type>(lhs.exponent_) - static_cast<local_signed_exponent_type>(rhs.exponent_) + 94};
1011-
const auto isneg {lhs.sign_ != rhs.sign_};
1012-
1013-
// If we have 8 figures round it down to 7
1014-
if (res_sig >= UINT64_C(10'000'000))
1015-
{
1016-
res_exp += detail::fenv_round<decimal_fast32_t>(res_sig, isneg);
1017-
}
1018-
1019-
BOOST_DECIMAL_ASSERT(res_sig >= 1'000'000 || res_sig == 0U);
1020-
BOOST_DECIMAL_ASSERT(res_exp <= 9'999'999 || res_sig == 0U);
1021-
1022-
if (BOOST_DECIMAL_LIKELY(res_exp >= 0))
1023-
{
1024-
q = direct_init(static_cast<decimal_fast32_t::significand_type>(res_sig), static_cast<decimal_fast32_t::exponent_type>(res_exp), isneg);
1025-
}
1026-
else
1027-
{
1028-
// Flush to zero
1029-
q = zero;
1030-
}
997+
q = detail::generic_div_impl<decimal_fast32_t>(lhs, rhs);
1031998
}
1032999

10331000
constexpr auto mod_impl(const decimal_fast32_t lhs, const decimal_fast32_t rhs, const decimal_fast32_t& q, decimal_fast32_t& r) noexcept -> void

0 commit comments

Comments
 (0)