Skip to content

Commit

Permalink
add Fp::m1pow
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtkana committed Jul 24, 2024
1 parent e419e10 commit 6b3c2f9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libs/fp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ impl<const P: u64> Fp<P> {
self.value
}

/// $(-1) ^ e$.
/// # Examples
/// ```
/// use fp::Fp;
/// const P: u64 = 998244353;
/// assert_eq!(Fp::<P>::m1pow(0), Fp::new(1));
/// assert_eq!(Fp::<P>::m1pow(1), Fp::from(-1));
/// assert_eq!(Fp::<P>::m1pow(2), Fp::new(1));
/// ```
pub const fn m1pow(exp: usize) -> Self {
match exp % 2 {
0 => Self { value: 1 },
1 => Self { value: P - 1 },
_ => unreachable!(),
}
}

/// Returns the multiplicative inverse.
/// # Examples
/// ```
Expand Down

0 comments on commit 6b3c2f9

Please sign in to comment.