diff --git a/src/field/crandall_field.rs b/src/field/crandall_field.rs index b94d36a3..99028016 100644 --- a/src/field/crandall_field.rs +++ b/src/field/crandall_field.rs @@ -363,7 +363,7 @@ impl Sub for CrandallField { #[inline] #[allow(clippy::suspicious_arithmetic_impl)] fn sub(self, rhs: Self) -> Self { - let (diff, under) = self.0.overflowing_sub(rhs.0); + let (diff, under) = self.0.overflowing_sub(rhs.to_canonical_u64()); Self(diff.overflowing_add((under as u64) * Self::ORDER).0) } } diff --git a/src/field/field_testing.rs b/src/field/field_testing.rs index bcb190e8..77b23ea3 100644 --- a/src/field/field_testing.rs +++ b/src/field/field_testing.rs @@ -305,6 +305,16 @@ macro_rules! test_arithmetic { } } } + + #[test] + fn subtraction() { + type F = $field; + + let (a, b) = (F::from_canonical_u64((F::ORDER + 1) / 2), F::TWO); + let x = a * b; + assert_eq!(x, F::ONE); + assert_eq!(F::ZERO - x, F::NEG_ONE); + } } }; }