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