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