diff --git a/include/boost/decimal/decimal128_t.hpp b/include/boost/decimal/decimal128_t.hpp index 50ec691ab..fef79398c 100644 --- a/include/boost/decimal/decimal128_t.hpp +++ b/include/boost/decimal/decimal128_t.hpp @@ -728,7 +728,7 @@ constexpr decimal128_t::decimal128_t(T1 coeff, T2 exp, bool sign) noexcept { if (coeff > detail::d128_max_significand_value || biased_exp < 0) { - coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign); + coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign, detail::num_digits(coeff)); } } diff --git a/include/boost/decimal/decimal32_t.hpp b/include/boost/decimal/decimal32_t.hpp index 334e5e41b..5eeb811c7 100644 --- a/include/boost/decimal/decimal32_t.hpp +++ b/include/boost/decimal/decimal32_t.hpp @@ -635,7 +635,7 @@ constexpr decimal32_t::decimal32_t(T1 coeff, T2 exp, bool sign) noexcept // NOLI auto biased_exp {static_cast(exp + detail::bias)}; if (coeff > detail::d32_max_significand_value || biased_exp < 0) { - coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign); + coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign, detail::num_digits(coeff)); } auto reduced_coeff {static_cast(coeff)}; diff --git a/include/boost/decimal/decimal64_t.hpp b/include/boost/decimal/decimal64_t.hpp index afb7f2172..5c6e82276 100644 --- a/include/boost/decimal/decimal64_t.hpp +++ b/include/boost/decimal/decimal64_t.hpp @@ -629,7 +629,7 @@ constexpr decimal64_t::decimal64_t(T1 coeff, T2 exp, bool sign) noexcept auto biased_exp {static_cast(exp) + detail::bias_v}; if (coeff > detail::d64_max_significand_value || biased_exp < 0) { - coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign); + coeff_digits = detail::coefficient_rounding(coeff, exp, biased_exp, sign, detail::num_digits(coeff)); } auto reduced_coeff {static_cast(coeff)}; diff --git a/include/boost/decimal/detail/fenv_rounding.hpp b/include/boost/decimal/detail/fenv_rounding.hpp index 6297ba62a..7acf79dbd 100644 --- a/include/boost/decimal/detail/fenv_rounding.hpp +++ b/include/boost/decimal/detail/fenv_rounding.hpp @@ -182,14 +182,12 @@ constexpr auto fenv_round(T& val, bool is_neg = false, bool sticky = false) noex #endif template -constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bool sign) noexcept +constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bool sign, int coeff_digits) noexcept { // T1 will be a 128-bit or 256-bit using sig_type = typename TargetDecimalType::significand_type; using demoted_integer_type = std::conditional_t::digits10 < std::numeric_limits::digits10, T1, sig_type>; - auto coeff_digits {detail::num_digits(coeff)}; - // How many digits need to be shifted? const auto shift_for_large_coeff {(coeff_digits - detail::precision_v) - 1}; int shift {}; diff --git a/include/boost/decimal/detail/normalize.hpp b/include/boost/decimal/detail/normalize.hpp index a2f1f35e7..5af8890d1 100644 --- a/include/boost/decimal/detail/normalize.hpp +++ b/include/boost/decimal/detail/normalize.hpp @@ -31,7 +31,7 @@ constexpr auto normalize(T1& significand, T2& exp, bool sign = false) noexcept - else if (digits > target_precision) { auto biased_exp {static_cast(exp) + detail::bias_v}; - detail::coefficient_rounding(significand, exp, biased_exp, sign); + detail::coefficient_rounding(significand, exp, biased_exp, sign, digits); } }