From fdcb45754d9e86c68ca87fff0e65786ee10cf8da Mon Sep 17 00:00:00 2001 From: bhargav Date: Sat, 18 Nov 2023 20:08:01 -0800 Subject: [PATCH] feat: elementary school addition/multiplication --- src/ntt.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ntt.rs b/src/ntt.rs index dadbf7c..7f9ac35 100644 --- a/src/ntt.rs +++ b/src/ntt.rs @@ -132,8 +132,16 @@ fn fft(inp: Vec, c: &Constants, w: BigInt) -> Vec { .zip(hi) .enumerate() .for_each(|(idx, (lo, hi))| { - let neg = (*lo).sub_mod(*hi, MOD); - *lo = (*lo).add_mod(*hi, MOD); + let neg = if *lo < *hi { + (MOD + *lo) - *hi + } else { + *lo - *hi + }; + *lo = if *lo + *hi >= MOD { + (*lo + *hi) - MOD + } else { + *lo + *hi + }; *hi = neg.mul_mod(pre[nchunks * idx], MOD); }); });