From a3d9f38682d428da59ce0b970c4e33499f0653bf Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 18 Dec 2024 13:44:18 +0100 Subject: [PATCH] Implement Neg for FieldElement. (#2252) --- executor/src/witgen/jit/compiler.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/executor/src/witgen/jit/compiler.rs b/executor/src/witgen/jit/compiler.rs index 19f54799e..3f8969229 100644 --- a/executor/src/witgen/jit/compiler.rs +++ b/executor/src/witgen/jit/compiler.rs @@ -368,6 +368,17 @@ impl std::ops::Sub for FieldElement {{ Self(IntType::try_from(((self.0 as DoubleIntType) + (MODULUS as DoubleIntType) - (b.0 as DoubleIntType)) % (MODULUS as DoubleIntType)).unwrap()) }} }} +impl std::ops::Neg for FieldElement {{ + type Output = Self; + #[inline] + fn neg(self) -> Self {{ + if self.0 == 0 {{ + self + }} else {{ + Self(MODULUS - self.0) + }} + }} +}} impl std::ops::Mul for FieldElement {{ type Output = Self; #[inline]