use super::super::Z;
use flint3_sys::fmpz_neg;
use std::ops::Neg;
impl Neg for Z {
type Output = Z;
fn neg(mut self) -> Self::Output {
unsafe { fmpz_neg(&mut self.value, &self.value) };
self
}
}
impl Neg for &Z {
type Output = Z;
fn neg(self) -> Self::Output {
let mut out = Z::default();
unsafe { fmpz_neg(&mut out.value, &self.value) };
out
}
}
#[cfg(test)]
mod test_neg {
use super::Z;
#[test]
fn correct_small() {
let a: Z = Z::ONE;
let b: Z = Z::MINUS_ONE;
let c: Z = Z::ZERO;
assert_eq!(a, -(-&a));
assert_eq!(a, -&b);
assert_eq!(b, -&a);
assert_eq!(a, -b.clone());
assert_eq!(b, -a);
assert_eq!(c, -&c);
assert_eq!(c.clone(), -c);
}
#[test]
fn correct_large() {
let a: Z = Z::from(u64::MAX);
let b: Z = Z::from(i64::MAX);
assert_eq!(a, -(-&a));
assert_eq!(b, -(-&b));
}
}