Skip to content

Commit

Permalink
Make Uint::gcd a const fn
Browse files Browse the repository at this point in the history
All the prerequisites are there. It was simply an oversight not making
it so in #472.
  • Loading branch information
tarcieri committed Dec 19, 2023
1 parent f990e36 commit 1279ba4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modular/bernstein_yang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize>
///
/// This is defined on this type to piggyback on the definitions for `SAT_LIMBS` and `UNSAT_LIMBS` which are
/// computed when defining `PrecomputeInverter::Inverter` for various `Uint` limb sizes.
pub(crate) fn gcd(f: &Uint<SAT_LIMBS>, g: &Uint<SAT_LIMBS>) -> Uint<SAT_LIMBS> {
pub(crate) const fn gcd(f: &Uint<SAT_LIMBS>, g: &Uint<SAT_LIMBS>) -> Uint<SAT_LIMBS> {
let f_0 = Int62L::from_uint(f);
let inverse = inv_mod2_62(f.as_words());

Expand Down
4 changes: 2 additions & 2 deletions src/uint/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ where
/// Compute the greatest common divisor (GCD) of this number and another.
///
/// Panics if `self` is odd.
pub fn gcd(&self, rhs: &Self) -> Self {
debug_assert!(bool::from(self.is_odd()));
pub const fn gcd(&self, rhs: &Self) -> Self {
debug_assert!(self.is_odd().is_true_vartime());
<Self as PrecomputeInverter>::Inverter::gcd(self, rhs)
}
}
Expand Down

0 comments on commit 1279ba4

Please sign in to comment.