Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions include/boost/decimal/decimal128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,14 +1606,14 @@ std::ostream& operator<<( std::ostream& os, boost::decimal::detail::builtin_uint

BOOST_DECIMAL_CUDA_CONSTEXPR auto d128_div_impl(const decimal128_t& lhs, const decimal128_t& rhs, decimal128_t& q, decimal128_t& r) noexcept -> void
{
const bool sign {lhs.isneg() != rhs.isneg()};

#ifndef BOOST_DECIMAL_FAST_MATH
// Check pre-conditions
constexpr decimal128_t zero {0, 0};
constexpr decimal128_t nan {from_bits(detail::d128_nan_mask)};
constexpr decimal128_t inf {from_bits(detail::d128_inf_mask)};

const bool sign {lhs.isneg() != rhs.isneg()};

const auto lhs_fp {fpclassify(lhs)};
const auto rhs_fp {fpclassify(rhs)};

Expand Down Expand Up @@ -1711,11 +1711,7 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto d128_div_impl(const decimal128_t& lhs, const d
<< "\nexp rhs: " << exp_rhs << std::endl;
#endif

detail::decimal128_t_components q_components {};

detail::d128_generic_div_impl(lhs_components, rhs.to_components(), q_components);

q = decimal128_t(q_components.sig, q_components.exp, q_components.sign);
q = detail::d128_generic_div_impl<decimal128_t>(lhs_components, rhs.to_components(), sign);
}

#ifdef _MSC_VER
Expand Down Expand Up @@ -2010,13 +2006,13 @@ template <typename Integer>
BOOST_DECIMAL_CUDA_CONSTEXPR auto operator/(const decimal128_t lhs, const Integer rhs) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal128_t)
{
const bool sign {lhs.isneg() != (rhs < 0)};

#ifndef BOOST_DECIMAL_FAST_MATH
// Check pre-conditions
constexpr decimal128_t zero {0, 0};
constexpr decimal128_t inf {from_bits(detail::d128_inf_mask)};

const bool sign {lhs.isneg() != (rhs < 0)};

const auto lhs_fp {fpclassify(lhs)};

switch (lhs_fp)
Expand All @@ -2041,24 +2037,21 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto operator/(const decimal128_t lhs, const Intege
detail::expand_significand<decimal128_t>(lhs_components.sig, lhs_components.exp);

const detail::decimal128_t_components rhs_components {detail::make_positive_unsigned(rhs), 0, rhs < 0};
detail::decimal128_t_components q_components {};

detail::d128_generic_div_impl(lhs_components, rhs_components, q_components);

return decimal128_t(q_components.sig, q_components.exp, q_components.sign);
return detail::d128_generic_div_impl<decimal128_t>(lhs_components, rhs_components, sign);
}

template <typename Integer>
BOOST_DECIMAL_CUDA_CONSTEXPR auto operator/(const Integer lhs, const decimal128_t rhs) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal128_t)
{
const bool sign {(lhs < 0) != rhs.isneg()};

#ifndef BOOST_DECIMAL_FAST_MATH
// Check pre-conditions
constexpr decimal128_t zero {0, 0};
constexpr decimal128_t inf {from_bits(detail::d128_inf_mask)};

const bool sign {(lhs < 0) != rhs.isneg()};

const auto rhs_fp {fpclassify(rhs)};

switch (rhs_fp)
Expand All @@ -2078,11 +2071,8 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto operator/(const Integer lhs, const decimal128_
detail::expand_significand<decimal128_t>(rhs_components.sig, rhs_components.exp);

const detail::decimal128_t_components lhs_components {detail::make_positive_unsigned(lhs), 0, lhs < 0};
detail::decimal128_t_components q_components {};

detail::d128_generic_div_impl(lhs_components, rhs_components, q_components);

return decimal128_t(q_components.sig, q_components.exp, q_components.sign);
return detail::d128_generic_div_impl<decimal128_t>(lhs_components, rhs_components, sign);
}

BOOST_DECIMAL_CUDA_CONSTEXPR auto operator%(const decimal128_t& lhs, const decimal128_t& rhs) noexcept -> decimal128_t
Expand Down
33 changes: 7 additions & 26 deletions include/boost/decimal/decimal_fast128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,20 +1399,7 @@ constexpr auto d128f_div_impl(const decimal_fast128_t& lhs, const decimal_fast12
static_cast<void>(r);
#endif

#ifdef BOOST_DECIMAL_DEBUG
std::cerr << "sig lhs: " << sig_lhs
<< "\nexp lhs: " << exp_lhs
<< "\nsig rhs: " << sig_rhs
<< "\nexp rhs: " << exp_rhs << std::endl;
#endif

constexpr auto ten_pow_precision {detail::pow10(int128::uint128_t(detail::precision_v<decimal_fast128_t>))};
const auto big_sig_lhs {detail::umul256(lhs.significand_, ten_pow_precision)};

const auto res_sig {big_sig_lhs / rhs.significand_};
const auto res_exp {lhs.biased_exponent() - rhs.biased_exponent() - detail::precision_v<decimal_fast128_t>};

q = decimal_fast128_t(static_cast<int128::uint128_t>(res_sig), res_exp, sign);
q = detail::d128_generic_div_impl<decimal_fast128_t>(lhs.to_components(), rhs.to_components(), sign);
}

constexpr auto operator/(const decimal_fast128_t& lhs, const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t
Expand All @@ -1428,13 +1415,13 @@ template <typename Integer>
constexpr auto operator/(const decimal_fast128_t& lhs, const Integer rhs) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal_fast128_t)
{
const bool sign {lhs.isneg() != (rhs < 0)};

#ifndef BOOST_DECIMAL_FAST_MATH
// Check pre-conditions
constexpr decimal_fast128_t zero {0, 0};
constexpr decimal_fast128_t inf {direct_init_d128(detail::d128_fast_inf, 0, false)};

const bool sign {lhs.isneg() != (rhs < 0)};

const auto lhs_fp {fpclassify(lhs)};

switch (lhs_fp)
Expand All @@ -1459,24 +1446,21 @@ constexpr auto operator/(const decimal_fast128_t& lhs, const Integer rhs) noexce

const auto rhs_sig {detail::make_positive_unsigned(rhs)};
const detail::decimal_fast128_t_components rhs_components {rhs_sig, 0, rhs < 0};
detail::decimal_fast128_t_components q_components {};

detail::d128_generic_div_impl(lhs_components, rhs_components, q_components);

return {q_components.sig, q_components.exp, q_components.sign};
return detail::d128_generic_div_impl<decimal_fast128_t>(lhs_components, rhs_components, sign);
}

template <typename Integer>
constexpr auto operator/(const Integer lhs, const decimal_fast128_t& rhs) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_integral_v, Integer, decimal_fast128_t)
{
const bool sign {(lhs < 0) != rhs.isneg()};

#ifndef BOOST_DECIMAL_FAST_MATH
// Check pre-conditions
constexpr decimal_fast128_t zero {0, 0};
constexpr decimal_fast128_t inf {direct_init_d128(detail::d128_fast_inf, 0, false)};

const bool sign {(lhs < 0) != rhs.isneg()};

const auto rhs_fp {fpclassify(rhs)};

switch (rhs_fp)
Expand All @@ -1494,11 +1478,8 @@ constexpr auto operator/(const Integer lhs, const decimal_fast128_t& rhs) noexce

const detail::decimal_fast128_t_components lhs_components {detail::make_positive_unsigned(lhs), 0, lhs < 0};
const detail::decimal_fast128_t_components rhs_components {rhs.significand_, rhs.biased_exponent(), rhs.isneg()};
detail::decimal_fast128_t_components q_components {};

detail::d128_generic_div_impl(lhs_components, rhs_components, q_components);

return {q_components.sig, q_components.exp, q_components.sign};
return detail::d128_generic_div_impl<decimal_fast128_t>(lhs_components, rhs_components, sign);
}

constexpr auto operator%(const decimal_fast128_t& lhs, const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t
Expand Down
20 changes: 1 addition & 19 deletions include/boost/decimal/decimal_fast64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,25 +1521,7 @@ constexpr auto d64_fast_div_impl(const decimal_fast64_t& lhs, const decimal_fast
static_cast<void>(r);
#endif

#ifdef BOOST_DECIMAL_DEBUG
std::cerr << "sig lhs: " << sig_lhs
<< "\nexp lhs: " << exp_lhs
<< "\nsig rhs: " << sig_rhs
<< "\nexp rhs: " << exp_rhs << std::endl;
#endif

using unsigned_int128_type = boost::int128::uint128_t;

// If rhs is greater than we need to offset the significands to get the correct values
// e.g. 4/8 is 0 but 40/8 yields 5 in integer maths
constexpr auto offset {std::numeric_limits<unsigned_int128_type>::digits10 - detail::precision_v<decimal_fast64_t>};
constexpr auto tens_needed {detail::pow10(static_cast<unsigned_int128_type>(offset))};
const auto big_sig_lhs {static_cast<unsigned_int128_type>(lhs.significand_) * tens_needed};

const auto res_sig {big_sig_lhs / rhs.significand_};
const auto res_exp {(lhs.biased_exponent() - offset) - rhs.biased_exponent()};

q = decimal_fast64_t{res_sig, res_exp, sign};
q = detail::d64_generic_div_impl<decimal_fast64_t>(lhs.to_components(), rhs.to_components(), sign);
}

constexpr auto operator/(const decimal_fast64_t& lhs, const decimal_fast64_t& rhs) noexcept -> decimal_fast64_t
Expand Down
Loading
Loading