use crate::gaussian_integer::GaussianInteger;
use crate::integer::Integer;
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
macro_rules! impl_float {
($t: ident) => {
impl EqAbs<$t> for GaussianInteger {
fn eq_abs(&self, other: &$t) -> bool {
if self.imaginary == 0u32 {
self.real.eq_abs(other)
} else if self.real == 0u32 {
self.imaginary.eq_abs(other)
} else if !self.real.lt_abs(other) || !self.imaginary.lt_abs(other) {
false
} else if let Ok(y) = Integer::try_from(*other) {
self.abs_squared() == y.abs_squared()
} else {
false
}
}
}
impl EqAbs<GaussianInteger> for $t {
#[inline]
fn eq_abs(&self, other: &GaussianInteger) -> bool {
other.eq_abs(self)
}
}
};
}
apply_to_primitive_floats!(impl_float);