use crate::integer::Integer;
use crate::natural::Natural;
use malachite_base::num::arithmetic::traits::UnsignedAbs;
use malachite_base::num::basic::traits::Zero;
macro_rules! impl_unsigned {
($t: ident) => {
impl PartialEq<$t> for Integer {
#[inline]
fn eq(&self, other: &$t) -> bool {
self.sign && self.abs == *other
}
}
impl PartialEq<Integer> for $t {
#[inline]
fn eq(&self, other: &Integer) -> bool {
other == self
}
}
};
}
apply_to_unsigneds!(impl_unsigned);
fn eq_signed<U, S: Copy + Ord + UnsignedAbs<Output = U> + Zero>(x: &Integer, other: &S) -> bool
where
Natural: PartialEq<U>,
{
x.sign == (*other >= S::ZERO) && x.abs == other.unsigned_abs()
}
macro_rules! impl_signed {
($t: ident) => {
impl PartialEq<$t> for Integer {
fn eq(&self, other: &$t) -> bool {
eq_signed(self, other)
}
}
impl PartialEq<Integer> for $t {
#[inline]
fn eq(&self, other: &Integer) -> bool {
other == self
}
}
};
}
apply_to_signeds!(impl_signed);