use crate::gaussian_rational::GaussianRational;
use core::cmp::Ordering::{self, Equal};
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
fn combine(x: Ordering, y: Ordering) -> Option<Ordering> {
if x == y || y == Equal {
Some(x)
} else if x == Equal {
Some(y)
} else {
None
}
}
impl EqAbs<GaussianInteger> for GaussianRational {
fn eq_abs(&self, other: &GaussianInteger) -> bool {
if let Some(o) = combine(
self.real.partial_cmp_abs(&other.real).unwrap(),
self.imaginary.partial_cmp_abs(&other.imaginary).unwrap(),
) {
return o == Equal;
}
if let Some(o) = combine(
self.real.partial_cmp_abs(&other.imaginary).unwrap(),
self.imaginary.partial_cmp_abs(&other.real).unwrap(),
) {
return o == Equal;
}
self.abs_squared() == other.abs_squared()
}
}
impl EqAbs<GaussianRational> for GaussianInteger {
#[inline]
fn eq_abs(&self, other: &GaussianRational) -> bool {
other.eq_abs(self)
}
}