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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright © 2026 Mikhail Hogrefe
//
// This file is part of Malachite.
//
// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
/// Implementations of [`Ord`] and [`PartialOrd`] for
/// [`ComparableGaussianInteger`](crate::gaussian_integer::ComparableGaussianInteger) and
/// [`ComparableGaussianIntegerRef`](crate::gaussian_integer::ComparableGaussianIntegerRef),
/// ordering [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)s lexicographically: first
/// by real part, then by imaginary part.
/// Implementations of [`OrdAbs`](malachite_base::num::comparison::traits::OrdAbs) and
/// [`PartialOrdAbs`](malachite_base::num::comparison::traits::PartialOrdAbs) for
/// [`GaussianInteger`](crate::gaussian_integer::GaussianInteger), comparing absolute values
/// (distances from the origin).
/// Implementations of [`PartialOrdAbs`](malachite_base::num::comparison::traits::PartialOrdAbs) for
/// comparing the absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)
/// and an [`Integer`](crate::integer::Integer).
/// Implementations of [`PartialOrdAbs`](malachite_base::num::comparison::traits::PartialOrdAbs) for
/// comparing the absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)
/// and a [`Natural`](crate::natural::Natural).
/// Implementations of [`PartialOrdAbs`](malachite_base::num::comparison::traits::PartialOrdAbs) for
/// comparing the absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)
/// and a primitive float.
///
/// # partial_cmp_abs
/// ```
/// use malachite_base::num::basic::traits::NegativeInfinity;
/// use malachite_base::num::comparison::traits::PartialOrdAbs;
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// // |3+4i| = 5
/// let x = GaussianInteger::from_str("3+4i").unwrap();
/// assert!(x.gt_abs(&-4.5f32));
/// assert!(x.lt_abs(&5.5f32));
/// assert!(x.lt_abs(&f32::NEGATIVE_INFINITY));
/// assert_eq!(x.partial_cmp_abs(&f32::NAN), None);
///
/// assert!((-4.5f32).lt_abs(&x));
/// assert!(5.5f32.gt_abs(&x));
/// assert!(f32::NEGATIVE_INFINITY.gt_abs(&x));
/// ```
/// Implementations of [`PartialOrdAbs`](malachite_base::num::comparison::traits::PartialOrdAbs) for
/// comparing the absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)
/// and a primitive integer.
///
/// # partial_cmp_abs
/// ```
/// use malachite_base::num::comparison::traits::PartialOrdAbs;
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// // |3+4i| = 5
/// let x = GaussianInteger::from_str("3+4i").unwrap();
/// assert!(x.gt_abs(&4u32));
/// assert!(x.ge_abs(&5u32));
/// assert!(x.le_abs(&5u32));
/// assert!(x.lt_abs(&6u32));
/// assert!(x.gt_abs(&-4i32));
/// assert!(x.lt_abs(&-6i32));
///
/// assert!(4u32.lt_abs(&x));
/// assert!(6u32.gt_abs(&x));
/// assert!((-4i32).lt_abs(&x));
/// assert!((-6i32).gt_abs(&x));
/// ```
/// An implementation of [`EqAbs`](malachite_base::num::comparison::traits::EqAbs) for
/// [`GaussianInteger`](crate::gaussian_integer::GaussianInteger), comparing absolute values
/// (distances from the origin) for equality.
/// Implementations of [`EqAbs`](malachite_base::num::comparison::traits::EqAbs) for comparing the
/// absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger) and an
/// [`Integer`](crate::integer::Integer) for equality.
/// Implementations of [`EqAbs`](malachite_base::num::comparison::traits::EqAbs) for comparing the
/// absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger) and a
/// [`Natural`](crate::natural::Natural) for equality.
/// Implementations of [`EqAbs`](malachite_base::num::comparison::traits::EqAbs) for comparing the
/// absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger) and a
/// primitive float for equality.
///
/// # eq_abs
/// ```
/// use malachite_base::num::comparison::traits::EqAbs;
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// // |3+4i| = 5
/// let x = GaussianInteger::from_str("3+4i").unwrap();
/// assert!(x.eq_abs(&-5.0f32));
/// assert_eq!(x.eq_abs(&4.0f32), false);
/// assert_eq!(x.eq_abs(&f32::NAN), false);
///
/// assert!((-5.0f32).eq_abs(&x));
/// assert_eq!(4.0f32.eq_abs(&x), false);
/// ```
/// Implementations of [`EqAbs`](malachite_base::num::comparison::traits::EqAbs) for comparing the
/// absolute values of a [`GaussianInteger`](crate::gaussian_integer::GaussianInteger) and a
/// primitive integer for equality.
///
/// # eq_abs
/// ```
/// use malachite_base::num::comparison::traits::EqAbs;
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// // |3+4i| = 5
/// let x = GaussianInteger::from_str("3+4i").unwrap();
/// assert!(x.eq_abs(&5u32));
/// assert_eq!(x.eq_abs(&4u32), false);
/// assert!(x.eq_abs(&-5i32));
///
/// assert!(5u32.eq_abs(&x));
/// assert!((-5i32).eq_abs(&x));
/// assert_eq!(4u32.eq_abs(&x), false);
/// ```
/// Equality of [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)s and
/// [`Integer`](crate::integer::Integer)s.
/// Equality of [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)s and
/// [`Natural`](crate::natural::Natural)s.
/// Equality of [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)s and primitive floats.
///
/// # partial_eq
/// ```
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// assert!(GaussianInteger::from(123) == 123.0f32);
/// assert!(GaussianInteger::from(123) != -5.0f32);
/// assert!(GaussianInteger::from_str("123+i").unwrap() != 123.0f32);
///
/// assert!(123.0f32 == GaussianInteger::from(123));
/// assert!(-5.0f32 != GaussianInteger::from(123));
/// ```
/// Equality of [`GaussianInteger`](crate::gaussian_integer::GaussianInteger)s and primitive
/// integers.
///
/// # partial_eq
/// ```
/// use malachite_nz::gaussian_integer::GaussianInteger;
/// use std::str::FromStr;
///
/// assert!(GaussianInteger::from(123) == 123u64);
/// assert!(GaussianInteger::from(-123) != 123u64);
/// assert!(GaussianInteger::from_str("123+i").unwrap() != 123u64);
///
/// assert!(123u64 == GaussianInteger::from(123));
/// assert!(123u64 != GaussianInteger::from(-123));
///
/// assert!(-123i64 == GaussianInteger::from(-123));
/// assert!(23i64 != GaussianInteger::from(123));
/// ```