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