Skip to content

Commit 94f7fe0

Browse files
authored
Merge pull request #905 from cppalliance/u256_integration
U256 integration
2 parents 5b4cf2b + 0ff4fdc commit 94f7fe0

File tree

12 files changed

+47
-2372
lines changed

12 files changed

+47
-2372
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <boost/decimal/detail/bit_cast.hpp>
1212
#include <boost/decimal/detail/config.hpp>
1313
#include <boost/int128.hpp>
14-
#include <boost/decimal/detail/emulated256.hpp>
1514
#include <boost/decimal/detail/fenv_rounding.hpp>
1615
#include <boost/decimal/detail/integer_search_trees.hpp>
1716
#include <boost/decimal/detail/parser.hpp>

include/boost/decimal/detail/div_impl.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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

Comments
 (0)