malachite_nz/integer/comparison/
eq_abs_primitive_float.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_eq_abs {
13    ($t: ident) => {
14        impl EqAbs<$t> for Integer {
15            /// Determines whether the absolute values of an [`Integer`] and a primitive float are
16            /// equal.
17            ///
18            /// # Worst-case complexity
19            /// Constant time and additional memory.
20            ///
21            /// See [here](super::eq_abs_primitive_float#eq_abs).
22            #[inline]
23            fn eq_abs(&self, other: &$t) -> bool {
24                *self.unsigned_abs_ref() == other.abs()
25            }
26        }
27
28        impl EqAbs<Integer> for $t {
29            /// Determines whether the absolute values of a primitive float and an [`Integer`] are
30            /// equal.
31            ///
32            /// # Worst-case complexity
33            /// Constant time and additional memory.
34            ///
35            /// See [here](super::eq_abs_primitive_float#eq_abs).
36            #[inline]
37            fn eq_abs(&self, other: &Integer) -> bool {
38                self.abs() == *other.unsigned_abs_ref()
39            }
40        }
41    };
42}
43apply_to_primitive_floats!(impl_eq_abs);