fix subtraction

This commit is contained in:
wborgeaud 2021-05-04 17:53:45 +02:00
parent c464c038af
commit 20dae028d8
2 changed files with 11 additions and 1 deletions

View File

@ -268,7 +268,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)
}
}

View File

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