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
// 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 [`AbsSquared`](malachite_base::num::arithmetic::traits::AbsSquared) and
/// [`AbsSquaredAssign`](malachite_base::num::arithmetic::traits::AbsSquaredAssign), traits for
/// computing the squared absolute value (norm) of a number.
/// Addition of [`GaussianRational`](crate::gaussian_rational::GaussianRational)s.
/// Implementations of [`CanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::CanonicalPrimitivePart) and
/// [`ContentAndCanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart), which compute the
/// primitive part of a Gaussian rational in canonical unit form.
/// An implementation of
/// [`CanonicalUnitIPow`](malachite_base::num::arithmetic::traits::CanonicalUnitIPow), a trait for
/// finding the power of $i$ that brings a number into canonical unit form.
/// Implementations of
/// [`CanonicalizeGaussianUnit`](malachite_base::num::arithmetic::traits::CanonicalizeGaussianUnit)
/// and [`CanonicalizeGaussianUnitAssign`](
/// malachite_base::num::arithmetic::traits::CanonicalizeGaussianUnitAssign), traits for bringing a
/// number into canonical Gaussian-unit form.
/// Implementations of
/// [`CanonicalizeUnit`](malachite_base::num::arithmetic::traits::CanonicalizeUnit) and
/// [`CanonicalizeUnitAssign`](malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign),
/// traits for bringing a number into canonical unit form.
/// Implementations of [`Conjugate`](malachite_base::num::arithmetic::traits::Conjugate) and
/// [`ConjugateAssign`](malachite_base::num::arithmetic::traits::ConjugateAssign), traits for
/// computing the complex conjugate of a number: the sign of the imaginary part is flipped.
/// Implementations of
/// [`ContentAndPrimitivePart`](malachite_base::num::arithmetic::traits::ContentAndPrimitivePart),
/// [`Content`](malachite_base::num::arithmetic::traits::Content), and
/// [`PrimitivePart`](malachite_base::num::arithmetic::traits::PrimitivePart), traits for splitting
/// a number into a rational scalar and a Gaussian integer with coprime parts.
/// Division of [`GaussianRational`](crate::gaussian_rational::GaussianRational)s, including
/// [`CheckedDiv`](malachite_base::num::arithmetic::traits::CheckedDiv).
/// Implementations of [`DivI`](malachite_base::num::arithmetic::traits::DivI) and
/// [`DivIAssign`](malachite_base::num::arithmetic::traits::DivIAssign), traits for dividing a
/// number by $i$: a clockwise quarter turn.
/// An implementation of [`IsUnit`](malachite_base::num::arithmetic::traits::IsUnit), a trait for
/// determining whether a number is a unit of its ring. Implementations of
/// [`Height`](malachite_base::num::arithmetic::traits::Height) and
/// [`HeightRef`](malachite_base::num::arithmetic::traits::HeightRef), the largest of the magnitudes
/// a [`GaussianRational`](super::GaussianRational) is built from.
/// An implementation of [`IsPowerOf2`](malachite_base::num::arithmetic::traits::IsPowerOf2), a
/// trait for determining whether a number is an integer power of 2.
/// Multiplication of [`GaussianRational`](crate::gaussian_rational::GaussianRational)s.
/// Implementations of [`MulI`](malachite_base::num::arithmetic::traits::MulI) and
/// [`MulIAssign`](malachite_base::num::arithmetic::traits::MulIAssign), traits for multiplying a
/// number by $i$: a counterclockwise quarter turn.
/// Implementations of [`MulIPow`](malachite_base::num::arithmetic::traits::MulIPow) and
/// [`MulIPowAssign`](malachite_base::num::arithmetic::traits::MulIPowAssign), traits for
/// multiplying a number by a power of $i$: a multiple of a quarter turn.
/// Implementations of [`Neg`](core::ops::Neg) and
/// [`NegAssign`](malachite_base::num::arithmetic::traits::NegAssign) for
/// [`GaussianRational`](crate::gaussian_rational::GaussianRational), negating both the real and
/// imaginary parts.
/// Implementations of [`Pow`](malachite_base::num::arithmetic::traits::Pow) and
/// [`PowAssign`](malachite_base::num::arithmetic::traits::PowAssign), traits for raising a number
/// to a power.
/// Implementations of [`PowerOf2`](malachite_base::num::arithmetic::traits::PowerOf2), a trait for
/// computing a power of 2.
/// Implementations of [`Reciprocal`](malachite_base::num::arithmetic::traits::Reciprocal) and
/// [`ReciprocalAssign`](malachite_base::num::arithmetic::traits::ReciprocalAssign), traits for
/// computing the reciprocal of a number.
/// Implementations of [`CheckedRoot`](malachite_base::num::arithmetic::traits::CheckedRoot), a
/// trait for taking the $n$th root of a number when it is a perfect $n$th power.
/// Left-shifting a [`GaussianRational`](crate::gaussian_rational::GaussianRational) (multiplying it
/// by a power of 2). A negative shift amount divides by a power of 2 instead.
///
/// # shl
/// ```
/// use malachite_q::gaussian_rational::GaussianRational;
/// use std::str::FromStr;
///
/// let x = GaussianRational::from_str("7/22-i").unwrap();
/// assert_eq!((x.clone() << 2u8).to_string(), "14/11-4i");
/// assert_eq!((&x << 2u64).to_string(), "14/11-4i");
/// assert_eq!((&x << 2i8).to_string(), "14/11-4i");
/// assert_eq!((&x << -2i64).to_string(), "7/88-i/4");
/// assert_eq!((x << -1i32).to_string(), "7/44-i/2");
/// ```
///
/// # shl_assign
/// ```
/// use malachite_q::gaussian_rational::GaussianRational;
/// use std::str::FromStr;
///
/// let mut x = GaussianRational::from_str("1+i").unwrap();
/// x <<= 1u8;
/// x <<= 2u16;
/// assert_eq!(x.to_string(), "8+8i");
/// x <<= -4i8;
/// x <<= -1i64;
/// assert_eq!(x.to_string(), "1/4+i/4");
/// ```
/// Right-shifting a [`GaussianRational`](crate::gaussian_rational::GaussianRational) (dividing it
/// by a power of 2). A negative shift amount multiplies by a power of 2 instead.
///
/// # shr
/// ```
/// use malachite_q::gaussian_rational::GaussianRational;
/// use std::str::FromStr;
///
/// let x = GaussianRational::from_str("14/11-4i").unwrap();
/// assert_eq!((x.clone() >> 2u8).to_string(), "7/22-i");
/// assert_eq!((&x >> 2u64).to_string(), "7/22-i");
/// assert_eq!((&x >> 2i8).to_string(), "7/22-i");
/// assert_eq!((&x >> -2i64).to_string(), "56/11-16i");
/// assert_eq!((x >> -1i32).to_string(), "28/11-8i");
/// ```
///
/// # shr_assign
/// ```
/// use malachite_q::gaussian_rational::GaussianRational;
/// use std::str::FromStr;
///
/// let mut x = GaussianRational::from_str("8+8i").unwrap();
/// x >>= 1u8;
/// x >>= 2u16;
/// assert_eq!(x.to_string(), "1+i");
/// x >>= -4i8;
/// x >>= -1i64;
/// assert_eq!(x.to_string(), "32+32i");
/// ```
/// Implementations of [`Square`](malachite_base::num::arithmetic::traits::Square) and
/// [`SquareAssign`](malachite_base::num::arithmetic::traits::SquareAssign), traits for squaring a
/// number. Implementations of
/// [`CheckedSqrt`](malachite_base::num::arithmetic::traits::CheckedSqrt), a trait for taking the
/// square root of a number when it is a perfect square.
/// Subtraction of [`GaussianRational`](crate::gaussian_rational::GaussianRational)s.