malachite_float/float/comparison/partial_eq_gaussian_integer.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::Float;
10use malachite_nz::gaussian_integer::GaussianInteger;
11
12impl PartialEq<GaussianInteger> for Float {
13 /// Determines whether a [`Float`] is equal to a [`GaussianInteger`].
14 ///
15 /// $\infty$, $-\infty$, and NaN are not equal to any [`GaussianInteger`]. Both the [`Float`]
16 /// zero and the [`Float`] negative zero are equal to the [`GaussianInteger`] zero.
17 ///
18 /// # Worst-case complexity
19 /// $T(n) = O(n)$
20 ///
21 /// $M(n) = O(1)$
22 ///
23 /// where $T$ is time, $M$ is additional memory, and $n$ is `min(self.significant_bits(),
24 /// other.real.significant_bits())`.
25 ///
26 /// # Examples
27 /// ```
28 /// use malachite_float::Float;
29 /// use malachite_nz::gaussian_integer::GaussianInteger;
30 /// use std::str::FromStr;
31 ///
32 /// assert!(Float::from(123) == GaussianInteger::from(123));
33 /// assert!(Float::from(-123) == GaussianInteger::from(-123));
34 /// assert!(Float::from(123) != GaussianInteger::from_str("123+i").unwrap());
35 /// ```
36 fn eq(&self, other: &GaussianInteger) -> bool {
37 other.imaginary == 0u32 && *self == other.real
38 }
39}
40
41impl PartialEq<Float> for GaussianInteger {
42 /// Determines whether a [`GaussianInteger`] is equal to a [`Float`].
43 ///
44 /// No [`GaussianInteger`] is equal to $\infty$, $-\infty$, or NaN. The [`GaussianInteger`] zero
45 /// is equal to both the [`Float`] zero and the [`Float`] negative zero.
46 ///
47 /// # Worst-case complexity
48 /// $T(n) = O(n)$
49 ///
50 /// $M(n) = O(1)$
51 ///
52 /// where $T$ is time, $M$ is additional memory, and $n$ is `min(self.real.significant_bits(),
53 /// other.significant_bits())`.
54 ///
55 /// # Examples
56 /// ```
57 /// use malachite_float::Float;
58 /// use malachite_nz::gaussian_integer::GaussianInteger;
59 /// use std::str::FromStr;
60 ///
61 /// assert!(GaussianInteger::from(123) == Float::from(123));
62 /// assert!(GaussianInteger::from(-123) == Float::from(-123));
63 /// assert!(GaussianInteger::from_str("123+i").unwrap() != Float::from(123));
64 /// ```
65 fn eq(&self, other: &Float) -> bool {
66 self.imaginary == 0u32 && self.real == *other
67 }
68}