Skip to content

Commit 90bd785

Browse files
committed
Update the B-Z test comments
1 parent 9be1ab7 commit 90bd785

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

tests/biguint.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -924,18 +924,16 @@ fn test_div_rem_big_multiple() {
924924

925925
#[test]
926926
fn test_div_rem_burnikel_ziegler_u1_equals_d() {
927-
// Construct u and d such that the B-Z entry point sees u1 == d.
927+
// Construct u and d such that div_blocks' most-significant block equals d.
928928
//
929929
// d has 65 u64-digits (130 u32-digits) with MSB set, ensuring:
930930
// - d.len() > 64 (enters B-Z)
931-
// - no normalization shift (MSB already set)
931+
// - level = next_power_of_two(65) = 128
932932
//
933-
// u = d << 8192 + 42, so u's high part (split at `level` digits) is exactly d.
934-
// For u64: u.len()=193, level=128, split gives u1=d
935-
// For u32: u.len()=386, level=256, split gives u1=d
936-
//
937-
// The entry point originally had `if &u1 > d` (should be >=), so the else branch was
938-
// taken with u1==d, violating div_two_digit_by_one's precondition ah < b.
933+
// The normalization shift pads d to fill the full 128 digits. Then u = d << 8192 + 42 is also
934+
// shifted, so the most-significant block of u (chunked at `level` digits) equals d exactly.
935+
// So div_blocks must not peel it off as the initial remainder (since it's not strictly less
936+
// than d), instead starting with r = 0.
939937
let d = (BigUint::one() << 4159usize) + BigUint::one();
940938
let remainder = BigUint::from(42u32);
941939
let u = (&d << 8192usize) + &remainder;
@@ -951,12 +949,11 @@ fn test_div_rem_burnikel_ziegler_a1_equals_b1() {
951949
// This triggered a bug for the missing a1 >= b1 guard in div_three_halves_by_two
952950
// (Algorithm 2, step 3b of the Burnikel-Ziegler paper).
953951
//
954-
// d has 65 u64-digits (130 u32-digits). In div_two_digit_by_one, the normalization
955-
// shift pads d to fill `level` digits. After div_two_digit_by_one_normalized splits
956-
// both ah and the shifted d at the half-level, the second div_three_halves_by_two call
957-
// receives a remainder whose upper half equals b1 (the upper half of the shifted d).
958-
// It then called div_two_digit_by_one(a1, a2, b1, level) with a1 == b1, violating the
959-
// a1 < b1 precondition.
952+
// d has 65 u64-digits (130 u32-digits). The top-level normalization shift pads d to fill
953+
// `level` digits, and div_two_digit_by_one splits both ah and the shifted d at the half-level.
954+
// Then the second div_three_halves_by_two call receives a remainder whose upper half equals b1
955+
// (the upper half of the shifted d). It then called div_two_digit_by_one(a1, a2, b1, level)
956+
// with a1 == b1, violating the a1 < b1 precondition.
960957
//
961958
// The quotient ((1 << 4096) - 1) is chosen so the remainder is d - 1, which shares
962959
// the same upper half as d after normalization.

0 commit comments

Comments
 (0)