1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::integer::Integer;
use crate::natural::Natural;
use malachite_base::num::comparison::traits::PartialOrdAbs;
use std::cmp::Ordering;

impl PartialOrdAbs<Natural> for Integer {
    /// Compares the absolute values of an [`Integer`] and a [`Natural`].
    ///
    /// # Worst-case complexity
    /// $T(n) = O(n)$
    ///
    /// $M(n) = O(1)$
    ///
    /// where $T$ is time, $M$ is additional memory, and $n$ is
    /// `min(self.significant_bits(), other.significant_bits())`.
    ///
    /// # Examples
    /// ```
    /// extern crate malachite_base;
    ///
    /// use malachite_base::num::comparison::traits::PartialOrdAbs;
    /// use malachite_nz::integer::Integer;
    /// use malachite_nz::natural::Natural;
    ///
    /// assert!(Integer::from(123).gt_abs(&Natural::from(122u32)));
    /// assert!(Integer::from(123).ge_abs(&Natural::from(122u32)));
    /// assert!(Integer::from(123).lt_abs(&Natural::from(124u32)));
    /// assert!(Integer::from(123).le_abs(&Natural::from(124u32)));
    /// assert!(Integer::from(-124).gt_abs(&Natural::from(123u32)));
    /// assert!(Integer::from(-124).ge_abs(&Natural::from(123u32)));
    /// ```
    fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering> {
        self.abs.partial_cmp(other)
    }
}

impl PartialOrdAbs<Integer> for Natural {
    /// Compares the absolute values of a [`Natural`] and an [`Integer`].
    ///
    /// # Worst-case complexity
    /// $T(n) = O(n)$
    ///
    /// $M(n) = O(1)$
    ///
    /// where $T$ is time, $M$ is additional memory, and $n$ is
    /// `min(self.significant_bits(), other.significant_bits())`.
    ///
    /// # Examples
    /// ```
    /// extern crate malachite_base;
    ///
    /// use malachite_base::num::comparison::traits::PartialOrdAbs;
    /// use malachite_nz::integer::Integer;
    /// use malachite_nz::natural::Natural;
    ///
    /// assert!(Natural::from(123u32).gt_abs(&Integer::from(122)));
    /// assert!(Natural::from(123u32).ge_abs(&Integer::from(122)));
    /// assert!(Natural::from(123u32).lt_abs(&Integer::from(124)));
    /// assert!(Natural::from(123u32).le_abs(&Integer::from(124)));
    /// assert!(Natural::from(123u32).lt_abs(&Integer::from(-124)));
    /// assert!(Natural::from(123u32).le_abs(&Integer::from(-124)));
    /// ```
    fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering> {
        self.partial_cmp(&other.abs)
    }
}