diff --git a/sunscreen_tfhe/src/math/fft/negacyclic/mod.rs b/sunscreen_tfhe/src/math/fft/negacyclic/mod.rs index 540c79a1f..585f4c7ab 100644 --- a/sunscreen_tfhe/src/math/fft/negacyclic/mod.rs +++ b/sunscreen_tfhe/src/math/fft/negacyclic/mod.rs @@ -60,10 +60,13 @@ where let two_pi = T::from(PI).unwrap() * T::from(2.0).unwrap(); - let w_2n = (Complex::from(two_pi / n_2) * Complex::i()).exp(); - let twist = (0..k) - .map(|x| w_2n.powf(T::from(x).unwrap())) + .map(|x| { + let x = T::from(x).unwrap(); + let (s, c) = (two_pi * x / n_2).sin_cos(); + + Complex::new(c, s) + }) .collect::>(); let twist_inv = twist @@ -76,7 +79,7 @@ where let a_a_inv = a * b; let err = a_a_inv - Complex::one(); - err.re.abs() < T::from(1e-12).unwrap() && err.im.abs() < T::from(1e-12).unwrap() + err.re.abs() < T::from(1e-15).unwrap() && err.im.abs() < T::from(1e-15).unwrap() })); Self { diff --git a/sunscreen_tfhe/src/math/polynomial.rs b/sunscreen_tfhe/src/math/polynomial.rs index 94c998adc..74483156f 100644 --- a/sunscreen_tfhe/src/math/polynomial.rs +++ b/sunscreen_tfhe/src/math/polynomial.rs @@ -321,7 +321,7 @@ mod tests { let a = Polynomial::new(&a); let b = (0..n) .map(|_| { - let signed = (rand::thread_rng().next_u64() % 32).reinterpret_as_signed() - 16; + let signed = (rand::thread_rng().next_u64() % (0x1 << 16)).reinterpret_as_signed() - 16; signed.reinterpret_as_unsigned() }) @@ -346,7 +346,7 @@ mod tests { for (a, e) in actual.coeffs().iter().zip(expected.coeffs().iter()) { let err = normalized_torus_distance(a, e).abs(); - assert!(err < 1e-12); + assert!(err < 1e-9); } } }