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); }); });