Skip to main content

malachite_nz/gaussian_integer/comparison/
partial_eq_primitive_int.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_unsigned {
12    ($t: ident) => {
13        impl PartialEq<$t> for GaussianInteger {
14            /// Determines whether a [`GaussianInteger`] is equal to an unsigned primitive integer.
15            ///
16            /// # Worst-case complexity
17            /// Constant time and additional memory.
18            ///
19            /// # Examples
20            /// See [here](super::partial_eq_primitive_int#partial_eq).
21            #[inline]
22            fn eq(&self, other: &$t) -> bool {
23                self.imaginary == 0u32 && self.real == *other
24            }
25        }
26
27        impl PartialEq<GaussianInteger> for $t {
28            /// Determines whether an unsigned primitive integer is equal to a [`GaussianInteger`].
29            ///
30            /// # Worst-case complexity
31            /// Constant time and additional memory.
32            ///
33            /// # Examples
34            /// See [here](super::partial_eq_primitive_int#partial_eq).
35            #[inline]
36            fn eq(&self, other: &GaussianInteger) -> bool {
37                other == self
38            }
39        }
40    };
41}
42apply_to_unsigneds!(impl_unsigned);
43
44macro_rules! impl_signed {
45    ($t: ident) => {
46        impl PartialEq<$t> for GaussianInteger {
47            /// Determines whether a [`GaussianInteger`] is equal to a signed primitive integer.
48            ///
49            /// # Worst-case complexity
50            /// Constant time and additional memory.
51            ///
52            /// # Examples
53            /// See [here](super::partial_eq_primitive_int#partial_eq).
54            #[inline]
55            fn eq(&self, other: &$t) -> bool {
56                self.imaginary == 0u32 && self.real == *other
57            }
58        }
59
60        impl PartialEq<GaussianInteger> for $t {
61            /// Determines whether a signed primitive integer is equal to a [`GaussianInteger`].
62            ///
63            /// # Worst-case complexity
64            /// Constant time and additional memory.
65            ///
66            /// # Examples
67            /// See [here](super::partial_eq_primitive_int#partial_eq).
68            #[inline]
69            fn eq(&self, other: &GaussianInteger) -> bool {
70                other == self
71            }
72        }
73    };
74}
75apply_to_signeds!(impl_signed);