diff --git a/include/boost/decimal/detail/fenv_rounding.hpp b/include/boost/decimal/detail/fenv_rounding.hpp index 4674033e0..ae369d38d 100644 --- a/include/boost/decimal/detail/fenv_rounding.hpp +++ b/include/boost/decimal/detail/fenv_rounding.hpp @@ -202,7 +202,7 @@ constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bo using demoted_integer_type = std::conditional_t::digits10 < std::numeric_limits::digits10, T1, sig_type>; // How many digits need to be shifted? - const auto shift_for_large_coeff {(coeff_digits - detail::precision_v) - 1}; + const int shift_for_large_coeff {(coeff_digits - detail::precision_v) - 1}; int shift {}; BOOST_DECIMAL_IF_CONSTEXPR (is_fast_type_v) { @@ -212,7 +212,7 @@ constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bo } else { - const auto shift_for_small_exp {(-biased_exp) - 1}; + const auto shift_for_small_exp {static_cast((-biased_exp) - 1)}; shift = std::max(shift_for_small_exp, shift_for_large_coeff); } diff --git a/include/boost/decimal/detail/mul_impl.hpp b/include/boost/decimal/detail/mul_impl.hpp index 8d8b4d9be..7ec48e9ce 100644 --- a/include/boost/decimal/detail/mul_impl.hpp +++ b/include/boost/decimal/detail/mul_impl.hpp @@ -162,11 +162,11 @@ constexpr auto d128_mul_impl(const T1& lhs_sig, const U1 lhs_exp, const bool lhs // 34 is the number of digits in the d128 significand // this way we can skip rounding in the constructor a second time - const auto digit_delta {sig_dig - 34}; + const auto digit_delta {sig_dig - std::numeric_limits::digits10}; if (BOOST_DECIMAL_LIKELY(digit_delta > 0)) { - res_sig /= pow10(digit_delta); - res_exp += digit_delta; + auto biased_exp {res_exp + detail::bias_v}; + detail::coefficient_rounding(res_sig, res_exp, biased_exp, sign, sig_dig); } BOOST_DECIMAL_ASSERT((res_sig[3] | res_sig[2]) == 0U); diff --git a/test/github_issue_1026.cpp b/test/github_issue_1026.cpp index 5a75afc42..94ee6badb 100644 --- a/test/github_issue_1026.cpp +++ b/test/github_issue_1026.cpp @@ -45,6 +45,8 @@ int main() BOOST_TEST_EQ("9999999999999999999999999992345678.49"_DL, "9999999999999999999999999992345678"_DL); BOOST_TEST_EQ("9999999999999999999999999992345678.50"_DL, "9999999999999999999999999992345678"_DL); BOOST_TEST_EQ("9999999999999999999999999992345678.51"_DL, "9999999999999999999999999992345679"_DL); + BOOST_TEST_EQ("145433.2908011933696719165119928295655062562131932287426051970822"_DL, "145433.2908011933696719165119928296"_DL); + BOOST_TEST_EQ("30269.587755640502150977251770554"_DL * "4.8046009735990873395936309640543"_DL, "145433.2908011933696719165119928296"_DL); BOOST_TEST_EQ(("0"_DF + "8.4e-96"_DF), "8.4e-96"_DF); BOOST_TEST_EQ(("0"_DF + std::numeric_limits::denorm_min()), std::numeric_limits::denorm_min());