Skip to content

Commit 99fe692

Browse files
committed
Add non-zero divisor assumption
1 parent bdbe32a commit 99fe692

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/boost/decimal/detail/u128.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2001,8 +2001,10 @@ constexpr void divide_knuth_core(std::uint32_t (&u)[u_size],
20012001
}
20022002
}
20032003

2004-
BOOST_DECIMAL_FORCE_INLINE constexpr void div_mod_impl(const u128& lhs, const std::uint64_t rhs, u128& quotient, u128& remainder) noexcept
2004+
constexpr void div_mod_impl(const u128& lhs, const std::uint64_t rhs, u128& quotient, u128& remainder) noexcept
20052005
{
2006+
BOOST_DECIMAL_ASSUME(rhs != 0);
2007+
20062008
// If rhs is greater than 2^32 the result is trivial to find
20072009
if (rhs >= UINT32_MAX)
20082010
{
@@ -2055,7 +2057,7 @@ BOOST_DECIMAL_FORCE_INLINE constexpr void div_mod_impl(const u128& lhs, const st
20552057
divide_knuth_core(u, v, q);
20562058

20572059
quotient.low = (static_cast<std::uint64_t>(q[1]) << 32) | q[0];
2058-
quotient.high = q[3];
2060+
quotient.high = q[2];
20592061
remainder.low = (static_cast<std::uint64_t>(u[1]) << (32 - offset)) | (static_cast<std::uint64_t>(u[0]) >> offset);
20602062
}
20612063

0 commit comments

Comments
 (0)