Skip to content

Commit

Permalink
Use wrapping subs instead of saturating subs
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Aug 21, 2024
1 parent c67d6ac commit bec0f0c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/uint/boxed/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub(crate) fn div_rem_vartime_in_place(x: &mut [Limb], y: &mut [Limb]) {
(x[xi + i + 1 - yc], carry) =
x[xi + i + 1 - yc].adc(Limb::select(Limb::ZERO, y[i], ct_borrow), carry);
}
ct_borrow.select_word(quo, quo.saturating_sub(1))
ct_borrow.select_word(quo, quo.wrapping_sub(1))
};

// Store the quotient within dividend and set x_hi to the current highest word
Expand Down
2 changes: 1 addition & 1 deletion src/uint/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
x[xi + i + 1 - yc].adc(Limb::select(Limb::ZERO, y[i], ct_borrow), carry);
i += 1;
}
ct_borrow.select_word(quo, quo.saturating_sub(1))
ct_borrow.select_word(quo, quo.wrapping_sub(1))
};

// Store the quotient within dividend and set x_hi to the current highest word
Expand Down
2 changes: 1 addition & 1 deletion src/uint/div_limb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub(crate) const fn div3by2(
// If r < b and q*y[-2] > r*x[-1], then set q = q - 1 and r = r + v1
let done = ConstChoice::from_word_nonzero((rem >> Word::BITS) as Word)
.or(ConstChoice::from_wide_word_le(qy, rx));
quo = done.select_word(quo.saturating_sub(1), quo);
quo = done.select_word(quo.wrapping_sub(1), quo);
rem = done.select_wide_word(rem + (v1_reciprocal.divisor_normalized as WideWord), rem);
i += 1;
}
Expand Down

0 comments on commit bec0f0c

Please sign in to comment.