Skip to content

Commit 7250c7c

Browse files
committed
Fix conversion of declets
1 parent 347a3aa commit 7250c7c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/boost/decimal/dpd_conversion.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,12 +802,12 @@ constexpr auto to_dpd_d128(DecimalType val) noexcept
802802
dpd.high |= (combination_field_bits << 58U);
803803
dpd.high |= (trailing_exp_bits << 46U);
804804

805-
// Now we have to encode all 10 of the declets
806-
int offset {9};
805+
// Now we have to encode all 11 of the declets
806+
int offset {10};
807807
for (std::size_t i {1}; i < num_digits - 1; i += 3U)
808808
{
809809
const auto declet {static_cast<detail::uint128>(detail::encode_dpd(d[i], d[i + 1], d[i + 2]))};
810-
dpd |= (declet << (10 * offset));
810+
dpd |= detail::uint128(declet << (10 * offset));
811811
--offset;
812812
}
813813

@@ -892,7 +892,7 @@ constexpr auto from_dpd_d128(detail::uint128 dpd) noexcept
892892
detail::uint128 significand {};
893893
for (int i {}; i < num_digits; ++i)
894894
{
895-
significand += static_cast<detail::uint128>(digits[i]) * detail::pow10(static_cast<detail::uint128>(num_digits - i));
895+
significand += static_cast<detail::uint128>(digits[i]) * detail::pow10(static_cast<detail::uint128>((num_digits - 1) - i));
896896
}
897897

898898
return DecimalType{significand, exp, sign};

0 commit comments

Comments
 (0)