malachite_nz/integer/comparison/
eq_abs.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
12impl EqAbs for Integer {
13    /// Determines whether the absolute values of two [`Integer`]s are equal.
14    ///
15    /// # Worst-case complexity
16    /// $T(n) = O(n)$
17    ///
18    /// $M(n) = O(1)$
19    ///
20    /// where $T$ is time, $M$ is additional memory, and $n$ is `min(self.significant_bits(),
21    /// other.significant_bits())`.
22    ///
23    /// # Examples
24    /// ```
25    /// use malachite_base::num::comparison::traits::EqAbs;
26    /// use malachite_nz::integer::Integer;
27    ///
28    /// assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-122)), false);
29    /// assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-124)), false);
30    /// assert_eq!(Integer::from(123).eq_abs(&Integer::from(123)), true);
31    /// assert_eq!(Integer::from(123).eq_abs(&Integer::from(-123)), true);
32    /// assert_eq!(Integer::from(-123).eq_abs(&Integer::from(123)), true);
33    /// assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-123)), true);
34    /// ```
35    #[inline]
36    fn eq_abs(&self, other: &Self) -> bool {
37        self.abs == other.abs
38    }
39}