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