Skip to content

Commit 83f3032

Browse files
add docstring test for omega
1 parent bfeb0a9 commit 83f3032

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn mod_mul(a: i64, b: i64, p: i64) -> i64 {
2121
///
2222
/// # Returns
2323
/// The result of the exponentiation modulo `p`.
24-
fn mod_exp(mut base: i64, mut exp: i64, p: i64) -> i64 {
24+
pub fn mod_exp(mut base: i64, mut exp: i64, p: i64) -> i64 {
2525
let mut result = 1;
2626
base %= p;
2727
while exp > 0 {
@@ -68,6 +68,20 @@ fn mod_inv(a: i64, modulus: i64) -> i64 {
6868
///
6969
/// # Returns
7070
/// The n-th root of unity modulo `modulus`.
71+
///
72+
/// # Examples
73+
///
74+
/// ```
75+
/// // For modulus = 17^2 = 289 and n = 8, we compute an 8th root of unity.
76+
/// let modulus = 17 * 17;
77+
/// let n = 8;
78+
///
79+
/// // Compute the omega for the given modulus and order.
80+
/// let omega = ntt::omega(modulus, n);
81+
///
82+
/// // Verify that omega^n is congruent to 1 modulo modulus.
83+
/// assert_eq!(ntt::mod_exp(omega, n as i64, modulus), 1);
84+
/// ```
7185
pub fn omega(modulus: i64, n: usize) -> i64 {
7286
let factors = factorize(modulus as i64);
7387
if factors.len() == 1 {

0 commit comments

Comments
 (0)