Skip to content

Commit 7d44a84

Browse files
authored
Merge pull request #1125 from cppalliance/1111
Avoid double counting digits in normalization process
2 parents d6ba003 + c88023f commit 7d44a84

File tree

5 files changed

+5
-7
lines changed

5 files changed

+5
-7
lines changed

include/boost/decimal/decimal128_t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ constexpr decimal128_t::decimal128_t(T1 coeff, T2 exp, bool sign) noexcept
728728
{
729729
if (coeff > detail::d128_max_significand_value || biased_exp < 0)
730730
{
731-
coeff_digits = detail::coefficient_rounding<decimal128_t>(coeff, exp, biased_exp, sign);
731+
coeff_digits = detail::coefficient_rounding<decimal128_t>(coeff, exp, biased_exp, sign, detail::num_digits(coeff));
732732
}
733733
}
734734

include/boost/decimal/decimal32_t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ constexpr decimal32_t::decimal32_t(T1 coeff, T2 exp, bool sign) noexcept // NOLI
635635
auto biased_exp {static_cast<int>(exp + detail::bias)};
636636
if (coeff > detail::d32_max_significand_value || biased_exp < 0)
637637
{
638-
coeff_digits = detail::coefficient_rounding<decimal32_t>(coeff, exp, biased_exp, sign);
638+
coeff_digits = detail::coefficient_rounding<decimal32_t>(coeff, exp, biased_exp, sign, detail::num_digits(coeff));
639639
}
640640

641641
auto reduced_coeff {static_cast<significand_type>(coeff)};

include/boost/decimal/decimal64_t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ constexpr decimal64_t::decimal64_t(T1 coeff, T2 exp, bool sign) noexcept
629629
auto biased_exp {static_cast<int>(exp) + detail::bias_v<decimal64_t>};
630630
if (coeff > detail::d64_max_significand_value || biased_exp < 0)
631631
{
632-
coeff_digits = detail::coefficient_rounding<decimal64_t>(coeff, exp, biased_exp, sign);
632+
coeff_digits = detail::coefficient_rounding<decimal64_t>(coeff, exp, biased_exp, sign, detail::num_digits(coeff));
633633
}
634634

635635
auto reduced_coeff {static_cast<significand_type>(coeff)};

include/boost/decimal/detail/fenv_rounding.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,12 @@ constexpr auto fenv_round(T& val, bool is_neg = false, bool sticky = false) noex
182182
#endif
183183

184184
template <typename TargetDecimalType, typename T1, typename T2, typename T3>
185-
constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bool sign) noexcept
185+
constexpr auto coefficient_rounding(T1& coeff, T2& exp, T3& biased_exp, const bool sign, int coeff_digits) noexcept
186186
{
187187
// T1 will be a 128-bit or 256-bit
188188
using sig_type = typename TargetDecimalType::significand_type;
189189
using demoted_integer_type = std::conditional_t<std::numeric_limits<T1>::digits10 < std::numeric_limits<sig_type>::digits10, T1, sig_type>;
190190

191-
auto coeff_digits {detail::num_digits(coeff)};
192-
193191
// How many digits need to be shifted?
194192
const auto shift_for_large_coeff {(coeff_digits - detail::precision_v<TargetDecimalType>) - 1};
195193
int shift {};

include/boost/decimal/detail/normalize.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ constexpr auto normalize(T1& significand, T2& exp, bool sign = false) noexcept -
3131
else if (digits > target_precision)
3232
{
3333
auto biased_exp {static_cast<int>(exp) + detail::bias_v<TargetDecimalType>};
34-
detail::coefficient_rounding<TargetDecimalType>(significand, exp, biased_exp, sign);
34+
detail::coefficient_rounding<TargetDecimalType>(significand, exp, biased_exp, sign, digits);
3535
}
3636
}
3737

0 commit comments

Comments
 (0)