66#define BOOST_DECIMAL_DETAIL_DIV_IMPL_HPP
77
88#include < boost/decimal/detail/config.hpp>
9+ #include < boost/decimal/detail/u256.hpp>
910#include < boost/int128/int128.hpp>
1011
1112#ifndef BOOST_DECIMAL_BUILD_MODULE
@@ -56,7 +57,7 @@ constexpr auto d64_generic_div_impl(const T& lhs, const T& rhs) noexcept -> Deci
5657 constexpr auto tens_needed {detail::pow10 (static_cast <unsigned_int128_type>(detail::precision_v<decimal64>))};
5758 const auto big_sig_lhs {static_cast <unsigned_int128_type>(lhs.sig ) * tens_needed};
5859
59- auto res_sig {big_sig_lhs / static_cast <unsigned_int128_type>( rhs.sig ) };
60+ auto res_sig {big_sig_lhs / rhs.sig };
6061 auto res_exp {(lhs.exp - detail::precision_v<decimal64>) - rhs.exp };
6162
6263 if (res_sig == 0U )
@@ -76,24 +77,24 @@ constexpr auto d128_generic_div_impl(const T& lhs, const T& rhs, T& q) noexcept
7677 constexpr auto ten_pow_precision {pow10 (int128::uint128_t (detail::precision_v<decimal128>))};
7778 const auto big_sig_lhs {detail::umul256 (lhs.sig , ten_pow_precision)};
7879
79- // TODO(mborland): Make this u256 / u128 rather than 256/256
80- auto res_sig {big_sig_lhs / detail::uint256_t (rhs.sig )};
80+ auto res_sig {big_sig_lhs / rhs.sig };
8181 auto res_exp {lhs.exp - rhs.exp - detail::precision_v<decimal128>};
8282
83- if (res_sig. high != UINT64_C ( 0 ) )
83+ if (res_sig[ 3 ] != 0 || res_sig[ 2 ] != 0 )
8484 {
8585 const auto sig_dig {detail::num_digits (res_sig)};
8686 const auto digit_delta {sig_dig - std::numeric_limits<int128::uint128_t >::digits10};
87- res_sig /= detail::uint256_t ( pow10 (int128::uint128_t (digit_delta) ));
87+ res_sig /= pow10 (int128::uint128_t (digit_delta));
8888 res_exp += digit_delta;
8989 }
90- else if (res_sig. low == UINT64_C ( 0 ) )
90+ else if (res_sig[ 1 ] == 0 && res_sig[ 0 ] == 0 )
9191 {
9292 sign = false ;
9393 }
9494
9595 // Let the constructor handle shrinking it back down and rounding correctly
96- q = T {res_sig.low , res_exp, sign};
96+ BOOST_DECIMAL_ASSERT ((res_sig[3 ] | res_sig[2 ]) == 0U );
97+ q = T {int128::uint128_t {res_sig[1 ], res_sig[0 ]}, res_exp, sign};
9798}
9899
99100} // namespace detail
0 commit comments