malachite_nz/natural/comparison/eq_abs_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::natural::Natural;
10use malachite_base::num::comparison::traits::EqAbs;
11
12macro_rules! impl_unsigned {
13 ($t: ident) => {
14 impl EqAbs<$t> for Natural {
15 /// Determines whether the absolute values of a [`Natural`] and a primitive unsigned
16 /// integer are equal.
17 ///
18 /// Since both values are non-negative, this is the same as ordinary equality.
19 ///
20 /// # Worst-case complexity
21 /// Constant time and additional memory.
22 ///
23 /// See [here](super::eq_abs_primitive_int#eq_abs).
24 #[inline]
25 fn eq_abs(&self, other: &$t) -> bool {
26 self == other
27 }
28 }
29
30 impl EqAbs<Natural> for $t {
31 /// Determines whether the absolute values of a primitive unsigned integer and a
32 /// [`Natural`] are equal.
33 ///
34 /// Since both values are non-negative, this is the same as ordinary equality.
35 ///
36 /// # Worst-case complexity
37 /// Constant time and additional memory.
38 ///
39 /// See [here](super::eq_abs_primitive_int#eq_abs).
40 #[inline]
41 fn eq_abs(&self, other: &Natural) -> bool {
42 self == other
43 }
44 }
45 };
46}
47apply_to_unsigneds!(impl_unsigned);
48
49macro_rules! impl_signed {
50 ($t: ident) => {
51 impl EqAbs<$t> for Natural {
52 /// Determines whether the absolute values of a [`Natural`] and a primitive signed
53 /// integer are equal.
54 ///
55 /// # Worst-case complexity
56 /// Constant time and additional memory.
57 ///
58 /// See [here](super::eq_abs_primitive_int#eq_abs).
59 #[inline]
60 fn eq_abs(&self, other: &$t) -> bool {
61 *self == other.unsigned_abs()
62 }
63 }
64
65 impl EqAbs<Natural> for $t {
66 /// Determines whether the absolute values of a primitive signed integer and a
67 /// [`Natural`] are equal.
68 ///
69 /// # Worst-case complexity
70 /// Constant time and additional memory.
71 ///
72 /// See [here](super::eq_abs_primitive_int#eq_abs).
73 #[inline]
74 fn eq_abs(&self, other: &Natural) -> bool {
75 self.unsigned_abs() == *other
76 }
77 }
78 };
79}
80apply_to_signeds!(impl_signed);