Skip to content

Commit e8435d3

Browse files
committed
test: add regression test for faster division of base_uint<256> to uint32_t
1 parent de1e56a commit e8435d3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/test/arith_uint256_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,19 @@ BOOST_AUTO_TEST_CASE( divide )
361361
BOOST_CHECK(R2L / MaxL == ZeroL);
362362
BOOST_CHECK(MaxL / R2L == 1);
363363
BOOST_CHECK_THROW(R2L / ZeroL, uint_error);
364+
365+
// The integer-divisor overload must be bit-identical to dividing by the same
366+
// value widened to arith_uint256, for both the fast word-wise path
367+
// (<= uint32 max) and the arith_uint256 fallback above it.
368+
for (uint64_t d : {uint64_t{1}, uint64_t{2}, uint64_t{24}, uint64_t{3600},
369+
uint64_t{std::numeric_limits<uint32_t>::max()},
370+
uint64_t{std::numeric_limits<uint32_t>::max()} + 1,
371+
uint64_t{0xFEDCBA9876543210}}) {
372+
BOOST_CHECK(R1L / d == R1L / arith_uint256(d));
373+
BOOST_CHECK(R2L / d == R2L / arith_uint256(d));
374+
BOOST_CHECK(MaxL / d == MaxL / arith_uint256(d));
375+
}
376+
BOOST_CHECK_THROW(R1L / uint64_t{0}, uint_error);
364377
}
365378

366379

0 commit comments

Comments
 (0)