malachite_nz/integer/comparison/partial_cmp_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 core::cmp::Ordering;
11use malachite_base::num::arithmetic::traits::UnsignedAbs;
12use malachite_base::num::comparison::traits::PartialOrdAbs;
13
14macro_rules! impl_float {
15 ($t: ident) => {
16 impl PartialOrdAbs<$t> for Integer {
17 /// Compares the absolute values of an [`Integer`] and a primitive float.
18 ///
19 /// # Worst-case complexity
20 /// $T(n) = O(n)$
21 ///
22 /// $M(n) = O(1)$
23 ///
24 /// where $T$ is time, $M$ is additional memory, and $n$ is `self.significant_bits()`.
25 ///
26 /// # Examples
27 /// See [here](super::partial_cmp_abs_primitive_float#partial_cmp_abs).
28 fn partial_cmp_abs(&self, other: &$t) -> Option<Ordering> {
29 self.unsigned_abs().partial_cmp(&other.abs())
30 }
31 }
32
33 impl PartialOrdAbs<Integer> for $t {
34 /// Compares the absolute values of a primitive float and an [`Integer`].
35 ///
36 /// # Worst-case complexity
37 /// $T(n) = O(n)$
38 ///
39 /// $M(n) = O(1)$
40 ///
41 /// where $T$ is time, $M$ is additional memory, and $n$ is `other.significant_bits()`.
42 ///
43 /// See [here](super::partial_cmp_abs_primitive_float#partial_cmp_abs).
44 #[inline]
45 fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering> {
46 other.partial_cmp_abs(self).map(Ordering::reverse)
47 }
48 }
49 };
50}
51apply_to_primitive_floats!(impl_float);