Skip to main content

malachite_nz/natural/arithmetic/
mod.rs

1// Copyright © 2026 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
9/// Implementations of [`AbsDiff`](malachite_base::num::arithmetic::traits::AbsDiff) and
10/// [`AbsDiffAssign`](malachite_base::num::arithmetic::traits::AbsDiffAssign), traits for getting
11/// the absolute value of the difference between two numbers.
12pub mod abs_diff;
13/// Addition of [`Natural`](super::Natural)s.
14pub mod add;
15/// Implementations of [`AddMul`](malachite_base::num::arithmetic::traits::AddMul) and
16/// [`AddMulAssign`](malachite_base::num::arithmetic::traits::AddMulAssign), traits for adding a
17/// number and the product of two other numbers.
18pub mod add_mul;
19/// Implementations of
20/// [`BinomialCoefficient`](malachite_base::num::arithmetic::traits::BinomialCoefficient), a trait
21/// for computing the binomial coefficient of two numbers.
22pub mod binomial_coefficient;
23/// Implementations of [`CheckedSub`](malachite_base::num::arithmetic::traits::CheckedSub), a trait
24/// for subtracting two numbers and checking whether the result is representable.
25pub mod checked_sub;
26/// Implementations of [`CheckedSubMul`](malachite_base::num::arithmetic::traits::CheckedSubMul), a
27/// trait for subtracting the product of two numbers from another number, and checking whether the
28/// result is representable.
29pub mod checked_sub_mul;
30/// Implementations of [`CoprimeWith`](malachite_base::num::arithmetic::traits::CoprimeWith), a
31/// trait for determining whether two numbers are coprime.
32pub mod coprime_with;
33/// Division of [`Natural`](super::Natural)s.
34pub mod div;
35/// Implementations of [`DivExact`](malachite_base::num::arithmetic::traits::DivExact) and
36/// [`DivExactAssign`](malachite_base::num::arithmetic::traits::DivExactAssign), traits for dividing
37/// two numbers when it's known that the division is exact.
38pub mod div_exact;
39/// Implementations of raits for simultaneously finding the quotient and remainder of two numbers,
40/// subject to various rounding rules.
41///
42/// These are the traits:
43///
44/// | rounding     | by value or reference           | by mutable reference (assignment)      |
45/// |--------------|---------------------------------|----------------------------------------|
46/// | towards $-\infty$ | [`DivMod`](malachite_base::num::arithmetic::traits::DivMod) | [`DivAssignMod`](malachite_base::num::arithmetic::traits::DivAssignMod) |
47/// | towards 0         | [`DivRem`](malachite_base::num::arithmetic::traits::DivRem) | [`DivAssignRem`](malachite_base::num::arithmetic::traits::DivAssignRem) |
48/// | towards $\infty$  | [`CeilingDivNegMod`](malachite_base::num::arithmetic::traits::CeilingDivNegMod) | [`CeilingDivAssignNegMod`](malachite_base::num::arithmetic::traits::CeilingDivAssignNegMod) |
49///
50/// [`CeilingDivNegMod`](malachite_base::num::arithmetic::traits::CeilingDivNegMod) returns a
51/// remainder greater than or equal to zero. This allows the remainder to have an unsigned type, but
52/// modifies the usual relation $x = qy + r$ to $x = qy - r$.
53pub mod div_mod;
54/// Implementations of [`DivRound`](malachite_base::num::arithmetic::traits::DivRound) and
55/// [`DivExactAssign`](malachite_base::num::arithmetic::traits::DivRoundAssign), traits for dividing
56/// two numbers according to a specified
57/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
58pub mod div_round;
59/// Implementations of [`DivisibleBy`](malachite_base::num::arithmetic::traits::DivisibleBy), a
60/// trait for determining whether one number is divisible by another.
61pub mod divisible_by;
62/// Implementations of
63/// [`DivisibleByPowerOf2`](malachite_base::num::arithmetic::traits::DivisibleByPowerOf2), a trait
64/// for determining whether a number is divisible by $2^k$.
65pub mod divisible_by_power_of_2;
66/// Implementations of [`EqMod`](malachite_base::num::arithmetic::traits::EqMod), a trait for
67/// determining whether one number is equal by another modulo a third.
68pub mod eq_mod;
69/// Implementations of [`EqModPowerOf2`](malachite_base::num::arithmetic::traits::EqModPowerOf2), a
70/// trait for determining whether one number is equal to another modulo $2^k$.
71pub mod eq_mod_power_of_2;
72/// Implementations of [`Factorial`](malachite_base::num::arithmetic::traits::Factorial),
73/// [`DoubleFactorial`](malachite_base::num::arithmetic::traits::DoubleFactorial),
74/// [`Multifactorial`](malachite_base::num::arithmetic::traits::Multifactorial), and
75/// [`Subfactorial`](malachite_base::num::arithmetic::traits::Subfactorial).
76pub mod factorial;
77#[cfg(feature = "float_helpers")]
78pub mod float_add;
79#[cfg(feature = "float_helpers")]
80pub mod float_div;
81#[cfg(feature = "float_helpers")]
82pub mod float_extras;
83#[cfg(feature = "float_helpers")]
84pub mod float_mul;
85#[cfg(feature = "float_helpers")]
86pub mod float_reciprocal;
87#[cfg(feature = "float_helpers")]
88pub mod float_reciprocal_sqrt;
89#[cfg(feature = "float_helpers")]
90pub mod float_sqrt;
91#[cfg(feature = "float_helpers")]
92pub mod float_square;
93#[cfg(feature = "float_helpers")]
94pub mod float_sub;
95/// Implementations of [`Gcd`](malachite_base::num::arithmetic::traits::Gcd) and
96/// [`GcdAssign`](malachite_base::num::arithmetic::traits::GcdAssign), traits for computing the GCD
97/// (greatest common divisor) of two numbers.
98pub mod gcd;
99/// Implementations of [`IsPowerOf2`](malachite_base::num::arithmetic::traits::IsPowerOf2), a trait
100/// for determining whether a number is an integer power of 2.
101pub mod is_power_of_2;
102/// Implementations of [`LegendreSymbol`](malachite_base::num::arithmetic::traits::LegendreSymbol),
103/// [`JacobiSymbol`](malachite_base::num::arithmetic::traits::JacobiSymbol), and
104/// [`KroneckerSymbol`](malachite_base::num::arithmetic::traits::KroneckerSymbol), traits for
105/// computing the Legendre, Jacobi, and Kronecker symbols of two numbers.
106pub mod kronecker_symbol;
107/// Implementations of [`Lcm`](malachite_base::num::arithmetic::traits::Lcm),
108/// [`LcmAssign`](malachite_base::num::arithmetic::traits::LcmAssign), and
109/// [`CheckedLcm`](malachite_base::num::arithmetic::traits::CheckedLcm), traits for computing the
110/// LCM (least common multiple) of two numbers.
111pub mod lcm;
112/// Implementations of traits for taking the base-$b$ logarithm of a number.
113///
114/// The traits are [`FloorLogBase`](malachite_base::num::arithmetic::traits::FloorLogBase),
115/// [`CeilingLogBase`](malachite_base::num::arithmetic::traits::CeilingLogBase), and
116/// [`CheckedLogBase`](malachite_base::num::arithmetic::traits::CheckedLogBase).
117pub mod log_base;
118/// Implementations of traits for taking the base-2 logarithm of a number.
119///
120/// The traits are [`FloorLogBase2`](malachite_base::num::arithmetic::traits::FloorLogBase2),
121/// [`CeilingLogBase2`](malachite_base::num::arithmetic::traits::CeilingLogBase2), and
122/// [`CheckedLogBase2`](malachite_base::num::arithmetic::traits::CheckedLogBase2).
123pub mod log_base_2;
124/// Implementations of traits for taking the base-$2^k$ logarithm of a number.
125///
126/// The traits are
127/// [`FloorLogBasePowerOf2`](malachite_base::num::arithmetic::traits::FloorLogBasePowerOf2),
128/// [`CeilingLogBasePowerOf2`](malachite_base::num::arithmetic::traits::CeilingLogBasePowerOf2), and
129/// [`CheckedLogBasePowerOf2`](malachite_base::num::arithmetic::traits::CheckedLogBasePowerOf2).
130pub mod log_base_power_of_2;
131/// Implementations of [`ModAdd`](malachite_base::num::arithmetic::traits::ModAdd) and
132/// [`ModAddAssign`](malachite_base::num::arithmetic::traits::ModAddAssign), traits for adding two
133/// numbers modulo another number.
134pub mod mod_add;
135/// Implementations of [`ModInverse`](malachite_base::num::arithmetic::traits::ModInverse), a trait
136/// for finding the multiplicative inverse of a number modulo another number.
137pub mod mod_inverse;
138/// Implementations of [`ModIsReduced`](malachite_base::num::arithmetic::traits::ModIsReduced), a
139/// trait for checking whether a number is reduced modulo another number.
140pub mod mod_is_reduced;
141/// Implementations of traits for multiplying two numbers modulo another number.
142///
143/// The traits are [`ModMul`](malachite_base::num::arithmetic::traits::ModMul),
144/// [`ModMulAssign`](malachite_base::num::arithmetic::traits::ModMulAssign),
145/// [`ModMulPrecomputed`](malachite_base::num::arithmetic::traits::ModMulPrecomputed), and
146/// [`ModMulPrecomputedAssign`](malachite_base::num::arithmetic::traits::ModMulPrecomputedAssign).
147/// [`ModMulPrecomputed`](malachite_base::num::arithmetic::traits::ModMulPrecomputed) and
148/// [`ModMulPrecomputedAssign`](malachite_base::num::arithmetic::traits::ModMulPrecomputedAssign)
149/// are useful when having to make several multiplications modulo the same modulus.
150pub mod mod_mul;
151/// Implementations of [`ModNeg`](malachite_base::num::arithmetic::traits::ModNeg) and
152/// [`ModNegAssign`](malachite_base::num::arithmetic::traits::ModNegAssign), traits for negating a
153/// number modulo another number.
154pub mod mod_neg;
155/// Implementations of traits for finding the remainder of two numbers, subject to various rounding
156/// rules.
157///
158/// These are the traits:
159///
160/// | rounding          | by value or reference      | by mutable reference (assignment)      |
161/// |-------------------|----------------------------|----------------------------------------|
162/// | towards $-\infty$ | [`Mod`](malachite_base::num::arithmetic::traits::Mod)       | [`ModAssign`](malachite_base::num::arithmetic::traits::ModAssign)       |
163/// | towards $\infty$  | [`NegMod`](malachite_base::num::arithmetic::traits::NegMod) | [`NegModAssign`](malachite_base::num::arithmetic::traits::NegModAssign) |
164///
165/// [`NegMod`](malachite_base::num::arithmetic::traits::NegMod) returns a remainder greater than or
166/// equal to zero. This allows the remainder to have an unsigned type, but modifies the usual
167/// relation $x = qy + r$ to $x = qy - r$.
168///
169/// The [`Rem`](core::ops::Rem) trait in the standard library rounds towards 0.
170pub mod mod_op;
171/// Implementations of traits for raising a number to a power modulo another number.
172///
173/// The traits are [`ModPow`](malachite_base::num::arithmetic::traits::ModPow),
174/// [`ModPowAssign`](malachite_base::num::arithmetic::traits::ModPowAssign), and
175/// [`ModPowPrecomputed`](malachite_base::num::arithmetic::traits::ModPowPrecomputed).
176/// [`ModPowPrecomputed`](malachite_base::num::arithmetic::traits::ModPowPrecomputed) is useful when
177/// having to make several exponentiations modulo the same modulus.
178pub mod mod_pow;
179/// Implementations of traits for finding the remainder of a number divided by $2^k$, subject to
180/// various rounding rules.
181///
182/// These are the traits:
183///
184/// | rounding | by value or reference | by mutable reference (assignment) |
185/// |----------|-----------------------|-----------------------------------|
186/// | towards $-\infty$ | [`ModPowerOf2`](malachite_base::num::arithmetic::traits::ModPowerOf2) | [`ModPowerOf2Assign`](malachite_base::num::arithmetic::traits::ModPowerOf2Assign)       |
187/// | towards 0 | [`RemPowerOf2`](malachite_base::num::arithmetic::traits::RemPowerOf2) | [`RemPowerOf2Assign`](malachite_base::num::arithmetic::traits::RemPowerOf2Assign)       |
188/// | towards $\infty$  | [`NegModPowerOf2`](malachite_base::num::arithmetic::traits::NegModPowerOf2) | [`NegModPowerOf2Assign`](malachite_base::num::arithmetic::traits::NegModPowerOf2Assign) |
189///
190/// [`NegModPowerOf2`](malachite_base::num::arithmetic::traits::NegModPowerOf2) returns a remainder
191/// greater than or equal to zero. This allows the remainder to have an unsigned type, but modifies
192/// the usual relation $x = q2^k + r$ to $x = q2^k - r$.
193pub mod mod_power_of_2;
194/// Implementations of [`ModPowerOf2Add`](malachite_base::num::arithmetic::traits::ModPowerOf2Add)
195/// and [`ModPowerOf2AddAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign),
196/// traits for adding two numbers modulo $2^k$.
197pub mod mod_power_of_2_add;
198/// Implementations of
199/// [`ModPowerOf2Inverse`](malachite_base::num::arithmetic::traits::ModPowerOf2Inverse), a trait for
200/// finding the multiplicative inverse of a number modulo $2^k$.
201pub mod mod_power_of_2_inverse;
202/// Implementations of
203/// [`ModPowerOf2IsReduced`](malachite_base::num::arithmetic::traits::ModPowerOf2IsReduced), a trait
204/// for checking whether a number is reduced modulo $2^k$.
205pub mod mod_power_of_2_is_reduced;
206/// Implementations of [`ModPowerOf2Mul`](malachite_base::num::arithmetic::traits::ModPowerOf2Mul)
207/// and [`ModPowerOf2MulAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign),
208/// traits for multiplying two numbers modulo $2^k$.
209pub mod mod_power_of_2_mul;
210/// Implementations of [`ModPowerOf2Neg`](malachite_base::num::arithmetic::traits::ModPowerOf2Neg)
211/// and [`ModPowerOf2NegAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2NegAssign),
212/// traits for negating a number modulo $2^k$.
213pub mod mod_power_of_2_neg;
214/// Implementations of [`ModPowerOf2Pow`](malachite_base::num::arithmetic::traits::ModPowerOf2Pow)
215/// and [`ModPowerOf2PowAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2PowAssign),
216/// traits for raising a number to a power modulo $2^k$.
217pub mod mod_power_of_2_pow;
218/// Implementations of [`ModPowerOf2Shl`](malachite_base::num::arithmetic::traits::ModPowerOf2Shl)
219/// and [`ModPowerOf2ShlAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2ShlAssign),
220/// traits for left-shifting a number modulo $2^k$.
221///
222/// # mod_power_of_2_shl
223/// ```
224/// use malachite_base::num::arithmetic::traits::ModPowerOf2Shl;
225/// use malachite_nz::natural::Natural;
226///
227/// assert_eq!(Natural::from(123u32).mod_power_of_2_shl(5u16, 8), 96);
228/// assert_eq!(Natural::from(123u32).mod_power_of_2_shl(100u64, 80), 0);
229/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shl(5u16, 8), 96);
230/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shl(100u64, 80), 0);
231///
232/// assert_eq!(Natural::from(123u32).mod_power_of_2_shl(5i16, 8), 96);
233/// assert_eq!(Natural::from(123u32).mod_power_of_2_shl(100i64, 80), 0);
234/// assert_eq!(Natural::from(123u32).mod_power_of_2_shl(-2i8, 8), 30);
235/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shl(5i16, 8), 96);
236/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shl(100i64, 80), 0);
237/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shl(-2i8, 8), 30);
238/// ```
239///
240/// # mod_power_of_2_shl_assign
241/// ```
242/// use malachite_base::num::arithmetic::traits::ModPowerOf2ShlAssign;
243/// use malachite_nz::natural::Natural;
244///
245/// let mut n = Natural::from(123u32);
246/// n.mod_power_of_2_shl_assign(5u16, 8);
247/// assert_eq!(n, 96);
248///
249/// let mut n = Natural::from(123u32);
250/// n.mod_power_of_2_shl_assign(100u64, 80);
251/// assert_eq!(n, 0);
252///
253/// let mut n = Natural::from(123u32);
254/// n.mod_power_of_2_shl_assign(5i16, 8);
255/// assert_eq!(n, 96);
256///
257/// let mut n = Natural::from(123u32);
258/// n.mod_power_of_2_shl_assign(100i64, 80);
259/// assert_eq!(n, 0);
260///
261/// let mut n = Natural::from(123u32);
262/// n.mod_power_of_2_shl_assign(-2i8, 8);
263/// assert_eq!(n, 30);
264/// ```
265pub mod mod_power_of_2_shl;
266/// Implementations of [`ModPowerOf2Shr`](malachite_base::num::arithmetic::traits::ModPowerOf2Shr)
267/// and [`ModPowerOf2ShrAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2ShrAssign),
268/// traits for right-shifting a number modulo $2^k$.
269///
270/// # mod_power_of_2_shr
271/// ```
272/// use malachite_base::num::arithmetic::traits::ModPowerOf2Shr;
273/// use malachite_nz::natural::Natural;
274///
275/// assert_eq!(Natural::from(123u32).mod_power_of_2_shr(-5i16, 8), 96);
276/// assert_eq!(Natural::from(123u32).mod_power_of_2_shr(-100i64, 80), 0);
277/// assert_eq!(Natural::from(123u32).mod_power_of_2_shr(2i8, 8), 30);
278/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shr(-5i16, 8), 96);
279/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shr(-100i64, 80), 0);
280/// assert_eq!((&Natural::from(123u32)).mod_power_of_2_shr(2i8, 8), 30);
281/// ```
282///
283/// # mod_power_of_2_shr_assign
284/// ```
285/// use malachite_base::num::arithmetic::traits::ModPowerOf2ShrAssign;
286/// use malachite_nz::natural::Natural;
287///
288/// let mut n = Natural::from(123u32);
289/// n.mod_power_of_2_shr_assign(-5i16, 8);
290/// assert_eq!(n, 96);
291///
292/// let mut n = Natural::from(123u32);
293/// n.mod_power_of_2_shr_assign(-100i64, 80);
294/// assert_eq!(n, 0);
295///
296/// let mut n = Natural::from(123u32);
297/// n.mod_power_of_2_shr_assign(2i8, 8);
298/// assert_eq!(n, 30);
299/// ```
300pub mod mod_power_of_2_shr;
301/// Implementations of
302/// `ModPowerOf2Square`](malachite_base::num::arithmetic::traits::ModPowerOf2Square) and
303/// [`ModPowerOf2SquareAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2SquareAssign),
304/// traits for squaring a number modulo $2^k$.
305pub mod mod_power_of_2_square;
306/// Implementations of [`ModPowerOf2Sub`](malachite_base::num::arithmetic::traits::ModPowerOf2Sub)
307/// and [`ModPowerOf2SubAssign`](malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign),
308/// traits for subtracting one number by another modulo $2^k$.
309pub mod mod_power_of_2_sub;
310/// Implementations of [`ModShl`](malachite_base::num::arithmetic::traits::ModShl) and
311/// [`ModShlAssign`](malachite_base::num::arithmetic::traits::ModShlAssign), traits for
312/// left-shifting a number modulo another number.
313///
314/// # mod_shl
315/// ```
316/// use core::str::FromStr;
317/// use malachite_base::num::arithmetic::traits::ModShl;
318/// use malachite_nz::natural::Natural;
319///
320/// assert_eq!(Natural::from(8u32).mod_shl(2u16, Natural::from(10u32)), 2);
321/// assert_eq!(
322///     Natural::from(123456u32).mod_shl(100u64, Natural::from_str("12345678987654321").unwrap()),
323///     7436663564915145u64
324/// );
325/// assert_eq!(Natural::from(8u32).mod_shl(2u16, &Natural::from(10u32)), 2);
326/// assert_eq!(
327///     Natural::from(123456u32).mod_shl(100u64, &Natural::from_str("12345678987654321").unwrap()),
328///     7436663564915145u64
329/// );
330/// assert_eq!(
331///     (&Natural::from(8u32)).mod_shl(2u16, Natural::from(10u32)),
332///     2
333/// );
334/// assert_eq!(
335///     (&Natural::from(123456u32))
336///         .mod_shl(100u64, Natural::from_str("12345678987654321").unwrap()),
337///     7436663564915145u64
338/// );
339/// assert_eq!(
340///     (&Natural::from(8u32)).mod_shl(2u16, &Natural::from(10u32)),
341///     2
342/// );
343/// assert_eq!(
344///     (&Natural::from(123456u32))
345///         .mod_shl(100u64, &Natural::from_str("12345678987654321").unwrap()),
346///     7436663564915145u64
347/// );
348///
349/// assert_eq!(Natural::from(8u32).mod_shl(2i8, Natural::from(10u32)), 2);
350/// assert_eq!(
351///     Natural::from(5u32).mod_shl(-100i32, Natural::from(10u32)),
352///     0
353/// );
354/// assert_eq!(
355///     Natural::from(123456u32).mod_shl(100i64, Natural::from_str("12345678987654321").unwrap()),
356///     7436663564915145u64
357/// );
358/// assert_eq!(Natural::from(8u32).mod_shl(2i8, &Natural::from(10u32)), 2);
359/// assert_eq!(
360///     Natural::from(5u32).mod_shl(-100i32, &Natural::from(10u32)),
361///     0
362/// );
363/// assert_eq!(
364///     Natural::from(123456u32).mod_shl(100i64, &Natural::from_str("12345678987654321").unwrap()),
365///     7436663564915145u64
366/// );
367/// assert_eq!((&Natural::from(8u32)).mod_shl(2i8, Natural::from(10u32)), 2);
368/// assert_eq!(
369///     (&Natural::from(5u32)).mod_shl(-100i32, Natural::from(10u32)),
370///     0
371/// );
372/// assert_eq!(
373///     (&Natural::from(123456u32))
374///         .mod_shl(100i64, Natural::from_str("12345678987654321").unwrap()),
375///     7436663564915145u64
376/// );
377/// assert_eq!(
378///     (&Natural::from(8u32)).mod_shl(2i8, &Natural::from(10u32)),
379///     2
380/// );
381/// assert_eq!(
382///     (&Natural::from(5u32)).mod_shl(-100i32, &Natural::from(10u32)),
383///     0
384/// );
385/// assert_eq!(
386///     (&Natural::from(123456u32))
387///         .mod_shl(100i64, &Natural::from_str("12345678987654321").unwrap()),
388///     7436663564915145u64
389/// );
390/// ```
391///
392/// # mod_shl_assign
393/// ```
394/// use core::str::FromStr;
395/// use malachite_base::num::arithmetic::traits::ModShlAssign;
396/// use malachite_nz::natural::Natural;
397///
398/// let mut x = Natural::from(8u32);
399/// x.mod_shl_assign(2u16, Natural::from(10u32));
400/// assert_eq!(x, 2);
401///
402/// let mut x = Natural::from(123456u32);
403/// x.mod_shl_assign(100u64, Natural::from_str("12345678987654321").unwrap());
404/// assert_eq!(x, 7436663564915145u64);
405///
406/// let mut x = Natural::from(8u32);
407/// x.mod_shl_assign(2u16, &Natural::from(10u32));
408/// assert_eq!(x, 2);
409///
410/// let mut x = Natural::from(123456u32);
411/// x.mod_shl_assign(100u64, &Natural::from_str("12345678987654321").unwrap());
412/// assert_eq!(x, 7436663564915145u64);
413///
414/// let mut x = Natural::from(8u32);
415/// x.mod_shl_assign(2i8, Natural::from(10u32));
416/// assert_eq!(x, 2);
417///
418/// let mut x = Natural::from(5u32);
419/// x.mod_shl_assign(-100i32, Natural::from(10u32));
420/// assert_eq!(x, 0);
421///
422/// let mut x = Natural::from(123456u32);
423/// x.mod_shl_assign(100i64, Natural::from_str("12345678987654321").unwrap());
424/// assert_eq!(x, 7436663564915145u64);
425///
426/// let mut x = Natural::from(8u32);
427/// x.mod_shl_assign(2i8, &Natural::from(10u32));
428/// assert_eq!(x, 2);
429///
430/// let mut x = Natural::from(5u32);
431/// x.mod_shl_assign(-100i32, &Natural::from(10u32));
432/// assert_eq!(x, 0);
433///
434/// let mut x = Natural::from(123456u32);
435/// x.mod_shl_assign(100i64, &Natural::from_str("12345678987654321").unwrap());
436/// assert_eq!(x, 7436663564915145u64);
437/// ```
438pub mod mod_shl;
439/// Implementations of [`ModShr`](malachite_base::num::arithmetic::traits::ModShr) and
440/// [`ModShrAssign`](malachite_base::num::arithmetic::traits::ModShrAssign), traits for
441/// right-shifting a number modulo another number.
442///
443/// # mod_shr
444/// ```
445/// use core::str::FromStr;
446/// use malachite_base::num::arithmetic::traits::ModShr;
447/// use malachite_nz::natural::Natural;
448///
449/// assert_eq!(Natural::from(8u32).mod_shr(-2i8, Natural::from(10u32)), 2);
450/// assert_eq!(Natural::from(5u32).mod_shr(100i32, Natural::from(10u32)), 0);
451/// assert_eq!(
452///     Natural::from(123456u32).mod_shr(-100i64, Natural::from_str("12345678987654321").unwrap()),
453///     7436663564915145u64
454/// );
455/// assert_eq!(Natural::from(8u32).mod_shr(-2i8, &Natural::from(10u32)), 2);
456/// assert_eq!(
457///     Natural::from(5u32).mod_shr(100i32, &Natural::from(10u32)),
458///     0
459/// );
460/// assert_eq!(
461///     Natural::from(123456u32).mod_shr(-100i64, &Natural::from_str("12345678987654321").unwrap()),
462///     7436663564915145u64
463/// );
464/// assert_eq!(
465///     (&Natural::from(8u32)).mod_shr(-2i8, Natural::from(10u32)),
466///     2
467/// );
468/// assert_eq!(
469///     (&Natural::from(5u32)).mod_shr(100i32, Natural::from(10u32)),
470///     0
471/// );
472/// assert_eq!(
473///     (&Natural::from(123456u32))
474///         .mod_shr(-100i64, Natural::from_str("12345678987654321").unwrap()),
475///     7436663564915145u64
476/// );
477/// assert_eq!(
478///     (&Natural::from(8u32)).mod_shr(-2i8, &Natural::from(10u32)),
479///     2
480/// );
481/// assert_eq!(
482///     (&Natural::from(5u32)).mod_shr(100i32, &Natural::from(10u32)),
483///     0
484/// );
485/// assert_eq!(
486///     (&Natural::from(123456u32))
487///         .mod_shr(-100i64, &Natural::from_str("12345678987654321").unwrap()),
488///     7436663564915145u64
489/// );
490/// ```
491///
492/// # mod_shr_assign
493/// ```
494/// use core::str::FromStr;
495/// use malachite_base::num::arithmetic::traits::ModShrAssign;
496/// use malachite_nz::natural::Natural;
497///
498/// let mut x = Natural::from(8u32);
499/// x.mod_shr_assign(-2i8, Natural::from(10u32));
500/// assert_eq!(x, 2);
501///
502/// let mut x = Natural::from(5u32);
503/// x.mod_shr_assign(100i32, Natural::from(10u32));
504/// assert_eq!(x, 0);
505///
506/// let mut x = Natural::from(123456u32);
507/// x.mod_shr_assign(-100i64, Natural::from_str("12345678987654321").unwrap());
508/// assert_eq!(x, 7436663564915145u64);
509///
510/// let mut x = Natural::from(8u32);
511/// x.mod_shr_assign(-2i8, &Natural::from(10u32));
512/// assert_eq!(x, 2);
513///
514/// let mut x = Natural::from(5u32);
515/// x.mod_shr_assign(100i32, &Natural::from(10u32));
516/// assert_eq!(x, 0);
517///
518/// let mut x = Natural::from(123456u32);
519/// x.mod_shr_assign(-100i64, &Natural::from_str("12345678987654321").unwrap());
520/// assert_eq!(x, 7436663564915145u64);
521/// ```
522pub mod mod_shr;
523/// Implementations of traits for squaring a number modulo another number.
524///
525/// The traits are [`ModSquare`](malachite_base::num::arithmetic::traits::ModSquare),
526/// [`ModSquareAssign`](malachite_base::num::arithmetic::traits::ModSquareAssign), and
527/// [`ModSquarePrecomputed`](malachite_base::num::arithmetic::traits::ModSquarePrecomputed).
528/// [`ModSquarePrecomputed`](malachite_base::num::arithmetic::traits::ModSquarePrecomputed) is
529/// useful when having to make several squarings modulo the same modulus.
530pub mod mod_square;
531/// Implementations of [`ModSub`](malachite_base::num::arithmetic::traits::ModSub) and
532/// [`ModSubAssign`](malachite_base::num::arithmetic::traits::ModSubAssign), traits for subtracting
533/// two numbers modulo another number.
534pub mod mod_sub;
535/// Multiplication of [`Natural`](super::Natural)s.
536pub mod mul;
537/// Negation of a [`Natural`](super::Natural), returning an [`Integer`](crate::integer::Integer).
538pub mod neg;
539/// Implementations of [`NextPowerOf2`](malachite_base::num::arithmetic::traits::NextPowerOf2) and
540/// [`NextPowerOf2Assign`](malachite_base::num::arithmetic::traits::NextPowerOf2Assign), traits for
541/// getting the next-highest power of 2.
542pub mod next_power_of_2;
543/// Implementations of [`Parity`](malachite_base::num::arithmetic::traits::Parity), a trait for
544/// determining whether a number is even or odd.
545pub mod parity;
546/// Implementations of [`Pow`](malachite_base::num::arithmetic::traits::Pow) and
547/// [`PowAssign`](malachite_base::num::arithmetic::traits::PowAssign), traits for raising a number
548/// to a power.
549pub mod pow;
550/// Implementations of [`PowerOf2`](malachite_base::num::arithmetic::traits::PowerOf2), a trait for
551/// computing a power of 2.
552pub mod power_of_2;
553/// An implementation of [`Primorial`](malachite_base::num::arithmetic::traits::Primorial), a trait
554/// for computing the primorial of a number.
555pub mod primorial;
556/// Implementations of traits for taking the $n$th root of a number.
557///
558/// The traits are [`FloorRoot`](malachite_base::num::arithmetic::traits::FloorRoot),
559/// [`FloorRootAssign`](malachite_base::num::arithmetic::traits::FloorRootAssign),
560/// [`CeilingRoot`](malachite_base::num::arithmetic::traits::CeilingRoot),
561/// [`CeilingRootAssign`](malachite_base::num::arithmetic::traits::CeilingRootAssign),
562/// [`CheckedRoot`](malachite_base::num::arithmetic::traits::CheckedRoot),
563/// [`RootRem`](malachite_base::num::arithmetic::traits::RootRem), and
564/// [`RootAssignRem`](malachite_base::num::arithmetic::traits::RootAssignRem).
565pub mod root;
566/// Implementations of [`RoundToMultiple`](malachite_base::num::arithmetic::traits::RoundToMultiple)
567/// and [`RoundToMultipleAssign`](malachite_base::num::arithmetic::traits::RoundToMultipleAssign),
568/// traits for rounding a number to a multiple of another number.
569pub mod round_to_multiple;
570/// Implementations of
571/// [`RoundToMultipleOfPowerOf2`](malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2)
572/// and
573/// [`RoundToMultipleOfPowerOf2Assign`](malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign),
574/// traits for rounding a number to a multiple of a power of 2.
575pub mod round_to_multiple_of_power_of_2;
576/// Implementations of [`SaturatingSub`](malachite_base::num::arithmetic::traits::SaturatingSub) and
577/// [`SaturatingSubAssign`](malachite_base::num::arithmetic::traits::SaturatingSubAssign), traits
578/// for subtracting two numbers and saturating at numeric bounds instead of overflowing.
579pub mod saturating_sub;
580/// Implementations of
581/// [`SaturatingSubMul`](malachite_base::num::arithmetic::traits::SaturatingSubMul) and
582/// [`SaturatingSubMulAssign`](malachite_base::num::arithmetic::traits::SaturatingSubMulAssign),
583/// traits for subtracting a number by the product of two numbers and saturating at numeric bounds
584/// instead of overflowing.
585pub mod saturating_sub_mul;
586/// Left-shifting a [`Natural`](super::Natural) (multiplying it by a power of 2).
587///
588/// # shl
589/// ```
590/// use malachite_base::num::arithmetic::traits::Pow;
591/// use malachite_base::num::basic::traits::Zero;
592/// use malachite_nz::natural::Natural;
593///
594/// assert_eq!((Natural::ZERO << 10u8), 0);
595/// assert_eq!((Natural::from(123u32) << 2u16), 492);
596/// assert_eq!(
597///     (Natural::from(123u32) << 100u64).to_string(),
598///     "155921023828072216384094494261248"
599/// );
600/// assert_eq!((&Natural::ZERO << 10u8), 0);
601/// assert_eq!((&Natural::from(123u32) << 2u16), 492);
602/// assert_eq!(
603///     (&Natural::from(123u32) << 100u64).to_string(),
604///     "155921023828072216384094494261248"
605/// );
606///
607/// assert_eq!((Natural::ZERO << 10i8), 0);
608/// assert_eq!((Natural::from(123u32) << 2i16), 492);
609/// assert_eq!(
610///     (Natural::from(123u32) << 100i32).to_string(),
611///     "155921023828072216384094494261248"
612/// );
613/// assert_eq!((Natural::ZERO << -10i64), 0);
614/// assert_eq!((Natural::from(10u32).pow(12) << -10i16), 976562500);
615/// assert_eq!((&Natural::ZERO << 10i8), 0);
616/// assert_eq!((&Natural::from(123u32) << 2i16), 492);
617/// assert_eq!(
618///     (&Natural::from(123u32) << 100i32).to_string(),
619///     "155921023828072216384094494261248"
620/// );
621/// assert_eq!((&Natural::ZERO << -10i64), 0);
622/// assert_eq!((&Natural::from(492u32) << -2i8), 123);
623/// assert_eq!((&Natural::from(10u32).pow(12) << -10i16), 976562500);
624/// ```
625///
626/// # shl_assign
627/// ```
628/// use malachite_base::num::basic::traits::One;
629/// use malachite_nz::natural::Natural;
630///
631/// let mut x = Natural::ONE;
632/// x <<= 1u8;
633/// x <<= 2u16;
634/// x <<= 3u32;
635/// x <<= 4u64;
636/// assert_eq!(x, 1024);
637///
638/// let mut x = Natural::ONE;
639/// x <<= 1i8;
640/// x <<= 2i16;
641/// x <<= 3i32;
642/// x <<= 4i64;
643/// assert_eq!(x, 1024);
644///
645/// let mut x = Natural::from(1024u32);
646/// x <<= -1i8;
647/// x <<= -2i16;
648/// x <<= -3i32;
649/// x <<= -4i64;
650/// assert_eq!(x, 1);
651/// ```
652pub mod shl;
653/// Implementations of [`ShlRound`](malachite_base::num::arithmetic::traits::ShlRound) and
654/// [`ShlRoundAssign`](malachite_base::num::arithmetic::traits::ShlRoundAssign), traits for
655/// multiplying a number by a power of 2 and rounding according to a specified
656/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
657///
658/// # shl_round
659/// ```
660/// use malachite_base::num::arithmetic::traits::ShlRound;
661/// use malachite_base::num::basic::traits::Zero;
662/// use malachite_base::rounding_modes::RoundingMode::*;
663/// use malachite_base::strings::ToDebugString;
664/// use malachite_nz::natural::Natural;
665///
666/// assert_eq!(
667///     Natural::from(0x101u32)
668///         .shl_round(-8i8, Down)
669///         .to_debug_string(),
670///     "(1, Less)"
671/// );
672/// assert_eq!(
673///     Natural::from(0x101u32)
674///         .shl_round(-8i16, Up)
675///         .to_debug_string(),
676///     "(2, Greater)"
677/// );
678/// assert_eq!(
679///     Natural::from(0x101u32)
680///         .shl_round(-9i32, Down)
681///         .to_debug_string(),
682///     "(0, Less)"
683/// );
684/// assert_eq!(
685///     Natural::from(0x101u32)
686///         .shl_round(-9i64, Up)
687///         .to_debug_string(),
688///     "(1, Greater)"
689/// );
690/// assert_eq!(
691///     Natural::from(0x101u32)
692///         .shl_round(-9i8, Nearest)
693///         .to_debug_string(),
694///     "(1, Greater)"
695/// );
696/// assert_eq!(
697///     Natural::from(0xffu32)
698///         .shl_round(-9i16, Nearest)
699///         .to_debug_string(),
700///     "(0, Less)"
701/// );
702/// assert_eq!(
703///     Natural::from(0x100u32)
704///         .shl_round(-9i32, Nearest)
705///         .to_debug_string(),
706///     "(0, Less)"
707/// );
708/// assert_eq!(
709///     Natural::from(0x100u32)
710///         .shl_round(-8i64, Exact)
711///         .to_debug_string(),
712///     "(1, Equal)"
713/// );
714/// assert_eq!(
715///     Natural::ZERO.shl_round(10i8, Exact).to_debug_string(),
716///     "(0, Equal)"
717/// );
718/// assert_eq!(
719///     Natural::from(123u32)
720///         .shl_round(2i16, Exact)
721///         .to_debug_string(),
722///     "(492, Equal)"
723/// );
724/// assert_eq!(
725///     Natural::from(123u32)
726///         .shl_round(100i32, Exact)
727///         .to_debug_string(),
728///     "(155921023828072216384094494261248, Equal)"
729/// );
730///
731/// assert_eq!(
732///     (&Natural::from(0x101u32))
733///         .shl_round(-8i8, Down)
734///         .to_debug_string(),
735///     "(1, Less)"
736/// );
737/// assert_eq!(
738///     (&Natural::from(0x101u32))
739///         .shl_round(-8i16, Up)
740///         .to_debug_string(),
741///     "(2, Greater)"
742/// );
743/// assert_eq!(
744///     (&Natural::from(0x101u32))
745///         .shl_round(-9i32, Down)
746///         .to_debug_string(),
747///     "(0, Less)"
748/// );
749/// assert_eq!(
750///     (&Natural::from(0x101u32))
751///         .shl_round(-9i64, Up)
752///         .to_debug_string(),
753///     "(1, Greater)"
754/// );
755/// assert_eq!(
756///     (&Natural::from(0x101u32))
757///         .shl_round(-9i8, Nearest)
758///         .to_debug_string(),
759///     "(1, Greater)"
760/// );
761/// assert_eq!(
762///     (&Natural::from(0xffu32))
763///         .shl_round(-9i16, Nearest)
764///         .to_debug_string(),
765///     "(0, Less)"
766/// );
767/// assert_eq!(
768///     (&Natural::from(0x100u32))
769///         .shl_round(-9i32, Nearest)
770///         .to_debug_string(),
771///     "(0, Less)"
772/// );
773/// assert_eq!(
774///     (&Natural::from(0x100u32))
775///         .shl_round(-8i64, Exact)
776///         .to_debug_string(),
777///     "(1, Equal)"
778/// );
779/// assert_eq!(
780///     (&Natural::ZERO).shl_round(10i8, Exact).to_debug_string(),
781///     "(0, Equal)"
782/// );
783/// assert_eq!(
784///     (&Natural::from(123u32))
785///         .shl_round(2i16, Exact)
786///         .to_debug_string(),
787///     "(492, Equal)"
788/// );
789/// assert_eq!(
790///     (&Natural::from(123u32))
791///         .shl_round(100i32, Exact)
792///         .to_debug_string(),
793///     "(155921023828072216384094494261248, Equal)"
794/// );
795/// ```
796///
797/// # shl_round_assign
798/// ```
799/// use core::cmp::Ordering::*;
800/// use malachite_base::num::arithmetic::traits::ShlRoundAssign;
801/// use malachite_base::num::basic::traits::One;
802/// use malachite_base::rounding_modes::RoundingMode::*;
803/// use malachite_nz::natural::Natural;
804///
805/// let mut n = Natural::from(0x101u32);
806/// assert_eq!(n.shl_round_assign(-8i8, Down), Less);
807/// assert_eq!(n, 1);
808///
809/// let mut n = Natural::from(0x101u32);
810/// assert_eq!(n.shl_round_assign(-8i16, Up), Greater);
811/// assert_eq!(n, 2);
812///
813/// let mut n = Natural::from(0x101u32);
814/// assert_eq!(n.shl_round_assign(-9i32, Down), Less);
815/// assert_eq!(n, 0);
816///
817/// let mut n = Natural::from(0x101u32);
818/// assert_eq!(n.shl_round_assign(-9i64, Up), Greater);
819/// assert_eq!(n, 1);
820///
821/// let mut n = Natural::from(0x101u32);
822/// assert_eq!(n.shl_round_assign(-9i8, Nearest), Greater);
823/// assert_eq!(n, 1);
824///
825/// let mut n = Natural::from(0xffu32);
826/// assert_eq!(n.shl_round_assign(-9i16, Nearest), Less);
827/// assert_eq!(n, 0);
828///
829/// let mut n = Natural::from(0x100u32);
830/// assert_eq!(n.shl_round_assign(-9i32, Nearest), Less);
831/// assert_eq!(n, 0);
832///
833/// let mut n = Natural::from(0x100u32);
834/// assert_eq!(n.shl_round_assign(-8i64, Exact), Equal);
835/// assert_eq!(n, 1);
836///
837/// let mut x = Natural::ONE;
838/// assert_eq!(x.shl_round_assign(1i8, Exact), Equal);
839/// assert_eq!(x.shl_round_assign(2i16, Exact), Equal);
840/// assert_eq!(x.shl_round_assign(3i32, Exact), Equal);
841/// assert_eq!(x.shl_round_assign(4i64, Exact), Equal);
842/// assert_eq!(x, 1024);
843/// ```
844pub mod shl_round;
845/// Right-shifting a [`Natural`](super::Natural) (dividing it by a power of 2).
846///
847/// # shr
848/// ```
849/// use malachite_base::num::arithmetic::traits::Pow;
850/// use malachite_base::num::basic::traits::Zero;
851/// use malachite_nz::natural::Natural;
852///
853/// assert_eq!((Natural::ZERO >> 10u8), 0);
854/// assert_eq!((Natural::from(492u32) >> 2u32), 123);
855/// assert_eq!((Natural::from(10u32).pow(12) >> 10u64), 976562500);
856/// assert_eq!((&Natural::ZERO >> 10u8), 0);
857/// assert_eq!((&Natural::from(492u32) >> 2u32), 123);
858/// assert_eq!((&Natural::from(10u32).pow(12) >> 10u64), 976562500);
859///
860/// assert_eq!((Natural::ZERO >> 10i8), 0);
861/// assert_eq!((Natural::from(492u32) >> 2i16), 123);
862/// assert_eq!((Natural::from(10u32).pow(12) >> 10i32), 976562500);
863/// assert_eq!((Natural::ZERO >> -10i64), 0);
864/// assert_eq!((Natural::from(123u32) >> -2i8), 492);
865/// assert_eq!(
866///     (Natural::from(123u32) >> -100i16).to_string(),
867///     "155921023828072216384094494261248"
868/// );
869/// assert_eq!((&Natural::ZERO >> -10i8), 0);
870/// assert_eq!((&Natural::from(123u32) >> -2i16), 492);
871/// assert_eq!(
872///     (&Natural::from(123u32) >> -100i32).to_string(),
873///     "155921023828072216384094494261248"
874/// );
875/// assert_eq!((&Natural::ZERO >> 10i64), 0);
876/// assert_eq!((&Natural::from(492u32) >> 2i8), 123);
877/// assert_eq!((&Natural::from(10u32).pow(12) >> 10i16), 976562500);
878/// ```
879///
880/// # shr_assign
881/// ```
882/// use malachite_base::num::basic::traits::One;
883/// use malachite_nz::natural::Natural;
884///
885/// let mut x = Natural::from(1024u32);
886/// x >>= 1u8;
887/// x >>= 2u16;
888/// x >>= 3u32;
889/// x >>= 4u64;
890/// assert_eq!(x, 1);
891///
892/// let mut x = Natural::ONE;
893/// x >>= -1i8;
894/// x >>= -2i16;
895/// x >>= -3i32;
896/// x >>= -4i64;
897/// assert_eq!(x, 1024);
898///
899/// let mut x = Natural::from(1024u32);
900/// x >>= 1i8;
901/// x >>= 2i16;
902/// x >>= 3i32;
903/// x >>= 4i64;
904/// assert_eq!(x, 1);
905/// ```
906pub mod shr;
907/// Implementations of [`ShrRound`](malachite_base::num::arithmetic::traits::ShrRound) and
908/// [`ShrRoundAssign`](malachite_base::num::arithmetic::traits::ShrRoundAssign), traits for dividing
909/// a number by a power of 2 and rounding according to a specified
910/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
911///
912/// # shr_round
913/// ```
914/// use malachite_base::num::arithmetic::traits::ShrRound;
915/// use malachite_base::num::basic::traits::Zero;
916/// use malachite_base::rounding_modes::RoundingMode::*;
917/// use malachite_base::strings::ToDebugString;
918/// use malachite_nz::natural::Natural;
919///
920/// assert_eq!(
921///     Natural::from(0x101u32)
922///         .shr_round(8u8, Down)
923///         .to_debug_string(),
924///     "(1, Less)"
925/// );
926/// assert_eq!(
927///     Natural::from(0x101u32)
928///         .shr_round(8u16, Up)
929///         .to_debug_string(),
930///     "(2, Greater)"
931/// );
932/// assert_eq!(
933///     Natural::from(0x101u32)
934///         .shr_round(9u32, Down)
935///         .to_debug_string(),
936///     "(0, Less)"
937/// );
938/// assert_eq!(
939///     Natural::from(0x101u32)
940///         .shr_round(9u64, Up)
941///         .to_debug_string(),
942///     "(1, Greater)"
943/// );
944/// assert_eq!(
945///     Natural::from(0x101u32)
946///         .shr_round(9u8, Nearest)
947///         .to_debug_string(),
948///     "(1, Greater)"
949/// );
950/// assert_eq!(
951///     Natural::from(0xffu32)
952///         .shr_round(9u16, Nearest)
953///         .to_debug_string(),
954///     "(0, Less)"
955/// );
956/// assert_eq!(
957///     Natural::from(0x100u32)
958///         .shr_round(9u32, Nearest)
959///         .to_debug_string(),
960///     "(0, Less)"
961/// );
962/// assert_eq!(
963///     Natural::from(0x100u32)
964///         .shr_round(8u64, Exact)
965///         .to_debug_string(),
966///     "(1, Equal)"
967/// );
968/// assert_eq!(
969///     (&Natural::from(0x101u32))
970///         .shr_round(8u8, Down)
971///         .to_debug_string(),
972///     "(1, Less)"
973/// );
974/// assert_eq!(
975///     (&Natural::from(0x101u32))
976///         .shr_round(8u16, Up)
977///         .to_debug_string(),
978///     "(2, Greater)"
979/// );
980/// assert_eq!(
981///     (&Natural::from(0x101u32))
982///         .shr_round(9u32, Down)
983///         .to_debug_string(),
984///     "(0, Less)"
985/// );
986/// assert_eq!(
987///     (&Natural::from(0x101u32))
988///         .shr_round(9u64, Up)
989///         .to_debug_string(),
990///     "(1, Greater)"
991/// );
992/// assert_eq!(
993///     (&Natural::from(0x101u32))
994///         .shr_round(9u8, Nearest)
995///         .to_debug_string(),
996///     "(1, Greater)"
997/// );
998/// assert_eq!(
999///     (&Natural::from(0xffu32))
1000///         .shr_round(9u16, Nearest)
1001///         .to_debug_string(),
1002///     "(0, Less)"
1003/// );
1004/// assert_eq!(
1005///     (&Natural::from(0x100u32))
1006///         .shr_round(9u32, Nearest)
1007///         .to_debug_string(),
1008///     "(0, Less)"
1009/// );
1010/// assert_eq!(
1011///     (&Natural::from(0x100u32))
1012///         .shr_round(8u64, Exact)
1013///         .to_debug_string(),
1014///     "(1, Equal)"
1015/// );
1016///
1017/// assert_eq!(
1018///     Natural::from(0x101u32)
1019///         .shr_round(8i8, Down)
1020///         .to_debug_string(),
1021///     "(1, Less)"
1022/// );
1023/// assert_eq!(
1024///     Natural::from(0x101u32)
1025///         .shr_round(8i16, Up)
1026///         .to_debug_string(),
1027///     "(2, Greater)"
1028/// );
1029/// assert_eq!(
1030///     Natural::from(0x101u32)
1031///         .shr_round(9i32, Down)
1032///         .to_debug_string(),
1033///     "(0, Less)"
1034/// );
1035/// assert_eq!(
1036///     Natural::from(0x101u32)
1037///         .shr_round(9i64, Up)
1038///         .to_debug_string(),
1039///     "(1, Greater)"
1040/// );
1041/// assert_eq!(
1042///     Natural::from(0x101u32)
1043///         .shr_round(9i8, Nearest)
1044///         .to_debug_string(),
1045///     "(1, Greater)"
1046/// );
1047/// assert_eq!(
1048///     Natural::from(0xffu32)
1049///         .shr_round(9i16, Nearest)
1050///         .to_debug_string(),
1051///     "(0, Less)"
1052/// );
1053/// assert_eq!(
1054///     Natural::from(0x100u32)
1055///         .shr_round(9i32, Nearest)
1056///         .to_debug_string(),
1057///     "(0, Less)"
1058/// );
1059/// assert_eq!(
1060///     Natural::from(0x100u32)
1061///         .shr_round(8i64, Exact)
1062///         .to_debug_string(),
1063///     "(1, Equal)"
1064/// );
1065/// assert_eq!(
1066///     Natural::ZERO.shr_round(-10i8, Exact).to_debug_string(),
1067///     "(0, Equal)"
1068/// );
1069/// assert_eq!(
1070///     Natural::from(123u32)
1071///         .shr_round(-2i16, Exact)
1072///         .to_debug_string(),
1073///     "(492, Equal)"
1074/// );
1075/// assert_eq!(
1076///     Natural::from(123u32)
1077///         .shr_round(-100i32, Exact)
1078///         .to_debug_string(),
1079///     "(155921023828072216384094494261248, Equal)"
1080/// );
1081/// assert_eq!(
1082///     (&Natural::from(0x101u32))
1083///         .shr_round(8i8, Down)
1084///         .to_debug_string(),
1085///     "(1, Less)"
1086/// );
1087/// assert_eq!(
1088///     (&Natural::from(0x101u32))
1089///         .shr_round(8i16, Up)
1090///         .to_debug_string(),
1091///     "(2, Greater)"
1092/// );
1093/// assert_eq!(
1094///     (&Natural::from(0x101u32))
1095///         .shr_round(9i32, Down)
1096///         .to_debug_string(),
1097///     "(0, Less)"
1098/// );
1099/// assert_eq!(
1100///     (&Natural::from(0x101u32))
1101///         .shr_round(9i64, Up)
1102///         .to_debug_string(),
1103///     "(1, Greater)"
1104/// );
1105/// assert_eq!(
1106///     (&Natural::from(0x101u32))
1107///         .shr_round(9i8, Nearest)
1108///         .to_debug_string(),
1109///     "(1, Greater)"
1110/// );
1111/// assert_eq!(
1112///     (&Natural::from(0xffu32))
1113///         .shr_round(9i16, Nearest)
1114///         .to_debug_string(),
1115///     "(0, Less)"
1116/// );
1117/// assert_eq!(
1118///     (&Natural::from(0x100u32))
1119///         .shr_round(9i32, Nearest)
1120///         .to_debug_string(),
1121///     "(0, Less)"
1122/// );
1123/// assert_eq!(
1124///     (&Natural::from(0x100u32))
1125///         .shr_round(8i64, Exact)
1126///         .to_debug_string(),
1127///     "(1, Equal)"
1128/// );
1129/// assert_eq!(
1130///     (&Natural::ZERO).shr_round(-10i8, Exact).to_debug_string(),
1131///     "(0, Equal)"
1132/// );
1133/// assert_eq!(
1134///     (&Natural::from(123u32))
1135///         .shr_round(-2i16, Exact)
1136///         .to_debug_string(),
1137///     "(492, Equal)"
1138/// );
1139/// assert_eq!(
1140///     (&Natural::from(123u32))
1141///         .shr_round(-100i32, Exact)
1142///         .to_debug_string(),
1143///     "(155921023828072216384094494261248, Equal)"
1144/// );
1145/// ```
1146///
1147/// # shr_round_assign
1148/// ```
1149/// use core::cmp::Ordering::*;
1150/// use malachite_base::num::arithmetic::traits::ShrRoundAssign;
1151/// use malachite_base::num::basic::traits::One;
1152/// use malachite_base::rounding_modes::RoundingMode::*;
1153/// use malachite_nz::natural::Natural;
1154///
1155/// let mut n = Natural::from(0x101u32);
1156/// assert_eq!(n.shr_round_assign(8u8, Down), Less);
1157/// assert_eq!(n, 1);
1158///
1159/// let mut n = Natural::from(0x101u32);
1160/// assert_eq!(n.shr_round_assign(8u16, Up), Greater);
1161/// assert_eq!(n, 2);
1162///
1163/// let mut n = Natural::from(0x101u32);
1164/// assert_eq!(n.shr_round_assign(9u32, Down), Less);
1165/// assert_eq!(n, 0);
1166///
1167/// let mut n = Natural::from(0x101u32);
1168/// assert_eq!(n.shr_round_assign(9u64, Up), Greater);
1169/// assert_eq!(n, 1);
1170///
1171/// let mut n = Natural::from(0x101u32);
1172/// assert_eq!(n.shr_round_assign(9u8, Nearest), Greater);
1173/// assert_eq!(n, 1);
1174///
1175/// let mut n = Natural::from(0xffu32);
1176/// assert_eq!(n.shr_round_assign(9u16, Nearest), Less);
1177/// assert_eq!(n, 0);
1178///
1179/// let mut n = Natural::from(0x100u32);
1180/// assert_eq!(n.shr_round_assign(9u32, Nearest), Less);
1181/// assert_eq!(n, 0);
1182///
1183/// let mut n = Natural::from(0x100u32);
1184/// assert_eq!(n.shr_round_assign(8u64, Exact), Equal);
1185/// assert_eq!(n, 1);
1186///
1187/// let mut n = Natural::from(0x101u32);
1188/// assert_eq!(n.shr_round_assign(8i8, Down), Less);
1189/// assert_eq!(n, 1);
1190///
1191/// let mut n = Natural::from(0x101u32);
1192/// assert_eq!(n.shr_round_assign(8i16, Up), Greater);
1193/// assert_eq!(n, 2);
1194///
1195/// let mut n = Natural::from(0x101u32);
1196/// assert_eq!(n.shr_round_assign(9i32, Down), Less);
1197/// assert_eq!(n, 0);
1198///
1199/// let mut n = Natural::from(0x101u32);
1200/// assert_eq!(n.shr_round_assign(9i64, Up), Greater);
1201/// assert_eq!(n, 1);
1202///
1203/// let mut n = Natural::from(0x101u32);
1204/// assert_eq!(n.shr_round_assign(9i8, Nearest), Greater);
1205/// assert_eq!(n, 1);
1206///
1207/// let mut n = Natural::from(0xffu32);
1208/// assert_eq!(n.shr_round_assign(9i16, Nearest), Less);
1209/// assert_eq!(n, 0);
1210///
1211/// let mut n = Natural::from(0x100u32);
1212/// assert_eq!(n.shr_round_assign(9i32, Nearest), Less);
1213/// assert_eq!(n, 0);
1214///
1215/// let mut n = Natural::from(0x100u32);
1216/// assert_eq!(n.shr_round_assign(8i64, Exact), Equal);
1217/// assert_eq!(n, 1);
1218///
1219/// let mut x = Natural::ONE;
1220/// assert_eq!(x.shr_round_assign(-1i8, Exact), Equal);
1221/// assert_eq!(x.shr_round_assign(-2i16, Exact), Equal);
1222/// assert_eq!(x.shr_round_assign(-3i32, Exact), Equal);
1223/// assert_eq!(x.shr_round_assign(-4i64, Exact), Equal);
1224/// assert_eq!(x, 1024);
1225/// ```
1226pub mod shr_round;
1227/// Implementations of [`Sign`](malachite_base::num::arithmetic::traits::Sign), a trait for
1228/// determining the sign of a number.
1229pub mod sign;
1230/// Implementations of traits for taking the square root of a number.
1231///
1232/// The traits are [`FloorSqrt`](malachite_base::num::arithmetic::traits::FloorSqrt),
1233/// [`FloorSqrtAssign`](malachite_base::num::arithmetic::traits::FloorSqrtAssign),
1234/// [`CeilingSqrt`](malachite_base::num::arithmetic::traits::CeilingSqrt),
1235/// [`CeilingSqrtAssign`](malachite_base::num::arithmetic::traits::CeilingSqrtAssign),
1236/// [`CheckedSqrt`](malachite_base::num::arithmetic::traits::CheckedSqrt),
1237/// [`SqrtRem`](malachite_base::num::arithmetic::traits::SqrtRem), and
1238/// [`SqrtAssignRem`](malachite_base::num::arithmetic::traits::SqrtAssignRem).
1239pub mod sqrt;
1240/// Implementations of [`Square`](malachite_base::num::arithmetic::traits::Square) and
1241/// [`SquareAssign`](malachite_base::num::arithmetic::traits::SquareAssign), traits for squaring a
1242/// number.
1243pub mod square;
1244/// Subtraction of [`Natural`](super::Natural)s.
1245pub mod sub;
1246/// Implementations of [`SubMul`](malachite_base::num::arithmetic::traits::SubMul) and
1247/// [`SubMulAssign`](malachite_base::num::arithmetic::traits::SubMulAssign), traits for subtracting
1248/// the product of two numbers from a number.
1249pub mod sub_mul;