malachite_nz/integer/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/// Absolute value of [`Integer`](super::Integer)s, including implementations of
10/// [`UnsignedAbs`](malachite_base::num::arithmetic::traits::UnsignedAbs).
11pub mod abs;
12/// Implementations of [`AbsDiff`](malachite_base::num::arithmetic::traits::AbsDiff) and
13/// [`AbsDiffAssign`](malachite_base::num::arithmetic::traits::AbsDiffAssign), traits for getting
14/// the absolute value of the difference between two numbers.
15pub mod abs_diff;
16/// Implementations of [`AbsSquared`](malachite_base::num::arithmetic::traits::AbsSquared) and
17/// [`AbsSquaredAssign`](malachite_base::num::arithmetic::traits::AbsSquaredAssign), traits for
18/// computing the squared absolute value of a number. For real types this is the same as squaring.
19pub mod abs_squared;
20/// Addition of [`Integer`](super::Integer)s.
21pub mod add;
22/// Implementations of [`AddMul`](malachite_base::num::arithmetic::traits::AddMul) and
23/// [`AddMulAssign`](malachite_base::num::arithmetic::traits::AddMulAssign), traits for adding a
24/// number and the product of two other numbers.
25pub mod add_mul;
26/// [`Average`](malachite_base::num::arithmetic::traits::Average),
27/// [`AverageAssign`](malachite_base::num::arithmetic::traits::AverageAssign),
28/// [`AverageRound`](malachite_base::num::arithmetic::traits::AverageRound), and
29/// [`AverageRoundAssign`](malachite_base::num::arithmetic::traits::AverageRoundAssign), traits for
30/// computing the average (arithmetic mean) of two numbers.
31pub mod average;
32/// [`BalancedMod`](malachite_base::num::arithmetic::traits::BalancedMod) and
33/// [`BalancedModAssign`](malachite_base::num::arithmetic::traits::BalancedModAssign), traits for
34/// finding the representative of a number modulo another number that is closest to zero.
35pub mod balanced_mod;
36/// Implementations of
37/// [`BinomialCoefficient`](malachite_base::num::arithmetic::traits::BinomialCoefficient), a trait
38/// for computing the binomial coefficient of two numbers.
39pub mod binomial_coefficient;
40/// An implementation of
41/// [`CanonicalUnitIPow`](malachite_base::num::arithmetic::traits::CanonicalUnitIPow), a trait for
42/// finding the power of $i$ that brings a number into canonical unit form.
43pub mod canonical_unit_i_pow;
44/// Implementations of
45/// [`CanonicalizeUnit`](malachite_base::num::arithmetic::traits::CanonicalizeUnit) and
46/// [`CanonicalizeUnitAssign`](malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign),
47/// traits for bringing a number into canonical unit form.
48pub mod canonicalize_unit;
49/// Implementations of [`Conjugate`](malachite_base::num::arithmetic::traits::Conjugate) and
50/// [`ConjugateAssign`](malachite_base::num::arithmetic::traits::ConjugateAssign), traits for
51/// computing the complex conjugate of a number. A real number is its own conjugate.
52pub mod conjugate;
53/// Implementations of [`BalancedCrt`](malachite_base::num::arithmetic::traits::BalancedCrt), a
54/// trait for combining two congruences by the Chinese remainder theorem and returning the
55/// representative of smallest absolute value.
56pub mod crt;
57/// Division of [`Integer`](super::Integer)s.
58pub mod div;
59/// Implementations of [`DivEuclidean`](malachite_base::num::arithmetic::traits::DivEuclidean) and
60/// [`DivEuclideanAssign`](malachite_base::num::arithmetic::traits::DivEuclideanAssign), traits for
61/// finding the quotient of two numbers, rounded so that the remainder would be nonnegative.
62pub mod div_euclidean;
63/// Implementations of [`DivExact`](malachite_base::num::arithmetic::traits::DivExact) and
64/// [`DivExactAssign`](malachite_base::num::arithmetic::traits::DivExactAssign), traits for dividing
65/// two numbers when it's known that the division is exact.
66pub mod div_exact;
67/// Implementations of traits for simultaneously finding the quotient and remainder of two numbers,
68/// subject to various rounding rules.
69///
70/// These are the traits:
71///
72/// | rounding | by value or reference | by mutable reference (assignment) |
73/// |--------------|---------------------------------|----------------------------------------|
74/// | towards $-\infty$ | [`DivMod`](malachite_base::num::arithmetic::traits::DivMod) | [`DivAssignMod`](malachite_base::num::arithmetic::traits::DivAssignMod) |
75/// | towards 0 | [`DivRem`](malachite_base::num::arithmetic::traits::DivRem) | [`DivAssignRem`](malachite_base::num::arithmetic::traits::DivAssignRem) |
76/// | towards $\infty$ | [`CeilingDivMod`](malachite_base::num::arithmetic::traits::CeilingDivMod) | [`CeilingDivAssignMod`](malachite_base::num::arithmetic::traits::CeilingDivAssignMod) |
77#[cfg_attr(dylint_lib = "malachite_lints", expect(long_lines))]
78pub mod div_mod;
79/// Implementations of [`DivModEuclidean`](malachite_base::num::arithmetic::traits::DivModEuclidean)
80/// and [`DivAssignModEuclidean`](malachite_base::num::arithmetic::traits::DivAssignModEuclidean),
81/// traits for simultaneously finding the quotient and remainder of two numbers, where the remainder
82/// is nonnegative.
83pub mod div_mod_euclidean;
84/// Implementations of [`DivRound`](malachite_base::num::arithmetic::traits::DivRound) and
85/// [`DivExactAssign`](malachite_base::num::arithmetic::traits::DivRoundAssign), traits for dividing
86/// two numbers according to a specified
87/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
88pub mod div_round;
89/// Implementations of [`DivisibleBy`](malachite_base::num::arithmetic::traits::DivisibleBy), a
90/// trait for determining whether one number is divisible by another.
91pub mod divisible_by;
92/// Implementations of
93/// [`DivisibleByPowerOf2`](malachite_base::num::arithmetic::traits::DivisibleByPowerOf2), a trait
94/// for determining whether a number is divisible by $2^k$.
95pub mod divisible_by_power_of_2;
96/// Implementations of [`EqMod`](malachite_base::num::arithmetic::traits::EqMod), a trait for
97/// determining whether one number is equal by another modulo a third.
98pub mod eq_mod;
99/// Implementations of [`EqModPowerOf2`](malachite_base::num::arithmetic::traits::EqModPowerOf2), a
100/// trait for determining whether one number is equal to another modulo $2^k$.
101pub mod eq_mod_power_of_2;
102/// Implementations of [`ExtendedGcd`](malachite_base::num::arithmetic::traits::ExtendedGcd), a
103/// trait for computing the extended GCD of two numbers.
104pub mod extended_gcd;
105/// Implementations of
106/// [`FallingFactorial`](malachite_base::num::arithmetic::traits::FallingFactorial), a trait for
107/// computing the falling factorial of a number.
108pub mod falling_factorial;
109/// Implementations of [`Gcd`](malachite_base::num::arithmetic::traits::Gcd) and
110/// [`GcdAssign`](malachite_base::num::arithmetic::traits::GcdAssign), traits for computing the GCD
111/// (greatest common divisor) of two numbers.
112pub mod gcd;
113/// An implementation of [`IsPowerOf2`](malachite_base::num::arithmetic::traits::IsPowerOf2), a
114/// trait for determining whether a number is an integer power of 2.
115pub mod is_power_of_2;
116/// An implementation of [`IsUnit`](malachite_base::num::arithmetic::traits::IsUnit), a trait for
117/// determining whether a number is a unit of its ring.
118pub mod is_unit;
119/// Implementations of [`LegendreSymbol`](malachite_base::num::arithmetic::traits::LegendreSymbol),
120/// [`JacobiSymbol`](malachite_base::num::arithmetic::traits::JacobiSymbol), and
121/// [`KroneckerSymbol`](malachite_base::num::arithmetic::traits::KroneckerSymbol), traits for
122/// computing the Legendre, Jacobi, and Kronecker symbols of two numbers.
123pub mod kronecker_symbol;
124/// Implementations of [`ModEuclidean`](malachite_base::num::arithmetic::traits::ModEuclidean) and
125/// [`ModEuclideanAssign`](malachite_base::num::arithmetic::traits::ModEuclideanAssign), traits for
126/// finding the remainder of two numbers, where the remainder is nonnegative.
127pub mod mod_euclidean;
128/// Implementations of traits for finding the remainder of two numbers, subject to various rounding
129/// rules.
130///
131/// These are the traits:
132///
133/// | rounding | by value or reference | by mutable reference (assignment) |
134/// |-------------------|----------------------------|----------------------------------------|
135/// | towards $-\infty$ | [`Mod`](malachite_base::num::arithmetic::traits::Mod) | [`ModAssign`](malachite_base::num::arithmetic::traits::ModAssign) |
136/// | towards $\infty$ | [`CeilingMod`](malachite_base::num::arithmetic::traits::CeilingMod) | [`CeilingModAssign`](malachite_base::num::arithmetic::traits::CeilingModAssign) |
137///
138/// The [`Rem`](core::ops::Rem) trait in the standard library rounds towards 0.
139#[cfg_attr(dylint_lib = "malachite_lints", expect(long_lines))]
140pub mod mod_op;
141/// Implementations of traits for finding the remainder of a number divided by $2^k$, subject to
142/// various rounding rules.
143///
144/// These are the traits:
145///
146/// | rounding | by value or reference | by mutable reference (assignment) |
147/// |----------|-----------------------|-----------------------------------|
148/// | towards $-\infty$ | [`ModPowerOf2`](malachite_base::num::arithmetic::traits::ModPowerOf2) | [`ModPowerOf2Assign`](malachite_base::num::arithmetic::traits::ModPowerOf2Assign) |
149/// | towards 0 | [`RemPowerOf2`](malachite_base::num::arithmetic::traits::RemPowerOf2) | [`RemPowerOf2Assign`](malachite_base::num::arithmetic::traits::RemPowerOf2Assign) |
150/// | towards $\infty$ | [`CeilingModPowerOf2`](malachite_base::num::arithmetic::traits::CeilingModPowerOf2) | [`CeilingModPowerOf2Assign`](malachite_base::num::arithmetic::traits::CeilingModPowerOf2Assign) |
151#[cfg_attr(dylint_lib = "malachite_lints", expect(long_lines))]
152pub mod mod_power_of_2;
153/// Multiplication of [`Integer`](super::Integer)s.
154pub mod mul;
155pub mod mul_add_mul;
156/// Implementations of [`MulShrRound`](malachite_base::num::arithmetic::traits::MulShrRound) and
157/// [`MulShrRoundAssign`](malachite_base::num::arithmetic::traits::MulShrRoundAssign), traits for
158/// multiplying two numbers and right-shifting the product with a specified rounding mode. When most
159/// of the product is discarded, a short product avoids computing the rest.
160pub mod mul_shr_round;
161pub mod mul_sub_mul;
162/// Negation of an [`Integer`](super::Integer). The one-shot balanced multi-modulus Chinese
163/// remainder combination, [`Integer::multi_balanced_crt`](super::Integer::multi_balanced_crt).
164pub mod multi_crt;
165pub mod neg;
166/// Implementations of [`Parity`](malachite_base::num::arithmetic::traits::Parity), a trait for
167/// determining whether a number is even or odd.
168pub mod parity;
169/// Implementations of [`Pow`](malachite_base::num::arithmetic::traits::Pow) and
170/// [`PowAssign`](malachite_base::num::arithmetic::traits::PowAssign), traits for raising a number
171/// to a power.
172pub mod pow;
173/// Implementations of [`PowerOf2`](malachite_base::num::arithmetic::traits::PowerOf2), a trait for
174/// computing a power of 2.
175pub mod power_of_2;
176/// Implementations of
177/// [`RisingFactorial`](malachite_base::num::arithmetic::traits::RisingFactorial), a trait for
178/// computing the rising factorial of a number.
179pub mod rising_factorial;
180/// Implementations of traits for taking the $n$th root of a number.
181///
182/// The traits are [`FloorRoot`](malachite_base::num::arithmetic::traits::FloorRoot),
183/// [`FloorRootAssign`](malachite_base::num::arithmetic::traits::FloorRootAssign),
184/// [`CeilingRoot`](malachite_base::num::arithmetic::traits::CeilingRoot),
185/// [`CeilingRootAssign`](malachite_base::num::arithmetic::traits::CeilingRootAssign), and
186/// [`CheckedRoot`](malachite_base::num::arithmetic::traits::CheckedRoot).
187pub mod root;
188/// Implementations of [`RoundToMultiple`](malachite_base::num::arithmetic::traits::RoundToMultiple)
189/// and [`RoundToMultipleAssign`](malachite_base::num::arithmetic::traits::RoundToMultipleAssign),
190/// traits for rounding a number to a multiple of another number.
191pub mod round_to_multiple;
192/// Implementations of
193/// [`RoundToMultipleOfPowerOf2`](malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2)
194/// and
195/// [`RoundToMultipleOfPowerOf2Assign`](malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign),
196/// traits for rounding a number to a multiple of a power of 2.
197#[cfg_attr(dylint_lib = "malachite_lints", expect(long_lines))]
198pub mod round_to_multiple_of_power_of_2;
199/// Left-shifting an [`Integer`](super::Integer) (multiplying it by a power of 2).
200///
201/// # shl
202/// ```
203/// use malachite_base::num::arithmetic::traits::Pow;
204/// use malachite_base::num::basic::traits::Zero;
205/// use malachite_nz::integer::Integer;
206///
207/// assert_eq!(Integer::ZERO << 10u8, 0);
208/// assert_eq!(Integer::from(123) << 2u16, 492);
209/// assert_eq!(
210/// (Integer::from(123) << 100u64).to_string(),
211/// "155921023828072216384094494261248"
212/// );
213/// assert_eq!(Integer::from(-123) << 2u64, -492);
214/// assert_eq!(
215/// (Integer::from(-123) << 100u8).to_string(),
216/// "-155921023828072216384094494261248"
217/// );
218/// assert_eq!(&Integer::ZERO << 10u8, 0);
219/// assert_eq!(&Integer::from(123) << 2u16, 492);
220/// assert_eq!(
221/// (&Integer::from(123) << 100u64).to_string(),
222/// "155921023828072216384094494261248"
223/// );
224/// assert_eq!(&Integer::from(-123) << 2u64, -492);
225/// assert_eq!(
226/// (&Integer::from(-123) << 100u8).to_string(),
227/// "-155921023828072216384094494261248"
228/// );
229///
230/// assert_eq!(Integer::ZERO << 10i8, 0);
231/// assert_eq!(Integer::from(123) << 2i16, 492);
232/// assert_eq!(
233/// (Integer::from(123) << 100i32).to_string(),
234/// "155921023828072216384094494261248"
235/// );
236/// assert_eq!(Integer::from(-123) << 2i64, -492);
237/// assert_eq!(
238/// (Integer::from(-123) << 100i8).to_string(),
239/// "-155921023828072216384094494261248"
240/// );
241/// assert_eq!(Integer::ZERO << -10i16, 0);
242/// assert_eq!(Integer::from(492) << -2i32, 123);
243/// assert_eq!(-Integer::from(10u32).pow(12) << -10i64, -976562500);
244/// assert_eq!(&Integer::ZERO << 10i8, 0);
245/// assert_eq!(&Integer::from(123) << 2i16, 492);
246/// assert_eq!(
247/// (&Integer::from(123) << 100i32).to_string(),
248/// "155921023828072216384094494261248"
249/// );
250/// assert_eq!(&Integer::from(-123) << 2i64, -492);
251/// assert_eq!(
252/// (&Integer::from(-123) << 100i8).to_string(),
253/// "-155921023828072216384094494261248"
254/// );
255/// assert_eq!(&Integer::ZERO << -10i16, 0);
256/// assert_eq!(&Integer::from(492) << -2i32, 123);
257/// assert_eq!(&(-Integer::from(10u32).pow(12)) << -10i64, -976562500);
258/// ```
259///
260/// # shl_assign
261/// ```
262/// use malachite_base::num::basic::traits::{NegativeOne, One};
263/// use malachite_nz::integer::Integer;
264///
265/// let mut x = Integer::ONE;
266/// x <<= 1u8;
267/// x <<= 2u16;
268/// x <<= 3u64;
269/// x <<= 4u64;
270/// assert_eq!(x, 1024);
271/// let mut x = Integer::NEGATIVE_ONE;
272/// x <<= 1u8;
273/// x <<= 2u16;
274/// x <<= 3u64;
275/// x <<= 4u64;
276/// assert_eq!(x, -1024);
277///
278/// let mut x = Integer::ONE;
279/// x <<= 1i8;
280/// x <<= 2i16;
281/// x <<= 3i32;
282/// x <<= 4i64;
283/// assert_eq!(x, 1024);
284/// let mut x = Integer::NEGATIVE_ONE;
285/// x <<= 1i8;
286/// x <<= 2i16;
287/// x <<= 3i32;
288/// x <<= 4i64;
289/// assert_eq!(x, -1024);
290///
291/// let mut x = Integer::from(1024);
292/// x <<= -1i8;
293/// x <<= -2i16;
294/// x <<= -3i32;
295/// x <<= -4i64;
296/// assert_eq!(x, 1);
297/// ```
298pub mod shl;
299/// Implementations of [`ShlRound`](malachite_base::num::arithmetic::traits::ShlRound) and
300/// [`ShlRoundAssign`](malachite_base::num::arithmetic::traits::ShlRoundAssign), traits for
301/// multiplying a number by a power of 2 and rounding according to a specified
302/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
303///
304/// # shl_round
305/// ```
306/// use malachite_base::num::arithmetic::traits::ShlRound;
307/// use malachite_base::num::basic::traits::Zero;
308/// use malachite_base::rounding_modes::RoundingMode::*;
309/// use malachite_base::strings::ToDebugString;
310/// use malachite_nz::integer::Integer;
311///
312/// assert_eq!(
313/// Integer::from(0x101).shl_round(-8i8, Down).to_debug_string(),
314/// "(1, Less)"
315/// );
316/// assert_eq!(
317/// Integer::from(0x101).shl_round(-8i16, Up).to_debug_string(),
318/// "(2, Greater)"
319/// );
320///
321/// assert_eq!(
322/// Integer::from(-0x101)
323/// .shl_round(-9i32, Down)
324/// .to_debug_string(),
325/// "(0, Greater)"
326/// );
327/// assert_eq!(
328/// Integer::from(-0x101).shl_round(-9i64, Up).to_debug_string(),
329/// "(-1, Less)"
330/// );
331/// assert_eq!(
332/// Integer::from(-0x101)
333/// .shl_round(-9i8, Nearest)
334/// .to_debug_string(),
335/// "(-1, Less)"
336/// );
337/// assert_eq!(
338/// Integer::from(-0xff)
339/// .shl_round(-9i16, Nearest)
340/// .to_debug_string(),
341/// "(0, Greater)"
342/// );
343/// assert_eq!(
344/// Integer::from(-0x100)
345/// .shl_round(-9i32, Nearest)
346/// .to_debug_string(),
347/// "(0, Greater)"
348/// );
349///
350/// assert_eq!(
351/// Integer::from(0x100)
352/// .shl_round(-8i64, Exact)
353/// .to_debug_string(),
354/// "(1, Equal)"
355/// );
356///
357/// assert_eq!(
358/// Integer::ZERO.shl_round(10i8, Exact).to_debug_string(),
359/// "(0, Equal)"
360/// );
361/// assert_eq!(
362/// Integer::from(123u32)
363/// .shl_round(2i16, Exact)
364/// .to_debug_string(),
365/// "(492, Equal)"
366/// );
367/// assert_eq!(
368/// Integer::from(123u32)
369/// .shl_round(100i32, Exact)
370/// .to_debug_string(),
371/// "(155921023828072216384094494261248, Equal)"
372/// );
373///
374/// assert_eq!(
375/// (&Integer::from(0x101))
376/// .shl_round(-8i8, Down)
377/// .to_debug_string(),
378/// "(1, Less)"
379/// );
380/// assert_eq!(
381/// (&Integer::from(0x101))
382/// .shl_round(-8i16, Up)
383/// .to_debug_string(),
384/// "(2, Greater)"
385/// );
386///
387/// assert_eq!(
388/// (&Integer::from(-0x101))
389/// .shl_round(-9i32, Down)
390/// .to_debug_string(),
391/// "(0, Greater)"
392/// );
393/// assert_eq!(
394/// (&Integer::from(-0x101))
395/// .shl_round(-9i64, Up)
396/// .to_debug_string(),
397/// "(-1, Less)"
398/// );
399/// assert_eq!(
400/// (&Integer::from(-0x101))
401/// .shl_round(-9i8, Nearest)
402/// .to_debug_string(),
403/// "(-1, Less)"
404/// );
405/// assert_eq!(
406/// (&Integer::from(-0xff))
407/// .shl_round(-9i16, Nearest)
408/// .to_debug_string(),
409/// "(0, Greater)"
410/// );
411/// assert_eq!(
412/// (&Integer::from(-0x100))
413/// .shl_round(-9i32, Nearest)
414/// .to_debug_string(),
415/// "(0, Greater)"
416/// );
417///
418/// assert_eq!(
419/// (&Integer::from(0x100))
420/// .shl_round(-8i64, Exact)
421/// .to_debug_string(),
422/// "(1, Equal)"
423/// );
424///
425/// assert_eq!(
426/// (&Integer::ZERO).shl_round(10i8, Exact).to_debug_string(),
427/// "(0, Equal)"
428/// );
429/// assert_eq!(
430/// (&Integer::from(123u32))
431/// .shl_round(2i16, Exact)
432/// .to_debug_string(),
433/// "(492, Equal)"
434/// );
435/// assert_eq!(
436/// (&Integer::from(123u32))
437/// .shl_round(100i32, Exact)
438/// .to_debug_string(),
439/// "(155921023828072216384094494261248, Equal)"
440/// );
441/// ```
442///
443/// # shl_round_assign
444/// ```
445/// use core::cmp::Ordering::*;
446/// use malachite_base::num::arithmetic::traits::ShlRoundAssign;
447/// use malachite_base::num::basic::traits::One;
448/// use malachite_base::rounding_modes::RoundingMode::*;
449/// use malachite_nz::integer::Integer;
450///
451/// let mut n = Integer::from(0x101);
452/// assert_eq!(n.shl_round_assign(-8i8, Down), Less);
453/// assert_eq!(n, 1);
454///
455/// let mut n = Integer::from(0x101);
456/// assert_eq!(n.shl_round_assign(-8i16, Up), Greater);
457/// assert_eq!(n, 2);
458///
459/// let mut n = Integer::from(-0x101);
460/// assert_eq!(n.shl_round_assign(-9i32, Down), Greater);
461/// assert_eq!(n, 0);
462///
463/// let mut n = Integer::from(-0x101);
464/// assert_eq!(n.shl_round_assign(-9i64, Up), Less);
465/// assert_eq!(n, -1);
466///
467/// let mut n = Integer::from(-0x101);
468/// assert_eq!(n.shl_round_assign(-9i8, Nearest), Less);
469/// assert_eq!(n, -1);
470///
471/// let mut n = Integer::from(-0xff);
472/// assert_eq!(n.shl_round_assign(-9i16, Nearest), Greater);
473/// assert_eq!(n, 0);
474///
475/// let mut n = Integer::from(-0x100);
476/// assert_eq!(n.shl_round_assign(-9i32, Nearest), Greater);
477/// assert_eq!(n, 0);
478///
479/// let mut n = Integer::from(0x100);
480/// assert_eq!(n.shl_round_assign(-8i64, Exact), Equal);
481/// assert_eq!(n, 1);
482///
483/// let mut x = Integer::ONE;
484/// assert_eq!(x.shl_round_assign(1i8, Exact), Equal);
485/// assert_eq!(x.shl_round_assign(2i16, Exact), Equal);
486/// assert_eq!(x.shl_round_assign(3i32, Exact), Equal);
487/// assert_eq!(x.shl_round_assign(4i64, Exact), Equal);
488/// assert_eq!(x, 1024);
489/// ```
490pub mod shl_round;
491/// Right-shifting an [`Integer`](super::Integer) (dividing it by a power of 2).
492///
493/// # shr
494/// ```
495/// use malachite_base::num::arithmetic::traits::Pow;
496/// use malachite_base::num::basic::traits::Zero;
497/// use malachite_nz::integer::Integer;
498///
499/// assert_eq!(Integer::ZERO >> 10u8, 0);
500/// assert_eq!(Integer::from(492) >> 2u16, 123);
501/// assert_eq!(-Integer::from(10u32).pow(12) >> 10u64, -976562500);
502/// assert_eq!(&Integer::ZERO >> 10u8, 0);
503/// assert_eq!(&Integer::from(492) >> 2u16, 123);
504/// assert_eq!(&-Integer::from(10u32).pow(12) >> 10u64, -976562500);
505///
506/// assert_eq!(Integer::ZERO >> 10i8, 0);
507/// assert_eq!(Integer::from(492) >> 2i16, 123);
508/// assert_eq!(-Integer::from(10u32).pow(12) >> 10i64, -976562500);
509/// assert_eq!(Integer::ZERO >> -10i8, 0);
510/// assert_eq!(Integer::from(123) >> -2i16, 492);
511/// assert_eq!(
512/// (Integer::from(123) >> -100i32).to_string(),
513/// "155921023828072216384094494261248"
514/// );
515/// assert_eq!(Integer::from(-123) >> -2i64, -492);
516/// assert_eq!(
517/// (Integer::from(-123) >> -100i8).to_string(),
518/// "-155921023828072216384094494261248"
519/// );
520/// assert_eq!(&Integer::ZERO >> 10i8, 0);
521/// assert_eq!(&Integer::from(492) >> 2i16, 123);
522/// assert_eq!(&-Integer::from(10u32).pow(12) >> 10i64, -976562500);
523/// assert_eq!(&Integer::ZERO >> -10i8, 0);
524/// assert_eq!(&Integer::from(123) >> -2i16, 492);
525/// assert_eq!(
526/// (&Integer::from(123) >> -100i32).to_string(),
527/// "155921023828072216384094494261248"
528/// );
529/// assert_eq!(&Integer::from(-123) >> -2i64, -492);
530/// assert_eq!(
531/// (&Integer::from(-123) >> -100i8).to_string(),
532/// "-155921023828072216384094494261248"
533/// );
534/// ```
535///
536/// # shr_assign
537/// ```
538/// use malachite_base::num::basic::traits::{NegativeOne, One};
539/// use malachite_nz::integer::Integer;
540///
541/// let mut x = Integer::from(1024);
542/// x >>= 1u8;
543/// x >>= 2u16;
544/// x >>= 3u64;
545/// x >>= 4u64;
546/// assert_eq!(x, 1);
547///
548/// let mut x = Integer::from(1024);
549/// x >>= 1i8;
550/// x >>= 2i16;
551/// x >>= 3i32;
552/// x >>= 4i64;
553/// assert_eq!(x, 1);
554///
555/// let mut x = Integer::ONE;
556/// x >>= -1i8;
557/// x >>= -2i16;
558/// x >>= -3i32;
559/// x >>= -4i64;
560/// assert_eq!(x, 1024);
561///
562/// let mut x = Integer::NEGATIVE_ONE;
563/// x >>= -1i8;
564/// x >>= -2i16;
565/// x >>= -3i32;
566/// x >>= -4i64;
567/// assert_eq!(x, -1024);
568/// ```
569pub mod shr;
570/// Implementations of [`ShrRound`](malachite_base::num::arithmetic::traits::ShrRound) and
571/// [`ShrRoundAssign`](malachite_base::num::arithmetic::traits::ShrRoundAssign), traits for dividing
572/// a number by a power of 2 and rounding according to a specified
573/// [`RoundingMode`](malachite_base::rounding_modes::RoundingMode).
574///
575/// # shr_round
576/// ```
577/// use malachite_base::num::arithmetic::traits::ShrRound;
578/// use malachite_base::num::basic::traits::Zero;
579/// use malachite_base::rounding_modes::RoundingMode::*;
580/// use malachite_base::strings::ToDebugString;
581/// use malachite_nz::integer::Integer;
582///
583/// assert_eq!(
584/// Integer::from(0x101).shr_round(8u8, Down).to_debug_string(),
585/// "(1, Less)"
586/// );
587/// assert_eq!(
588/// Integer::from(0x101).shr_round(8u16, Up).to_debug_string(),
589/// "(2, Greater)"
590/// );
591///
592/// assert_eq!(
593/// Integer::from(-0x101)
594/// .shr_round(9u32, Down)
595/// .to_debug_string(),
596/// "(0, Greater)"
597/// );
598/// assert_eq!(
599/// Integer::from(-0x101).shr_round(9u64, Up).to_debug_string(),
600/// "(-1, Less)"
601/// );
602/// assert_eq!(
603/// Integer::from(-0x101)
604/// .shr_round(9u8, Nearest)
605/// .to_debug_string(),
606/// "(-1, Less)"
607/// );
608/// assert_eq!(
609/// Integer::from(-0xff)
610/// .shr_round(9u16, Nearest)
611/// .to_debug_string(),
612/// "(0, Greater)"
613/// );
614/// assert_eq!(
615/// Integer::from(-0x100)
616/// .shr_round(9u64, Nearest)
617/// .to_debug_string(),
618/// "(0, Greater)"
619/// );
620///
621/// assert_eq!(
622/// Integer::from(0x100u32)
623/// .shr_round(8u32, Exact)
624/// .to_debug_string(),
625/// "(1, Equal)"
626/// );
627///
628/// assert_eq!(
629/// (&Integer::from(0x101))
630/// .shr_round(8u8, Down)
631/// .to_debug_string(),
632/// "(1, Less)"
633/// );
634/// assert_eq!(
635/// (&Integer::from(0x101))
636/// .shr_round(8u16, Up)
637/// .to_debug_string(),
638/// "(2, Greater)"
639/// );
640///
641/// assert_eq!(
642/// (&Integer::from(-0x101))
643/// .shr_round(9u32, Down)
644/// .to_debug_string(),
645/// "(0, Greater)"
646/// );
647/// assert_eq!(
648/// (&Integer::from(-0x101))
649/// .shr_round(9u64, Up)
650/// .to_debug_string(),
651/// "(-1, Less)"
652/// );
653/// assert_eq!(
654/// (&Integer::from(-0x101))
655/// .shr_round(9u8, Nearest)
656/// .to_debug_string(),
657/// "(-1, Less)"
658/// );
659/// assert_eq!(
660/// (&Integer::from(-0xff))
661/// .shr_round(9u16, Nearest)
662/// .to_debug_string(),
663/// "(0, Greater)"
664/// );
665/// assert_eq!(
666/// (&Integer::from(-0x100))
667/// .shr_round(9u64, Nearest)
668/// .to_debug_string(),
669/// "(0, Greater)"
670/// );
671///
672/// assert_eq!(
673/// (&Integer::from(0x100u32))
674/// .shr_round(8u32, Exact)
675/// .to_debug_string(),
676/// "(1, Equal)"
677/// );
678///
679/// assert_eq!(
680/// Integer::from(0x101u32)
681/// .shr_round(8i8, Down)
682/// .to_debug_string(),
683/// "(1, Less)"
684/// );
685/// assert_eq!(
686/// Integer::from(0x101u32)
687/// .shr_round(8i16, Up)
688/// .to_debug_string(),
689/// "(2, Greater)"
690/// );
691///
692/// assert_eq!(
693/// Integer::from(-0x101)
694/// .shr_round(9i32, Down)
695/// .to_debug_string(),
696/// "(0, Greater)"
697/// );
698/// assert_eq!(
699/// Integer::from(-0x101).shr_round(9i64, Up).to_debug_string(),
700/// "(-1, Less)"
701/// );
702/// assert_eq!(
703/// Integer::from(-0x101)
704/// .shr_round(9i8, Nearest)
705/// .to_debug_string(),
706/// "(-1, Less)"
707/// );
708/// assert_eq!(
709/// Integer::from(-0xff)
710/// .shr_round(9i16, Nearest)
711/// .to_debug_string(),
712/// "(0, Greater)"
713/// );
714/// assert_eq!(
715/// Integer::from(-0x100)
716/// .shr_round(9i32, Nearest)
717/// .to_debug_string(),
718/// "(0, Greater)"
719/// );
720///
721/// assert_eq!(
722/// Integer::from(0x100u32)
723/// .shr_round(8i64, Exact)
724/// .to_debug_string(),
725/// "(1, Equal)"
726/// );
727///
728/// assert_eq!(
729/// Integer::ZERO.shr_round(-10i8, Exact).to_debug_string(),
730/// "(0, Equal)"
731/// );
732/// assert_eq!(
733/// Integer::from(123u32)
734/// .shr_round(-2i16, Exact)
735/// .to_debug_string(),
736/// "(492, Equal)"
737/// );
738/// assert_eq!(
739/// Integer::from(123u32)
740/// .shr_round(-100i32, Exact)
741/// .to_debug_string(),
742/// "(155921023828072216384094494261248, Equal)"
743/// );
744///
745/// assert_eq!(
746/// (&Integer::from(0x101u32))
747/// .shr_round(8i8, Down)
748/// .to_debug_string(),
749/// "(1, Less)"
750/// );
751/// assert_eq!(
752/// (&Integer::from(0x101u32))
753/// .shr_round(8i16, Up)
754/// .to_debug_string(),
755/// "(2, Greater)"
756/// );
757///
758/// assert_eq!(
759/// (&Integer::from(-0x101))
760/// .shr_round(9i32, Down)
761/// .to_debug_string(),
762/// "(0, Greater)"
763/// );
764/// assert_eq!(
765/// (&Integer::from(-0x101))
766/// .shr_round(9i64, Up)
767/// .to_debug_string(),
768/// "(-1, Less)"
769/// );
770/// assert_eq!(
771/// (&Integer::from(-0x101))
772/// .shr_round(9i8, Nearest)
773/// .to_debug_string(),
774/// "(-1, Less)"
775/// );
776/// assert_eq!(
777/// (&Integer::from(-0xff))
778/// .shr_round(9i16, Nearest)
779/// .to_debug_string(),
780/// "(0, Greater)"
781/// );
782/// assert_eq!(
783/// (&Integer::from(-0x100))
784/// .shr_round(9i32, Nearest)
785/// .to_debug_string(),
786/// "(0, Greater)"
787/// );
788///
789/// assert_eq!(
790/// (&Integer::from(0x100u32))
791/// .shr_round(8i64, Exact)
792/// .to_debug_string(),
793/// "(1, Equal)"
794/// );
795///
796/// assert_eq!(
797/// (&Integer::ZERO).shr_round(-10i8, Exact).to_debug_string(),
798/// "(0, Equal)"
799/// );
800/// assert_eq!(
801/// (&Integer::from(123u32))
802/// .shr_round(-2i16, Exact)
803/// .to_debug_string(),
804/// "(492, Equal)"
805/// );
806/// assert_eq!(
807/// (&Integer::from(123u32))
808/// .shr_round(-100i32, Exact)
809/// .to_debug_string(),
810/// "(155921023828072216384094494261248, Equal)"
811/// );
812/// ```
813///
814/// # shr_round_assign
815/// ```
816/// use core::cmp::Ordering::*;
817/// use malachite_base::num::arithmetic::traits::ShrRoundAssign;
818/// use malachite_base::num::basic::traits::One;
819/// use malachite_base::rounding_modes::RoundingMode::*;
820/// use malachite_nz::integer::Integer;
821///
822/// let mut n = Integer::from(0x101);
823/// assert_eq!(n.shr_round_assign(8u8, Down), Less);
824/// assert_eq!(n, 1);
825///
826/// let mut n = Integer::from(0x101);
827/// assert_eq!(n.shr_round_assign(8u16, Up), Greater);
828/// assert_eq!(n, 2);
829///
830/// let mut n = Integer::from(-0x101);
831/// assert_eq!(n.shr_round_assign(9u32, Down), Greater);
832/// assert_eq!(n, 0);
833///
834/// let mut n = Integer::from(-0x101);
835/// assert_eq!(n.shr_round_assign(9u64, Up), Less);
836/// assert_eq!(n, -1);
837///
838/// let mut n = Integer::from(-0x101);
839/// assert_eq!(n.shr_round_assign(9u8, Nearest), Less);
840/// assert_eq!(n, -1);
841///
842/// let mut n = Integer::from(-0xff);
843/// assert_eq!(n.shr_round_assign(9u16, Nearest), Greater);
844/// assert_eq!(n, 0);
845///
846/// let mut n = Integer::from(-0x100);
847/// assert_eq!(n.shr_round_assign(9u32, Nearest), Greater);
848/// assert_eq!(n, 0);
849///
850/// let mut n = Integer::from(0x100);
851/// assert_eq!(n.shr_round_assign(8u64, Exact), Equal);
852/// assert_eq!(n, 1);
853///
854/// let mut n = Integer::from(0x101u32);
855/// assert_eq!(n.shr_round_assign(8i8, Down), Less);
856/// assert_eq!(n, 1);
857///
858/// let mut n = Integer::from(0x101u32);
859/// assert_eq!(n.shr_round_assign(8i16, Up), Greater);
860/// assert_eq!(n, 2);
861///
862/// let mut n = Integer::from(-0x101);
863/// assert_eq!(n.shr_round_assign(9i32, Down), Greater);
864/// assert_eq!(n, 0);
865///
866/// let mut n = Integer::from(-0x101);
867/// assert_eq!(n.shr_round_assign(9i64, Up), Less);
868/// assert_eq!(n, -1);
869///
870/// let mut n = Integer::from(-0x101);
871/// assert_eq!(n.shr_round_assign(9i8, Nearest), Less);
872/// assert_eq!(n, -1);
873///
874/// let mut n = Integer::from(-0xff);
875/// assert_eq!(n.shr_round_assign(9i16, Nearest), Greater);
876/// assert_eq!(n, 0);
877///
878/// let mut n = Integer::from(-0x100);
879/// assert_eq!(n.shr_round_assign(9i32, Nearest), Greater);
880/// assert_eq!(n, 0);
881///
882/// let mut n = Integer::from(0x100u32);
883/// assert_eq!(n.shr_round_assign(8i64, Exact), Equal);
884/// assert_eq!(n, 1);
885///
886/// let mut x = Integer::ONE;
887/// assert_eq!(x.shr_round_assign(-1i8, Exact), Equal);
888/// assert_eq!(x.shr_round_assign(-2i16, Exact), Equal);
889/// assert_eq!(x.shr_round_assign(-3i32, Exact), Equal);
890/// assert_eq!(x.shr_round_assign(-4i64, Exact), Equal);
891/// assert_eq!(x, 1024);
892/// ```
893pub mod shr_round;
894/// Implementations of [`Sign`](malachite_base::num::arithmetic::traits::Sign), a trait for
895/// determining the sign of a number.
896pub mod sign;
897/// Implementations of traits for taking the square root of a number.
898///
899/// The traits are [`FloorSqrt`](malachite_base::num::arithmetic::traits::FloorSqrt),
900/// [`FloorSqrtAssign`](malachite_base::num::arithmetic::traits::FloorSqrtAssign),
901/// [`CeilingSqrt`](malachite_base::num::arithmetic::traits::CeilingSqrt),
902/// [`CeilingSqrtAssign`](malachite_base::num::arithmetic::traits::CeilingSqrtAssign), and
903/// [`CheckedSqrt`](malachite_base::num::arithmetic::traits::CheckedSqrt).
904pub mod sqrt;
905/// Implementations of [`Square`](malachite_base::num::arithmetic::traits::Square) and
906/// [`SquareAssign`](malachite_base::num::arithmetic::traits::SquareAssign), traits for squaring a
907/// number.
908pub mod square;
909/// Subtraction of [`Integer`](super::Integer)s.
910pub mod sub;
911/// Implementations of [`SubMul`](malachite_base::num::arithmetic::traits::SubMul) and
912/// [`SubMulAssign`](malachite_base::num::arithmetic::traits::SubMulAssign), traits for subtracting
913/// the product of two numbers from a number.
914pub mod sub_mul;