Skip to main content

malachite_nz/gaussian_integer/comparison/
partial_eq_primitive_float.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::gaussian_integer::GaussianInteger;
10
11macro_rules! impl_float {
12    ($t: ident) => {
13        impl PartialEq<$t> for GaussianInteger {
14            /// Determines whether a [`GaussianInteger`] is equal to a primitive float.
15            ///
16            /// No [`GaussianInteger`] is equal to an infinity or NaN.
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
24            /// `self.real.significant_bits()`.
25            ///
26            /// # Examples
27            /// See [here](super::partial_eq_primitive_float#partial_eq).
28            #[inline]
29            fn eq(&self, other: &$t) -> bool {
30                self.imaginary == 0u32 && self.real == *other
31            }
32        }
33
34        impl PartialEq<GaussianInteger> for $t {
35            /// Determines whether a primitive float is equal to a [`GaussianInteger`].
36            ///
37            /// No infinity or NaN is equal to a [`GaussianInteger`].
38            ///
39            /// # Worst-case complexity
40            /// $T(n) = O(n)$
41            ///
42            /// $M(n) = O(1)$
43            ///
44            /// where $T$ is time, $M$ is additional memory, and $n$ is
45            /// `other.real.significant_bits()`.
46            ///
47            /// # Examples
48            /// See [here](super::partial_eq_primitive_float#partial_eq).
49            #[inline]
50            fn eq(&self, other: &GaussianInteger) -> bool {
51                other == self
52            }
53        }
54    };
55}
56apply_to_primitive_floats!(impl_float);