malachite_nz/integer/comparison/partial_eq_natural.rs
1// Copyright © 2025 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::integer::Integer;
10use crate::natural::Natural;
11
12impl PartialEq<Natural> for Integer {
13 /// Determines whether an [`Integer`] is equal to a [`Natural`].
14 ///
15 /// # Worst-case complexity
16 /// $T(n) = O(n)$
17 ///
18 /// $M(n) = O(1)$
19 ///
20 /// where n = `min(self.significant_bits(), other.significant_bits())`
21 ///
22 /// # Examples
23 /// ```
24 /// use malachite_nz::integer::Integer;
25 /// use malachite_nz::natural::Natural;
26 ///
27 /// assert!(Integer::from(123) == Natural::from(123u32));
28 /// assert!(Integer::from(123) != Natural::from(5u32));
29 /// ```
30 fn eq(&self, other: &Natural) -> bool {
31 self.sign && self.abs == *other
32 }
33}
34
35impl PartialEq<Integer> for Natural {
36 /// Determines whether a [`Natural`] is equal to an [`Integer`].
37 ///
38 /// # Worst-case complexity
39 /// $T(n) = O(n)$
40 ///
41 /// $M(n) = O(1)$
42 ///
43 /// where n = `min(self.significant_bits(), other.significant_bits())`
44 ///
45 /// # Examples
46 /// ```
47 /// use malachite_nz::integer::Integer;
48 /// use malachite_nz::natural::Natural;
49 ///
50 /// assert!(Natural::from(123u32) == Integer::from(123));
51 /// assert!(Natural::from(123u32) != Integer::from(5));
52 /// ```
53 fn eq(&self, other: &Integer) -> bool {
54 other.sign && *self == other.abs
55 }
56}