Skip to main content

malachite_base/num/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/// [`Abs`](traits::Abs), [`AbsAssign`](traits::AbsAssign), and
10/// [`UnsignedAbs`](traits::UnsignedAbs), traits for getting the absolute value of a number.
11///
12/// # abs_assign
13/// ```
14/// use malachite_base::num::arithmetic::traits::AbsAssign;
15/// use malachite_base::num::basic::traits::NegativeInfinity;
16/// use malachite_base::num::float::NiceFloat;
17///
18/// let mut x = 0i8;
19/// x.abs_assign();
20/// assert_eq!(x, 0i8);
21///
22/// let mut x = 100i64;
23/// x.abs_assign();
24/// assert_eq!(x, 100i64);
25///
26/// let mut x = -100i64;
27/// x.abs_assign();
28/// assert_eq!(x, 100i64);
29///
30/// let mut x = -0.0;
31/// x.abs_assign();
32/// assert_eq!(NiceFloat(x), NiceFloat(0.0));
33///
34/// let mut x = f64::NEGATIVE_INFINITY;
35/// x.abs_assign();
36/// assert_eq!(NiceFloat(x), NiceFloat(f64::INFINITY));
37///
38/// let mut x = 100.0;
39/// x.abs_assign();
40/// assert_eq!(NiceFloat(x), NiceFloat(100.0));
41///
42/// let mut x = -100.0;
43/// x.abs_assign();
44/// assert_eq!(NiceFloat(x), NiceFloat(100.0));
45/// ```
46pub mod abs;
47/// [`AbsDiff`](traits::AbsDiff) and [`AbsDiffAssign`](traits::AbsDiffAssign), traits for getting
48/// the absolute value of the difference between two numbers.
49///
50/// # abs_diff
51/// ```
52/// assert_eq!(10u8.abs_diff(20u8), 10u8);
53/// assert_eq!(10i8.abs_diff(-10i8), 20u8);
54/// ```
55///
56/// # abs_diff_assign
57/// ```
58/// use malachite_base::num::arithmetic::traits::AbsDiffAssign;
59///
60/// let mut x = 10u8;
61/// x.abs_diff_assign(20u8);
62/// assert_eq!(x, 10);
63/// ```
64pub mod abs_diff;
65/// [`AddMul`](traits::AddMul) and [`AddMulAssign`](traits::AddMulAssign), traits for adding a
66/// number and the product of two other numbers.
67///
68/// # add_mul
69/// ```
70/// use malachite_base::num::arithmetic::traits::AddMul;
71///
72/// assert_eq!(2u8.add_mul(3, 7), 23);
73/// assert_eq!(127i8.add_mul(-2, 100), -73);
74/// assert_eq!(1.0f32.add_mul(2.0, 3.0), 7.0);
75/// ```
76///
77/// # add_mul_assign
78/// ```
79/// use malachite_base::num::arithmetic::traits::AddMulAssign;
80///
81/// let mut x = 2u8;
82/// x.add_mul_assign(3, 7);
83/// assert_eq!(x, 23);
84///
85/// let mut x = 127i8;
86/// x.add_mul_assign(-2, 100);
87/// assert_eq!(x, -73);
88///
89/// let mut x = 1.0f32;
90/// x.add_mul_assign(2.0, 3.0);
91/// assert_eq!(x, 7.0);
92/// ```
93pub mod add_mul;
94/// [`ArithmeticCheckedShl`](traits::ArithmeticCheckedShl), a trait for left-shifting a number and
95/// checking whether the result is representable.
96///
97/// # arithmetic_checked_shl
98/// ```
99/// use malachite_base::num::arithmetic::traits::ArithmeticCheckedShl;
100///
101/// assert_eq!(3u8.arithmetic_checked_shl(6), Some(192u8));
102/// assert_eq!(3u8.arithmetic_checked_shl(7), None);
103/// assert_eq!(3u8.arithmetic_checked_shl(100), None);
104/// assert_eq!(0u8.arithmetic_checked_shl(100), Some(0u8));
105///
106/// assert_eq!(3u8.arithmetic_checked_shl(6), Some(192u8));
107/// assert_eq!(3u8.arithmetic_checked_shl(7), None);
108/// assert_eq!(3u8.arithmetic_checked_shl(100), None);
109/// assert_eq!(0u8.arithmetic_checked_shl(100), Some(0u8));
110/// assert_eq!(100u8.arithmetic_checked_shl(-3), Some(12u8));
111/// assert_eq!(100u8.arithmetic_checked_shl(-100), Some(0u8));
112///
113/// assert_eq!(3i8.arithmetic_checked_shl(5), Some(96i8));
114/// assert_eq!(3i8.arithmetic_checked_shl(6), None);
115/// assert_eq!((-3i8).arithmetic_checked_shl(5), Some(-96i8));
116/// assert_eq!((-3i8).arithmetic_checked_shl(6), None);
117/// assert_eq!(3i8.arithmetic_checked_shl(100), None);
118/// assert_eq!((-3i8).arithmetic_checked_shl(100), None);
119/// assert_eq!(0i8.arithmetic_checked_shl(100), Some(0i8));
120///
121/// assert_eq!(3i8.arithmetic_checked_shl(5), Some(96i8));
122/// assert_eq!(3i8.arithmetic_checked_shl(6), None);
123/// assert_eq!((-3i8).arithmetic_checked_shl(5), Some(-96i8));
124/// assert_eq!((-3i8).arithmetic_checked_shl(6), None);
125/// assert_eq!(3i8.arithmetic_checked_shl(100), None);
126/// assert_eq!((-3i8).arithmetic_checked_shl(100), None);
127/// assert_eq!(0i8.arithmetic_checked_shl(100), Some(0i8));
128/// assert_eq!(100i8.arithmetic_checked_shl(-3), Some(12i8));
129/// assert_eq!((-100i8).arithmetic_checked_shl(-3), Some(-13i8));
130/// assert_eq!(100i8.arithmetic_checked_shl(-100), Some(0i8));
131/// assert_eq!((-100i8).arithmetic_checked_shl(-100), Some(-1i8));
132/// ```
133pub mod arithmetic_checked_shl;
134/// [`ArithmeticCheckedShr`](traits::ArithmeticCheckedShr), a trait for right-shifting a number and
135/// checking whether the result is representable.
136///
137/// # arithmetic_checked_shr
138/// ```
139/// use malachite_base::num::arithmetic::traits::ArithmeticCheckedShr;
140///
141/// assert_eq!(100u8.arithmetic_checked_shr(3), Some(12u8));
142/// assert_eq!(100u8.arithmetic_checked_shr(100), Some(0u8));
143/// assert_eq!(3u8.arithmetic_checked_shr(-6), Some(192u8));
144/// assert_eq!(3u8.arithmetic_checked_shr(-7), None);
145/// assert_eq!(3u8.arithmetic_checked_shr(-100), None);
146/// assert_eq!(0u8.arithmetic_checked_shr(-100), Some(0u8));
147///
148/// assert_eq!(100i8.arithmetic_checked_shr(3), Some(12i8));
149/// assert_eq!((-100i8).arithmetic_checked_shr(3), Some(-13i8));
150/// assert_eq!(100i8.arithmetic_checked_shr(100), Some(0i8));
151/// assert_eq!((-100i8).arithmetic_checked_shr(100), Some(-1i8));
152/// assert_eq!(3i8.arithmetic_checked_shr(-5), Some(96i8));
153/// assert_eq!(3i8.arithmetic_checked_shr(-6), None);
154/// assert_eq!((-3i8).arithmetic_checked_shr(-5), Some(-96i8));
155/// assert_eq!((-3i8).arithmetic_checked_shr(-6), None);
156/// assert_eq!(3i8.arithmetic_checked_shr(-100), None);
157/// assert_eq!((-3i8).arithmetic_checked_shr(-100), None);
158/// assert_eq!(0i8.arithmetic_checked_shr(-100), Some(0i8));
159/// ```
160pub mod arithmetic_checked_shr;
161/// Traits for computing the binomial coefficient of two numbers. There is a trait whose
162/// implementations panic if the result cannot be represented, and a checked trait whose
163/// implementations return `None` in that case: [`BinomialCoefficient`](traits::BinomialCoefficient)
164/// and [`CheckedBinomialCoefficient`](traits::CheckedBinomialCoefficient).
165///
166/// # binomial_coefficient
167/// ```
168/// use malachite_base::num::arithmetic::traits::BinomialCoefficient;
169///
170/// assert_eq!(u8::binomial_coefficient(3, 0), 1);
171/// assert_eq!(u8::binomial_coefficient(3, 1), 3);
172/// assert_eq!(u8::binomial_coefficient(3, 2), 3);
173/// assert_eq!(u8::binomial_coefficient(3, 3), 1);
174/// assert_eq!(u8::binomial_coefficient(10, 5), 252);
175///
176/// assert_eq!(i8::binomial_coefficient(-3, 0), 1);
177/// assert_eq!(i8::binomial_coefficient(-3, 1), -3);
178/// assert_eq!(i8::binomial_coefficient(-3, 2), 6);
179/// assert_eq!(i8::binomial_coefficient(-3, 3), -10);
180/// ```
181///
182/// # checked_binomial_coefficient
183/// ```
184/// use malachite_base::num::arithmetic::traits::CheckedBinomialCoefficient;
185///
186/// assert_eq!(u8::checked_binomial_coefficient(3, 0), Some(1));
187/// assert_eq!(u8::checked_binomial_coefficient(3, 1), Some(3));
188/// assert_eq!(u8::checked_binomial_coefficient(3, 2), Some(3));
189/// assert_eq!(u8::checked_binomial_coefficient(3, 3), Some(1));
190/// assert_eq!(u8::checked_binomial_coefficient(10, 5), Some(252));
191/// assert_eq!(u8::checked_binomial_coefficient(11, 5), None);
192///
193/// assert_eq!(i8::checked_binomial_coefficient(-3, 0), Some(1));
194/// assert_eq!(i8::checked_binomial_coefficient(-3, 1), Some(-3));
195/// assert_eq!(i8::checked_binomial_coefficient(-3, 2), Some(6));
196/// assert_eq!(i8::checked_binomial_coefficient(-3, 3), Some(-10));
197/// assert_eq!(i8::checked_binomial_coefficient(-3, -3), None);
198/// assert_eq!(i8::checked_binomial_coefficient(11, 5), None);
199/// ```
200pub mod binomial_coefficient;
201/// [`Ceiling`](traits::Ceiling) and [`CeilingAssign`](traits::CeilingAssign), traits for computing
202/// the ceiling of a number.
203///
204/// # ceiling
205/// ```
206/// use malachite_base::num::arithmetic::traits::CeilingAssign;
207///
208/// let mut x = 1.5f32;
209/// x.ceiling_assign();
210/// assert_eq!(x, 2.0);
211///
212/// let mut x = -1.5f32;
213/// x.ceiling_assign();
214/// assert_eq!(x, -1.0);
215/// ```
216pub mod ceiling;
217/// [`CheckedAbs`](traits::CheckedAbs), a trait for computing the absolute value of number and
218/// checking whether the result is representable.
219pub mod checked_abs;
220/// [`CheckedAdd`](traits::CheckedAdd), a trait for adding two numbers and checking whether the
221/// result is representable.
222pub mod checked_add;
223/// [`CheckedAddMul`](traits::CheckedAddMul), a trait for adding a number and the product of two
224/// other numbers, and checking whether the result is representable.
225///
226/// # checked_add_mul
227/// ```
228/// use malachite_base::num::arithmetic::traits::CheckedAddMul;
229///
230/// assert_eq!(2u8.checked_add_mul(3, 7), Some(23));
231/// assert_eq!(2u8.checked_add_mul(20, 20), None);
232///
233/// assert_eq!(127i8.checked_add_mul(-2, 100), Some(-73));
234/// assert_eq!((-127i8).checked_add_mul(-2, 100), None);
235/// ```
236pub mod checked_add_mul;
237/// [`CheckedDiv`](traits::CheckedDiv), a trait for dividing two numbers and checking whether the
238/// result is representable.
239pub mod checked_div;
240/// [`CheckedMul`](traits::CheckedMul), a trait for multiplying two numbers and checking whether the
241/// result is representable.
242pub mod checked_mul;
243/// [`CheckedNeg`](traits::CheckedNeg), a trait for negating a number and checking whether the
244/// result is representable.
245pub mod checked_neg;
246/// [`CheckedNextPowerOf2`](traits::CheckedNextPowerOf2), a trait for getting the next-highest power
247/// of 2, if it's representable.
248pub mod checked_next_power_of_2;
249/// [`CheckedPow`](traits::CheckedPow), a trait for raising a number to the power of a [`u64`] and
250/// checking whether the result is representable.
251pub mod checked_pow;
252/// [`CheckedSquare`](traits::CheckedSquare), a trait for squaring a number and checking whether the
253/// result is representable.
254///
255/// # checked_square
256/// ```
257/// use malachite_base::num::arithmetic::traits::CheckedSquare;
258///
259/// assert_eq!(3u8.checked_square(), Some(9));
260/// assert_eq!((-1000i32).checked_square(), Some(1000000));
261/// assert_eq!((1000u16).checked_square(), None);
262/// ```
263pub mod checked_square;
264/// [`CheckedSub`](traits::CheckedSub), a trait for subtracting two numbers and checking whether the
265/// result is representable.
266pub mod checked_sub;
267/// [`CheckedSubMul`](traits::CheckedSubMul), a trait for subtracting the product of two numbers
268/// from another number, and checking whether the result is representable.
269///
270/// # checked_sub_mul
271/// ```
272/// use malachite_base::num::arithmetic::traits::CheckedSubMul;
273///
274/// assert_eq!(60u8.checked_sub_mul(5, 10), Some(10));
275/// assert_eq!(2u8.checked_sub_mul(10, 5), None);
276///
277/// assert_eq!(127i8.checked_sub_mul(2, 100), Some(-73));
278/// assert_eq!((-127i8).checked_sub_mul(2, 100), None);
279/// ```
280pub mod checked_sub_mul;
281/// [`CoprimeWith`](traits::CoprimeWith), a trait for determining whether two numbers are coprime.
282///
283/// # coprime_with
284/// ```
285/// use malachite_base::num::arithmetic::traits::CoprimeWith;
286///
287/// assert_eq!(0u8.coprime_with(0), false);
288/// assert_eq!(0u8.coprime_with(1), true);
289/// assert_eq!(6u8.coprime_with(1), true);
290/// assert_eq!(3u8.coprime_with(5), true);
291/// assert_eq!(6u8.coprime_with(4), false);
292/// assert_eq!(6u8.coprime_with(35), true);
293/// ```
294pub mod coprime_with;
295/// [`DivExact`](traits::DivExact) and [`DivExactAssign`](traits::DivExactAssign), traits for
296/// dividing two numbers when it's known that the division is exact.
297///
298/// # div_exact
299/// ```
300/// use malachite_base::num::arithmetic::traits::DivExact;
301///
302/// // 123 * 456 = 56088
303/// #[allow(unstable_name_collisions)]
304/// {
305///     assert_eq!(56088u32.div_exact(456), 123);
306/// }
307///
308/// // -123 * -456 = 56088
309/// #[allow(unstable_name_collisions)]
310/// {
311///     assert_eq!(56088i64.div_exact(-456), -123);
312/// }
313/// ```
314///
315/// # div_exact_assign
316/// ```
317/// use malachite_base::num::arithmetic::traits::DivExactAssign;
318///
319/// // 123 * 456 = 56088
320/// let mut x = 56088u32;
321/// x.div_exact_assign(456);
322/// assert_eq!(x, 123);
323///
324/// // -123 * -456 = 56088
325/// let mut x = 56088i64;
326/// x.div_exact_assign(-456);
327/// assert_eq!(x, -123);
328/// ```
329pub mod div_exact;
330/// Traits for simultaneously finding the quotient and remainder of two numbers, subject to various
331/// rounding rules.
332///
333/// These are the traits:
334///
335/// | rounding     | by value or reference           | by mutable reference (assignment)      |
336/// |--------------|---------------------------------|----------------------------------------|
337/// | towards $-\infty$ | [`DivMod`](traits::DivMod) | [`DivAssignMod`](traits::DivAssignMod) |
338/// | towards 0         | [`DivRem`](traits::DivRem) | [`DivAssignRem`](traits::DivAssignRem) |
339/// | towards $\infty$  | [`CeilingDivMod`](traits::CeilingDivMod) | [`CeilingDivAssignMod`](traits::CeilingDivAssignMod) |
340/// | towards $\infty$  | [`CeilingDivNegMod`](traits::CeilingDivNegMod) | [`CeilingDivAssignNegMod`](traits::CeilingDivAssignNegMod) |
341///
342/// [`CeilingDivMod`](traits::CeilingDivMod) and [`CeilingDivNegMod`](traits::CeilingDivNegMod) are
343/// similar. The difference is that [`CeilingDivMod`](traits::CeilingDivMod) returns a remainder
344/// less than or equal to 0, so that the usual relation $x = qy + r$ is satisfied, while
345/// [`CeilingDivNegMod`](traits::CeilingDivNegMod) returns a remainder greater than or equal to
346/// zero. This allows the remainder to have an unsigned type, but modifies the relation to $x = qy
347/// - r$.
348///
349/// # div_mod
350/// ```
351/// use malachite_base::num::arithmetic::traits::DivMod;
352///
353/// // 2 * 10 + 3 = 23
354/// assert_eq!(23u8.div_mod(10), (2, 3));
355///
356/// // 9 * 5 + 0 = 45
357/// assert_eq!(45u32.div_mod(5), (9, 0));
358///
359/// // 2 * 10 + 3 = 23
360/// assert_eq!(23i8.div_mod(10), (2, 3));
361///
362/// // -3 * -10 + -7 = 23
363/// assert_eq!(23i16.div_mod(-10), (-3, -7));
364///
365/// // -3 * 10 + 7 = -23
366/// assert_eq!((-23i32).div_mod(10), (-3, 7));
367///
368/// // 2 * -10 + -3 = -23
369/// assert_eq!((-23i64).div_mod(-10), (2, -3));
370/// ```
371///
372/// # div_assign_mod
373/// ```
374/// use malachite_base::num::arithmetic::traits::DivAssignMod;
375///
376/// // 2 * 10 + 3 = 23
377/// let mut x = 23u8;
378/// assert_eq!(x.div_assign_mod(10), 3);
379/// assert_eq!(x, 2);
380///
381/// // 9 * 5 + 0 = 45
382/// let mut x = 45u32;
383/// assert_eq!(x.div_assign_mod(5), 0);
384/// assert_eq!(x, 9);
385///
386/// // 2 * 10 + 3 = 23
387/// let mut x = 23i8;
388/// assert_eq!(x.div_assign_mod(10), 3);
389/// assert_eq!(x, 2);
390///
391/// // -3 * -10 + -7 = 23
392/// let mut x = 23i16;
393/// assert_eq!(x.div_assign_mod(-10), -7);
394/// assert_eq!(x, -3);
395///
396/// // -3 * 10 + 7 = -23
397/// let mut x = -23i32;
398/// assert_eq!(x.div_assign_mod(10), 7);
399/// assert_eq!(x, -3);
400///
401/// // 2 * -10 + -3 = -23
402/// let mut x = -23i64;
403/// assert_eq!(x.div_assign_mod(-10), -3);
404/// assert_eq!(x, 2);
405/// ```
406///
407/// # div_rem
408/// ```
409/// use malachite_base::num::arithmetic::traits::DivRem;
410///
411/// // 2 * 10 + 3 = 23
412/// assert_eq!(23u8.div_rem(10), (2, 3));
413///
414/// // 9 * 5 + 0 = 45
415/// assert_eq!(45u32.div_rem(5), (9, 0));
416///
417/// // 2 * 10 + 3 = 23
418/// assert_eq!(23i8.div_rem(10), (2, 3));
419///
420/// // -2 * -10 + 3 = 23
421/// assert_eq!(23i16.div_rem(-10), (-2, 3));
422///
423/// // -2 * 10 + -3 = -23
424/// assert_eq!((-23i32).div_rem(10), (-2, -3));
425///
426/// // 2 * -10 + -3 = -23
427/// assert_eq!((-23i64).div_rem(-10), (2, -3));
428/// ```
429///
430/// # div_assign_rem
431/// ```
432/// use malachite_base::num::arithmetic::traits::DivAssignRem;
433///
434/// // 2 * 10 + 3 = 23
435/// let mut x = 23u8;
436/// assert_eq!(x.div_assign_rem(10), 3);
437/// assert_eq!(x, 2);
438///
439/// // 9 * 5 + 0 = 45
440/// let mut x = 45u32;
441/// assert_eq!(x.div_assign_rem(5), 0);
442/// assert_eq!(x, 9);
443///
444/// // 2 * 10 + 3 = 23
445/// let mut x = 23i8;
446/// assert_eq!(x.div_assign_rem(10), 3);
447/// assert_eq!(x, 2);
448///
449/// // -2 * -10 + 3 = 23
450/// let mut x = 23i16;
451/// assert_eq!(x.div_assign_rem(-10), 3);
452/// assert_eq!(x, -2);
453///
454/// // -2 * 10 + -3 = -23
455/// let mut x = -23i32;
456/// assert_eq!(x.div_assign_rem(10), -3);
457/// assert_eq!(x, -2);
458///
459/// // 2 * -10 + -3 = -23
460/// let mut x = -23i64;
461/// assert_eq!(x.div_assign_rem(-10), -3);
462/// assert_eq!(x, 2);
463/// ```
464///
465/// # ceiling_div_neg_mod
466/// ```
467/// use malachite_base::num::arithmetic::traits::CeilingDivNegMod;
468///
469/// // 3 * 10 - 7 = 23
470/// assert_eq!(23u8.ceiling_div_neg_mod(10), (3, 7));
471///
472/// // 9 * 5 + 0 = 45
473/// assert_eq!(45u32.ceiling_div_neg_mod(5), (9, 0));
474/// ```
475///
476/// # ceiling_div_assign_neg_mod
477/// ```
478/// use malachite_base::num::arithmetic::traits::CeilingDivAssignNegMod;
479///
480/// // 3 * 10 - 7 = 23
481/// let mut x = 23u8;
482/// assert_eq!(x.ceiling_div_assign_neg_mod(10), 7);
483/// assert_eq!(x, 3);
484///
485/// // 9 * 5 + 0 = 45
486/// let mut x = 45u32;
487/// assert_eq!(x.ceiling_div_assign_neg_mod(5), 0);
488/// assert_eq!(x, 9);
489/// ```
490///
491/// # ceiling_div_mod
492/// ```
493/// use malachite_base::num::arithmetic::traits::CeilingDivMod;
494///
495/// // 3 * 10 + -7 = 23
496/// assert_eq!(23i8.ceiling_div_mod(10), (3, -7));
497///
498/// // -2 * -10 + 3 = 23
499/// assert_eq!(23i16.ceiling_div_mod(-10), (-2, 3));
500///
501/// // -2 * 10 + -3 = -23
502/// assert_eq!((-23i32).ceiling_div_mod(10), (-2, -3));
503///
504/// // 3 * -10 + 7 = -23
505/// assert_eq!((-23i64).ceiling_div_mod(-10), (3, 7));
506/// ```
507///
508/// # ceiling_div_assign_mod
509/// ```
510/// use malachite_base::num::arithmetic::traits::CeilingDivAssignMod;
511///
512/// // 3 * 10 + -7 = 23
513/// let mut x = 23i8;
514/// assert_eq!(x.ceiling_div_assign_mod(10), -7);
515/// assert_eq!(x, 3);
516///
517/// // -2 * -10 + 3 = 23
518/// let mut x = 23i16;
519/// assert_eq!(x.ceiling_div_assign_mod(-10), 3);
520/// assert_eq!(x, -2);
521///
522/// // -2 * 10 + -3 = -23
523/// let mut x = -23i32;
524/// assert_eq!(x.ceiling_div_assign_mod(10), -3);
525/// assert_eq!(x, -2);
526///
527/// // 3 * -10 + 7 = -23
528/// let mut x = -23i64;
529/// assert_eq!(x.ceiling_div_assign_mod(-10), 7);
530/// assert_eq!(x, 3);
531/// ```
532pub mod div_mod;
533/// [`DivRound`](traits::DivRound) and [`DivExactAssign`](traits::DivRoundAssign), traits for
534/// dividing two numbers according to a specified
535/// [`RoundingMode`](crate::rounding_modes::RoundingMode).
536///
537/// # div_round
538/// ```
539/// use malachite_base::num::arithmetic::traits::DivRound;
540/// use malachite_base::rounding_modes::RoundingMode::*;
541/// use std::cmp::Ordering::*;
542///
543/// assert_eq!(10u8.div_round(4, Down), (2, Less));
544/// assert_eq!(10u16.div_round(4, Up), (3, Greater));
545/// assert_eq!(10u32.div_round(5, Exact), (2, Equal));
546/// assert_eq!(10u64.div_round(3, Nearest), (3, Less));
547/// assert_eq!(20u128.div_round(3, Nearest), (7, Greater));
548/// assert_eq!(10usize.div_round(4, Nearest), (2, Less));
549/// assert_eq!(14u8.div_round(4, Nearest), (4, Greater));
550///
551/// assert_eq!((-10i8).div_round(4, Down), (-2, Greater));
552/// assert_eq!((-10i16).div_round(4, Up), (-3, Less));
553/// assert_eq!((-10i32).div_round(5, Exact), (-2, Equal));
554/// assert_eq!((-10i64).div_round(3, Nearest), (-3, Greater));
555/// assert_eq!((-20i128).div_round(3, Nearest), (-7, Less));
556/// assert_eq!((-10isize).div_round(4, Nearest), (-2, Greater));
557/// assert_eq!((-14i8).div_round(4, Nearest), (-4, Less));
558///
559/// assert_eq!((-10i16).div_round(-4, Down), (2, Less));
560/// assert_eq!((-10i32).div_round(-4, Up), (3, Greater));
561/// assert_eq!((-10i64).div_round(-5, Exact), (2, Equal));
562/// assert_eq!((-10i128).div_round(-3, Nearest), (3, Less));
563/// assert_eq!((-20isize).div_round(-3, Nearest), (7, Greater));
564/// assert_eq!((-10i8).div_round(-4, Nearest), (2, Less));
565/// assert_eq!((-14i16).div_round(-4, Nearest), (4, Greater));
566/// ```
567///
568/// # div_round_assign
569/// ```
570/// use malachite_base::num::arithmetic::traits::DivRoundAssign;
571/// use malachite_base::rounding_modes::RoundingMode::*;
572/// use std::cmp::Ordering::*;
573///
574/// let mut x = 10u8;
575/// assert_eq!(x.div_round_assign(4, Down), Less);
576/// assert_eq!(x, 2);
577///
578/// let mut x = 10u16;
579/// assert_eq!(x.div_round_assign(4, Up), Greater);
580/// assert_eq!(x, 3);
581///
582/// let mut x = 10u32;
583/// assert_eq!(x.div_round_assign(5, Exact), Equal);
584/// assert_eq!(x, 2);
585///
586/// let mut x = 10u64;
587/// assert_eq!(x.div_round_assign(3, Nearest), Less);
588/// assert_eq!(x, 3);
589///
590/// let mut x = 20u128;
591/// assert_eq!(x.div_round_assign(3, Nearest), Greater);
592/// assert_eq!(x, 7);
593///
594/// let mut x = 10usize;
595/// assert_eq!(x.div_round_assign(4, Nearest), Less);
596/// assert_eq!(x, 2);
597///
598/// let mut x = 14u8;
599/// assert_eq!(x.div_round_assign(4, Nearest), Greater);
600/// assert_eq!(x, 4);
601///
602/// let mut x = -10i8;
603/// assert_eq!(x.div_round_assign(4, Down), Greater);
604/// assert_eq!(x, -2);
605///
606/// let mut x = -10i16;
607/// assert_eq!(x.div_round_assign(4, Up), Less);
608/// assert_eq!(x, -3);
609///
610/// let mut x = -10i32;
611/// assert_eq!(x.div_round_assign(5, Exact), Equal);
612/// assert_eq!(x, -2);
613///
614/// let mut x = -10i64;
615/// assert_eq!(x.div_round_assign(3, Nearest), Greater);
616/// assert_eq!(x, -3);
617///
618/// let mut x = -20i128;
619/// assert_eq!(x.div_round_assign(3, Nearest), Less);
620/// assert_eq!(x, -7);
621///
622/// let mut x = -10isize;
623/// assert_eq!(x.div_round_assign(4, Nearest), Greater);
624/// assert_eq!(x, -2);
625///
626/// let mut x = -14i8;
627/// assert_eq!(x.div_round_assign(4, Nearest), Less);
628/// assert_eq!(x, -4);
629///
630/// let mut x = -10i16;
631/// assert_eq!(x.div_round_assign(-4, Down), Less);
632/// assert_eq!(x, 2);
633///
634/// let mut x = -10i32;
635/// assert_eq!(x.div_round_assign(-4, Up), Greater);
636/// assert_eq!(x, 3);
637///
638/// let mut x = -10i64;
639/// assert_eq!(x.div_round_assign(-5, Exact), Equal);
640/// assert_eq!(x, 2);
641///
642/// let mut x = -10i128;
643/// assert_eq!(x.div_round_assign(-3, Nearest), Less);
644/// assert_eq!(x, 3);
645///
646/// let mut x = -20isize;
647/// assert_eq!(x.div_round_assign(-3, Nearest), Greater);
648/// assert_eq!(x, 7);
649///
650/// let mut x = -10i8;
651/// assert_eq!(x.div_round_assign(-4, Nearest), Less);
652/// assert_eq!(x, 2);
653///
654/// let mut x = -14i16;
655/// assert_eq!(x.div_round_assign(-4, Nearest), Greater);
656/// assert_eq!(x, 4);
657/// ```
658pub mod div_round;
659/// [`DivisibleBy`](traits::DivisibleBy), a trait for determining whether one number is divisible by
660/// another.
661///
662/// # divisible_by
663/// ```
664/// use malachite_base::num::arithmetic::traits::DivisibleBy;
665///
666/// assert_eq!(0u8.divisible_by(0), true);
667/// assert_eq!(100u16.divisible_by(3), false);
668/// assert_eq!(102u32.divisible_by(3), true);
669///
670/// assert_eq!(0i8.divisible_by(0), true);
671/// assert_eq!((-100i16).divisible_by(-3), false);
672/// assert_eq!(102i32.divisible_by(-3), true);
673/// ```
674pub mod divisible_by;
675/// [`DivisibleByPowerOf2`](traits::DivisibleByPowerOf2), a trait for determining whether a number
676/// is divisible by $2^k$.
677///
678/// # divisible_by_power_of_2
679/// ```
680/// use malachite_base::num::arithmetic::traits::DivisibleByPowerOf2;
681///
682/// assert_eq!(0u8.divisible_by_power_of_2(100), true);
683/// assert_eq!(96u16.divisible_by_power_of_2(5), true);
684/// assert_eq!(96u32.divisible_by_power_of_2(6), false);
685///
686/// assert_eq!(0i8.divisible_by_power_of_2(100), true);
687/// assert_eq!((-96i16).divisible_by_power_of_2(5), true);
688/// assert_eq!(96i32.divisible_by_power_of_2(6), false);
689/// ```
690pub mod divisible_by_power_of_2;
691/// [`EqMod`](traits::EqMod), a trait for determining whether one number is equal by another modulo
692/// a third.
693///
694/// # eq_mod
695/// ```
696/// use malachite_base::num::arithmetic::traits::EqMod;
697///
698/// assert_eq!(123u16.eq_mod(223, 100), true);
699/// assert_eq!((-123i32).eq_mod(277, 100), true);
700/// assert_eq!((-123i64).eq_mod(278, 100), false);
701/// ```
702pub mod eq_mod;
703/// [`EqModPowerOf2`](traits::EqModPowerOf2), a trait for determining whether one number is equal to
704/// another modulo $2^k$.
705///
706/// # eq_mod_power_of_2
707/// ```
708/// use malachite_base::num::arithmetic::traits::EqModPowerOf2;
709///
710/// assert_eq!(0u16.eq_mod_power_of_2(256, 8), true);
711/// assert_eq!((-0b1101i32).eq_mod_power_of_2(0b11011, 3), true);
712/// assert_eq!((-0b1101i64).eq_mod_power_of_2(0b11011, 4), false);
713/// ```
714pub mod eq_mod_power_of_2;
715/// [`ExtendedGcd`](traits::ExtendedGcd), a trait for computing the GCD (greatest common divisor) of
716/// two numbers as well as the coefficients of Bézout's identity $ax+by=\gcd(a,b)$.
717///
718/// # extended_gcd
719/// ```
720/// use malachite_base::num::arithmetic::traits::ExtendedGcd;
721///
722/// assert_eq!(3u8.extended_gcd(5), (1, 2, -1));
723/// assert_eq!(240u16.extended_gcd(46), (2, -9, 47));
724/// assert_eq!((-111i16).extended_gcd(300), (3, 27, 10));
725/// ```
726pub mod extended_gcd;
727/// Traits for computing the factorial, double factorial, multifactorial, and subfactorial. Each
728/// function has a trait whose implementations panic if the result cannot be represented, and a
729/// checked trait whose implementations return `None` in that case. The traits are
730/// [`Factorial`](traits::Factorial), [`DoubleFactorial`](traits::DoubleFactorial),
731/// [`Multifactorial`](traits::Multifactorial), [`Subfactorial`](traits::Subfactorial),
732/// [`CheckedFactorial`](traits::CheckedFactorial),
733/// [`CheckedDoubleFactorial`](traits::CheckedDoubleFactorial),
734/// [`CheckedMultifactorial`](traits::CheckedMultifactorial), and
735/// [`CheckedSubfactorial`](traits::CheckedSubfactorial).
736///
737/// # factorial
738/// ```
739/// use malachite_base::num::arithmetic::traits::Factorial;
740///
741/// assert_eq!(u8::factorial(0), 1);
742/// assert_eq!(u8::factorial(1), 1);
743/// assert_eq!(u8::factorial(2), 2);
744/// assert_eq!(u8::factorial(3), 6);
745/// assert_eq!(u8::factorial(4), 24);
746/// assert_eq!(u8::factorial(5), 120);
747/// assert_eq!(u32::factorial(10), 3628800);
748/// ```
749///
750/// # checked_factorial
751/// ```
752/// use malachite_base::num::arithmetic::traits::CheckedFactorial;
753///
754/// assert_eq!(u8::checked_factorial(0), Some(1));
755/// assert_eq!(u8::checked_factorial(1), Some(1));
756/// assert_eq!(u8::checked_factorial(2), Some(2));
757/// assert_eq!(u8::checked_factorial(3), Some(6));
758/// assert_eq!(u8::checked_factorial(4), Some(24));
759/// assert_eq!(u8::checked_factorial(5), Some(120));
760/// assert_eq!(u8::checked_factorial(6), None);
761/// assert_eq!(u32::checked_factorial(10), Some(3628800));
762/// assert_eq!(u32::checked_factorial(100), None);
763/// ```
764///
765/// # double_factorial
766/// ```
767/// use malachite_base::num::arithmetic::traits::DoubleFactorial;
768///
769/// assert_eq!(u8::double_factorial(0), 1);
770/// assert_eq!(u8::double_factorial(1), 1);
771/// assert_eq!(u8::double_factorial(2), 2);
772/// assert_eq!(u8::double_factorial(3), 3);
773/// assert_eq!(u8::double_factorial(4), 8);
774/// assert_eq!(u8::double_factorial(5), 15);
775/// assert_eq!(u8::double_factorial(6), 48);
776/// assert_eq!(u8::double_factorial(7), 105);
777/// assert_eq!(u32::double_factorial(19), 654729075);
778/// assert_eq!(u32::double_factorial(20), 3715891200);
779/// ```
780///
781/// # checked_double_factorial
782/// ```
783/// use malachite_base::num::arithmetic::traits::CheckedDoubleFactorial;
784///
785/// assert_eq!(u8::checked_double_factorial(0), Some(1));
786/// assert_eq!(u8::checked_double_factorial(1), Some(1));
787/// assert_eq!(u8::checked_double_factorial(2), Some(2));
788/// assert_eq!(u8::checked_double_factorial(3), Some(3));
789/// assert_eq!(u8::checked_double_factorial(4), Some(8));
790/// assert_eq!(u8::checked_double_factorial(5), Some(15));
791/// assert_eq!(u8::checked_double_factorial(6), Some(48));
792/// assert_eq!(u8::checked_double_factorial(7), Some(105));
793/// assert_eq!(u8::checked_double_factorial(8), None);
794/// assert_eq!(u32::checked_double_factorial(19), Some(654729075));
795/// assert_eq!(u32::checked_double_factorial(20), Some(3715891200));
796/// assert_eq!(u32::checked_double_factorial(100), None);
797/// ```
798///
799/// # multifactorial
800/// ```
801/// use malachite_base::num::arithmetic::traits::Multifactorial;
802///
803/// assert_eq!(u8::multifactorial(0, 1), 1);
804/// assert_eq!(u8::multifactorial(1, 1), 1);
805/// assert_eq!(u8::multifactorial(2, 1), 2);
806/// assert_eq!(u8::multifactorial(3, 1), 6);
807/// assert_eq!(u8::multifactorial(4, 1), 24);
808/// assert_eq!(u8::multifactorial(5, 1), 120);
809///
810/// assert_eq!(u8::multifactorial(0, 2), 1);
811/// assert_eq!(u8::multifactorial(1, 2), 1);
812/// assert_eq!(u8::multifactorial(2, 2), 2);
813/// assert_eq!(u8::multifactorial(3, 2), 3);
814/// assert_eq!(u8::multifactorial(4, 2), 8);
815/// assert_eq!(u8::multifactorial(5, 2), 15);
816/// assert_eq!(u8::multifactorial(6, 2), 48);
817/// assert_eq!(u8::multifactorial(7, 2), 105);
818///
819/// assert_eq!(u8::multifactorial(0, 3), 1);
820/// assert_eq!(u8::multifactorial(1, 3), 1);
821/// assert_eq!(u8::multifactorial(2, 3), 2);
822/// assert_eq!(u8::multifactorial(3, 3), 3);
823/// assert_eq!(u8::multifactorial(4, 3), 4);
824/// assert_eq!(u8::multifactorial(5, 3), 10);
825/// assert_eq!(u8::multifactorial(6, 3), 18);
826/// assert_eq!(u8::multifactorial(7, 3), 28);
827/// assert_eq!(u8::multifactorial(8, 3), 80);
828/// assert_eq!(u8::multifactorial(9, 3), 162);
829///
830/// assert_eq!(u32::multifactorial(10, 1), 3628800);
831/// assert_eq!(u32::multifactorial(20, 2), 3715891200);
832/// assert_eq!(u32::multifactorial(25, 3), 608608000);
833/// ```
834///
835/// # checked_multifactorial
836/// ```
837/// use malachite_base::num::arithmetic::traits::CheckedMultifactorial;
838///
839/// assert_eq!(u8::checked_multifactorial(0, 1), Some(1));
840/// assert_eq!(u8::checked_multifactorial(1, 1), Some(1));
841/// assert_eq!(u8::checked_multifactorial(2, 1), Some(2));
842/// assert_eq!(u8::checked_multifactorial(3, 1), Some(6));
843/// assert_eq!(u8::checked_multifactorial(4, 1), Some(24));
844/// assert_eq!(u8::checked_multifactorial(5, 1), Some(120));
845/// assert_eq!(u8::checked_multifactorial(6, 1), None);
846///
847/// assert_eq!(u8::checked_multifactorial(0, 2), Some(1));
848/// assert_eq!(u8::checked_multifactorial(1, 2), Some(1));
849/// assert_eq!(u8::checked_multifactorial(2, 2), Some(2));
850/// assert_eq!(u8::checked_multifactorial(3, 2), Some(3));
851/// assert_eq!(u8::checked_multifactorial(4, 2), Some(8));
852/// assert_eq!(u8::checked_multifactorial(5, 2), Some(15));
853/// assert_eq!(u8::checked_multifactorial(6, 2), Some(48));
854/// assert_eq!(u8::checked_multifactorial(7, 2), Some(105));
855/// assert_eq!(u8::checked_multifactorial(8, 2), None);
856///
857/// assert_eq!(u8::checked_multifactorial(0, 3), Some(1));
858/// assert_eq!(u8::checked_multifactorial(1, 3), Some(1));
859/// assert_eq!(u8::checked_multifactorial(2, 3), Some(2));
860/// assert_eq!(u8::checked_multifactorial(3, 3), Some(3));
861/// assert_eq!(u8::checked_multifactorial(4, 3), Some(4));
862/// assert_eq!(u8::checked_multifactorial(5, 3), Some(10));
863/// assert_eq!(u8::checked_multifactorial(6, 3), Some(18));
864/// assert_eq!(u8::checked_multifactorial(7, 3), Some(28));
865/// assert_eq!(u8::checked_multifactorial(8, 3), Some(80));
866/// assert_eq!(u8::checked_multifactorial(9, 3), Some(162));
867/// assert_eq!(u8::checked_multifactorial(10, 3), None);
868///
869/// assert_eq!(u32::checked_multifactorial(10, 1), Some(3628800));
870/// assert_eq!(u32::checked_multifactorial(20, 2), Some(3715891200));
871/// assert_eq!(u32::checked_multifactorial(25, 3), Some(608608000));
872/// assert_eq!(u32::checked_multifactorial(100, 1), None);
873/// assert_eq!(u32::checked_multifactorial(100, 2), None);
874/// assert_eq!(u32::checked_multifactorial(100, 3), None);
875/// ```
876///
877/// # subfactorial
878/// ```
879/// use malachite_base::num::arithmetic::traits::Subfactorial;
880///
881/// assert_eq!(u8::subfactorial(0), 1);
882/// assert_eq!(u8::subfactorial(1), 0);
883/// assert_eq!(u8::subfactorial(2), 1);
884/// assert_eq!(u8::subfactorial(3), 2);
885/// assert_eq!(u8::subfactorial(4), 9);
886/// assert_eq!(u8::subfactorial(5), 44);
887/// assert_eq!(u32::subfactorial(10), 1334961);
888/// ```
889///
890/// # checked_subfactorial
891/// ```
892/// use malachite_base::num::arithmetic::traits::CheckedSubfactorial;
893///
894/// assert_eq!(u8::checked_subfactorial(0), Some(1));
895/// assert_eq!(u8::checked_subfactorial(1), Some(0));
896/// assert_eq!(u8::checked_subfactorial(2), Some(1));
897/// assert_eq!(u8::checked_subfactorial(3), Some(2));
898/// assert_eq!(u8::checked_subfactorial(4), Some(9));
899/// assert_eq!(u8::checked_subfactorial(5), Some(44));
900/// assert_eq!(u8::checked_subfactorial(6), None);
901/// assert_eq!(u32::checked_subfactorial(10), Some(1334961));
902/// assert_eq!(u32::checked_subfactorial(100), None);
903/// ```
904pub mod factorial;
905/// [`Floor`](traits::Floor) and [`FloorAssign`](traits::FloorAssign), traits for computing the
906/// floor of a number.
907///
908/// # floor_assign
909/// ```
910/// use malachite_base::num::arithmetic::traits::FloorAssign;
911///
912/// let mut x = 1.5f32;
913/// x.floor_assign();
914/// assert_eq!(x, 1.0);
915///
916/// let mut x = -1.5f32;
917/// x.floor_assign();
918/// assert_eq!(x, -2.0);
919/// ```
920pub mod floor;
921/// [`Gcd`](traits::Gcd) and [`GcdAssign`](traits::GcdAssign), traits for computing the GCD
922/// (greatest common divisor) of two numbers.
923///
924/// # gcd
925/// ```
926/// use malachite_base::num::arithmetic::traits::Gcd;
927///
928/// assert_eq!(3u8.gcd(5), 1);
929/// assert_eq!(12u16.gcd(90), 6);
930/// ```
931///
932/// # gcd_assign
933/// ```
934/// use malachite_base::num::arithmetic::traits::GcdAssign;
935///
936/// let mut x = 3u8;
937/// x.gcd_assign(5);
938/// assert_eq!(x, 1);
939///
940/// let mut x = 12u16;
941/// x.gcd_assign(90);
942/// assert_eq!(x, 6);
943/// ```
944pub mod gcd;
945/// [`IsPowerOf2`](traits::IsPowerOf2), a trait for determining whether a number is an integer power
946/// of 2.
947///
948/// # is_power_of_2
949/// ```
950/// use malachite_base::num::arithmetic::traits::IsPowerOf2;
951///
952/// assert_eq!(4.0.is_power_of_2(), true);
953/// assert_eq!(0.25.is_power_of_2(), true);
954/// assert_eq!(0.2.is_power_of_2(), false);
955/// assert_eq!((-4.0).is_power_of_2(), false);
956/// ```
957pub mod is_power_of_2;
958/// [`LegendreSymbol`](traits::LegendreSymbol), [`JacobiSymbol`](traits::JacobiSymbol), and
959/// [`KroneckerSymbol`](traits::KroneckerSymbol), traits for computing the Legendre, Jacobi, and
960/// Kronecker symbols of two numbers.
961///
962/// # legendre_symbol
963/// ```
964/// use malachite_base::num::arithmetic::traits::LegendreSymbol;
965///
966/// assert_eq!(10u8.legendre_symbol(5), 0);
967/// assert_eq!(7u8.legendre_symbol(5), -1);
968/// assert_eq!(11u8.legendre_symbol(5), 1);
969///
970/// assert_eq!((-7i8).legendre_symbol(5), -1);
971/// assert_eq!((-11i8).legendre_symbol(5), 1);
972/// ```
973///
974/// # jacobi_symbol
975/// ```
976/// use malachite_base::num::arithmetic::traits::JacobiSymbol;
977///
978/// assert_eq!(10u8.jacobi_symbol(5), 0);
979/// assert_eq!(7u8.jacobi_symbol(5), -1);
980/// assert_eq!(11u8.jacobi_symbol(5), 1);
981/// assert_eq!(11u8.jacobi_symbol(9), 1);
982///
983/// assert_eq!((-7i8).jacobi_symbol(5), -1);
984/// assert_eq!((-11i8).jacobi_symbol(5), 1);
985/// assert_eq!((-11i8).jacobi_symbol(9), 1);
986/// ```
987///
988/// # kronecker_symbol
989/// ```
990/// use malachite_base::num::arithmetic::traits::KroneckerSymbol;
991///
992/// assert_eq!(10u8.kronecker_symbol(5), 0);
993/// assert_eq!(7u8.kronecker_symbol(5), -1);
994/// assert_eq!(11u8.kronecker_symbol(5), 1);
995/// assert_eq!(11u8.kronecker_symbol(9), 1);
996/// assert_eq!(11u8.kronecker_symbol(8), -1);
997///
998/// assert_eq!((-7i8).kronecker_symbol(5), -1);
999/// assert_eq!((-11i8).kronecker_symbol(5), 1);
1000/// assert_eq!((-11i8).kronecker_symbol(9), 1);
1001/// assert_eq!((-11i8).kronecker_symbol(8), -1);
1002/// assert_eq!((-11i8).kronecker_symbol(-8), 1);
1003/// ```
1004pub mod kronecker_symbol;
1005/// [`Lcm`](traits::Lcm), [`LcmAssign`](traits::LcmAssign), and [`CheckedLcm`](traits::CheckedLcm),
1006/// traits for computing the LCM (least common multiple) of two numbers.
1007///
1008/// # lcm
1009/// ```
1010/// use malachite_base::num::arithmetic::traits::Lcm;
1011///
1012/// assert_eq!(3u8.lcm(5), 15);
1013/// assert_eq!(12u16.lcm(90), 180);
1014/// ```
1015///
1016/// # lcm_assign
1017/// ```
1018/// use malachite_base::num::arithmetic::traits::LcmAssign;
1019///
1020/// let mut x = 3u8;
1021/// x.lcm_assign(5);
1022/// assert_eq!(x, 15);
1023///
1024/// let mut x = 12u16;
1025/// x.lcm_assign(90);
1026/// assert_eq!(x, 180);
1027/// ```
1028///
1029/// # checked_lcm
1030/// ```
1031/// use malachite_base::num::arithmetic::traits::CheckedLcm;
1032///
1033/// assert_eq!(3u8.checked_lcm(5), Some(15));
1034/// assert_eq!(12u16.checked_lcm(90), Some(180));
1035/// assert_eq!(120u8.checked_lcm(90), None);
1036/// ```
1037pub mod lcm;
1038/// Traits for taking the base-$b$ logarithm of a number.
1039///
1040/// The traits are [`FloorLogBase`](traits::FloorLogBase),
1041/// [`CeilingLogBase`](traits::CeilingLogBase), and [`CheckedLogBase`](traits::CheckedLogBase).
1042///
1043/// # floor_log_base
1044/// ```
1045/// use malachite_base::num::arithmetic::traits::FloorLogBase;
1046///
1047/// assert_eq!(1u8.floor_log_base(5), 0);
1048/// assert_eq!(125u8.floor_log_base(5), 3);
1049/// assert_eq!(99u64.floor_log_base(10), 1);
1050/// assert_eq!(100u64.floor_log_base(10), 2);
1051/// assert_eq!(101u64.floor_log_base(10), 2);
1052/// ```
1053///
1054/// # ceiling_log_base
1055/// ```
1056/// use malachite_base::num::arithmetic::traits::CeilingLogBase;
1057///
1058/// assert_eq!(1u8.ceiling_log_base(5), 0);
1059/// assert_eq!(125u8.ceiling_log_base(5), 3);
1060/// assert_eq!(99u64.ceiling_log_base(10), 2);
1061/// assert_eq!(100u64.ceiling_log_base(10), 2);
1062/// assert_eq!(101u64.ceiling_log_base(10), 3);
1063/// ```
1064///
1065/// # checked_log_base
1066/// ```
1067/// use malachite_base::num::arithmetic::traits::CheckedLogBase;
1068///
1069/// assert_eq!(1u8.checked_log_base(5), Some(0));
1070/// assert_eq!(125u8.checked_log_base(5), Some(3));
1071/// assert_eq!(99u64.checked_log_base(10), None);
1072/// assert_eq!(100u64.checked_log_base(10), Some(2));
1073/// assert_eq!(101u64.checked_log_base(10), None);
1074/// ```
1075pub mod log_base;
1076/// Traits for taking the base-2 logarithm of a number.
1077///
1078/// The traits are [`FloorLogBase2`](traits::FloorLogBase2),
1079/// [`CeilingLogBase2`](traits::CeilingLogBase2), and [`CheckedLogBase2`](traits::CheckedLogBase2).
1080///
1081/// # floor_log_base_2
1082/// ```
1083/// use malachite_base::num::arithmetic::traits::FloorLogBase2;
1084///
1085/// assert_eq!(1u8.floor_log_base_2(), 0);
1086/// assert_eq!(100u64.floor_log_base_2(), 6);
1087///
1088/// assert_eq!(1.0f32.floor_log_base_2(), 0);
1089/// assert_eq!(100.0f32.floor_log_base_2(), 6);
1090/// assert_eq!(0.1f32.floor_log_base_2(), -4);
1091/// ```
1092///
1093/// # ceiling_log_base_2
1094/// ```
1095/// use malachite_base::num::arithmetic::traits::CeilingLogBase2;
1096///
1097/// assert_eq!(1u8.ceiling_log_base_2(), 0);
1098/// assert_eq!(100u64.ceiling_log_base_2(), 7);
1099///
1100/// assert_eq!(1.0f32.ceiling_log_base_2(), 0);
1101/// assert_eq!(100.0f32.ceiling_log_base_2(), 7);
1102/// assert_eq!(0.1f32.ceiling_log_base_2(), -3);
1103/// ```
1104///
1105/// # checked_log_base_2
1106/// ```
1107/// use malachite_base::num::arithmetic::traits::CheckedLogBase2;
1108///
1109/// assert_eq!(1u8.checked_log_base_2(), Some(0));
1110/// assert_eq!(100u64.checked_log_base_2(), None);
1111/// assert_eq!(128u64.checked_log_base_2(), Some(7));
1112///
1113/// assert_eq!(1.0f32.checked_log_base_2(), Some(0));
1114/// assert_eq!(100.0f32.checked_log_base_2(), None);
1115/// assert_eq!(128.0f32.checked_log_base_2(), Some(7));
1116/// assert_eq!(0.1f32.checked_log_base_2(), None);
1117/// assert_eq!(0.0625f32.checked_log_base_2(), Some(-4));
1118/// ```
1119pub mod log_base_2;
1120/// Traits for taking the base-$2^k$ logarithm of a number.
1121///
1122/// The traits are [`FloorLogBasePowerOf2`](traits::FloorLogBasePowerOf2),
1123/// [`CeilingLogBasePowerOf2`](traits::CeilingLogBasePowerOf2), and
1124/// [`CheckedLogBasePowerOf2`](traits::CheckedLogBasePowerOf2).
1125///
1126/// # floor_log_base_power_of_2
1127/// ```
1128/// use malachite_base::num::arithmetic::traits::FloorLogBasePowerOf2;
1129///
1130/// assert_eq!(1u8.floor_log_base_power_of_2(4), 0);
1131/// assert_eq!(100u64.floor_log_base_power_of_2(2), 3);
1132///
1133/// assert_eq!(0.1f32.floor_log_base_power_of_2(2), -2);
1134/// ```
1135///
1136/// # ceiling_log_base_power_of_2
1137/// ```
1138/// use malachite_base::num::arithmetic::traits::CeilingLogBasePowerOf2;
1139///
1140/// assert_eq!(1u8.ceiling_log_base_power_of_2(4), 0);
1141/// assert_eq!(100u64.ceiling_log_base_power_of_2(2), 4);
1142///
1143/// assert_eq!(0.1f32.ceiling_log_base_power_of_2(2), -1);
1144/// ```
1145///
1146/// # checked_log_base_power_of_2
1147/// ```
1148/// use malachite_base::num::arithmetic::traits::CheckedLogBasePowerOf2;
1149///
1150/// assert_eq!(1u8.checked_log_base_power_of_2(4), Some(0));
1151/// assert_eq!(100u64.checked_log_base_power_of_2(4), None);
1152/// assert_eq!(256u64.checked_log_base_power_of_2(4), Some(2));
1153///
1154/// assert_eq!(0.1f32.checked_log_base_power_of_2(2), None);
1155/// assert_eq!(0.0625f32.checked_log_base_power_of_2(2), Some(-2));
1156/// ```
1157pub mod log_base_power_of_2;
1158/// [`ModAdd`](traits::ModAdd) and [`ModAddAssign`](traits::ModAddAssign), traits for adding two
1159/// numbers modulo another number.
1160///
1161/// # mod_add
1162/// ```
1163/// use malachite_base::num::arithmetic::traits::ModAdd;
1164///
1165/// assert_eq!(0u8.mod_add(3, 5), 3);
1166/// assert_eq!(7u32.mod_add(5, 10), 2);
1167/// ```
1168///
1169/// # mod_add_assign
1170/// ```
1171/// use malachite_base::num::arithmetic::traits::ModAddAssign;
1172///
1173/// let mut n = 0u8;
1174/// n.mod_add_assign(3, 5);
1175/// assert_eq!(n, 3);
1176///
1177/// let mut n = 7u32;
1178/// n.mod_add_assign(5, 10);
1179/// assert_eq!(n, 2);
1180/// ```
1181pub mod mod_add;
1182/// [`ModInverse`](traits::ModInverse), a trait for finding the multiplicative inverse of a number
1183/// modulo another number.
1184///
1185/// # mod_inverse
1186/// ```
1187/// use malachite_base::num::arithmetic::traits::ModInverse;
1188///
1189/// assert_eq!(7u8.mod_inverse(10), Some(3));
1190/// assert_eq!(8u8.mod_inverse(10), None);
1191/// assert_eq!(123u32.mod_inverse(4567), Some(854));
1192/// ```
1193pub mod mod_inverse;
1194/// [`ModIsReduced`](traits::ModIsReduced), a trait for checking whether a number is reduced modulo
1195/// another number.
1196///
1197/// # mod_is_reduced
1198/// ```
1199/// use malachite_base::num::arithmetic::traits::ModIsReduced;
1200///
1201/// assert_eq!(0u8.mod_is_reduced(&5), true);
1202/// assert_eq!(100u64.mod_is_reduced(&100), false);
1203/// assert_eq!(100u16.mod_is_reduced(&101), true);
1204/// ```
1205pub mod mod_is_reduced;
1206/// Traits for multiplying two numbers modulo another number.
1207///
1208/// The traits are [`ModMul`](traits::ModMul), [`ModMulAssign`](traits::ModMulAssign),
1209/// [`ModMulPrecomputed`](traits::ModMulPrecomputed), and
1210/// [`ModMulPrecomputedAssign`](traits::ModMulPrecomputedAssign).
1211/// [`ModMulPrecomputed`](traits::ModMulPrecomputed) and
1212/// [`ModMulPrecomputedAssign`](traits::ModMulPrecomputedAssign) are useful when having to make
1213/// several multiplications modulo the same modulus.
1214///
1215/// # mod_mul
1216/// ```
1217/// use malachite_base::num::arithmetic::traits::ModMul;
1218///
1219/// assert_eq!(2u8.mod_mul(3, 7), 6);
1220/// assert_eq!(7u32.mod_mul(3, 10), 1);
1221/// ```
1222///
1223/// # mod_mul_assign
1224/// ```
1225/// use malachite_base::num::arithmetic::traits::ModMulAssign;
1226///
1227/// let mut n = 2u8;
1228/// n.mod_mul_assign(3, 7);
1229/// assert_eq!(n, 6);
1230///
1231/// let mut n = 7u32;
1232/// n.mod_mul_assign(3, 10);
1233/// assert_eq!(n, 1);
1234/// ```
1235///
1236/// # mod_mul_precomputed
1237/// ```
1238/// use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
1239///
1240/// let data = u32::precompute_mod_mul_data(&7);
1241/// assert_eq!(2u32.mod_mul_precomputed(3, 7, &data), 6);
1242/// assert_eq!(5u32.mod_mul_precomputed(3, 7, &data), 1);
1243/// assert_eq!(4u32.mod_mul_precomputed(4, 7, &data), 2);
1244///
1245/// let data = u64::precompute_mod_mul_data(&10);
1246/// assert_eq!(7u64.mod_mul_precomputed(3, 10, &data), 1);
1247/// assert_eq!(4u64.mod_mul_precomputed(9, 10, &data), 6);
1248/// assert_eq!(5u64.mod_mul_precomputed(8, 10, &data), 0);
1249///
1250/// let data = u8::precompute_mod_mul_data(&7);
1251/// assert_eq!(2u8.mod_mul_precomputed(3, 7, &data), 6);
1252/// assert_eq!(5u8.mod_mul_precomputed(3, 7, &data), 1);
1253/// assert_eq!(4u8.mod_mul_precomputed(4, 7, &data), 2);
1254///
1255/// let data = u16::precompute_mod_mul_data(&10);
1256/// assert_eq!(7u16.mod_mul_precomputed(3, 10, &data), 1);
1257/// assert_eq!(4u16.mod_mul_precomputed(9, 10, &data), 6);
1258/// assert_eq!(5u16.mod_mul_precomputed(8, 10, &data), 0);
1259///
1260/// let data = u128::precompute_mod_mul_data(&7);
1261/// assert_eq!(2u128.mod_mul_precomputed(3, 7, &data), 6);
1262/// assert_eq!(5u128.mod_mul_precomputed(3, 7, &data), 1);
1263/// assert_eq!(4u128.mod_mul_precomputed(4, 7, &data), 2);
1264///
1265/// let data = u128::precompute_mod_mul_data(&10);
1266/// assert_eq!(7u128.mod_mul_precomputed(3, 10, &data), 1);
1267/// assert_eq!(4u128.mod_mul_precomputed(9, 10, &data), 6);
1268/// assert_eq!(5u128.mod_mul_precomputed(8, 10, &data), 0);
1269/// ```
1270///
1271/// # mod_mul_precomputed_assign
1272/// ```
1273/// use malachite_base::num::arithmetic::traits::{ModMulPrecomputed, ModMulPrecomputedAssign};
1274///
1275/// let data = u8::precompute_mod_mul_data(&7);
1276///
1277/// let mut x = 2u8;
1278/// x.mod_mul_precomputed_assign(3, 7, &data);
1279/// assert_eq!(x, 6);
1280///
1281/// let mut x = 5u8;
1282/// x.mod_mul_precomputed_assign(3, 7, &data);
1283/// assert_eq!(x, 1);
1284///
1285/// let mut x = 4u8;
1286/// x.mod_mul_precomputed_assign(4, 7, &data);
1287/// assert_eq!(x, 2);
1288///
1289/// let data = u32::precompute_mod_mul_data(&10);
1290///
1291/// let mut x = 7u32;
1292/// x.mod_mul_precomputed_assign(3, 10, &data);
1293/// assert_eq!(x, 1);
1294///
1295/// let mut x = 4u32;
1296/// x.mod_mul_precomputed_assign(9, 10, &data);
1297/// assert_eq!(x, 6);
1298///
1299/// let mut x = 5u32;
1300/// x.mod_mul_precomputed_assign(8, 10, &data);
1301/// assert_eq!(x, 0);
1302/// ```
1303pub mod mod_mul;
1304/// [`ModNeg`](traits::ModNeg) and [`ModNegAssign`](traits::ModNegAssign), traits for negating a
1305/// number modulo another number.
1306///
1307/// # mod_neg
1308/// ```
1309/// use malachite_base::num::arithmetic::traits::ModNeg;
1310///
1311/// assert_eq!(0u8.mod_neg(5), 0);
1312/// assert_eq!(7u32.mod_neg(10), 3);
1313/// assert_eq!(100u16.mod_neg(101), 1);
1314/// ```
1315///
1316/// # mod_neg_assign
1317/// ```
1318/// use malachite_base::num::arithmetic::traits::ModNegAssign;
1319///
1320/// let mut n = 0u8;
1321/// n.mod_neg_assign(5);
1322/// assert_eq!(n, 0);
1323///
1324/// let mut n = 7u32;
1325/// n.mod_neg_assign(10);
1326/// assert_eq!(n, 3);
1327///
1328/// let mut n = 100u16;
1329/// n.mod_neg_assign(101);
1330/// assert_eq!(n, 1);
1331/// ```
1332pub mod mod_neg;
1333/// Traits for finding the remainder of two numbers, subject to various rounding rules.
1334///
1335/// These are the traits:
1336///
1337/// | rounding          | by value or reference      | by mutable reference (assignment)      |
1338/// |-------------------|----------------------------|----------------------------------------|
1339/// | towards $-\infty$ | [`Mod`](traits::Mod)       | [`ModAssign`](traits::ModAssign)       |
1340/// | towards $\infty$  | [`CeilingMod`](traits::CeilingMod) | [`CeilingModAssign`](traits::CeilingModAssign) |
1341/// | towards $\infty$  | [`NegMod`](traits::NegMod) | [`NegModAssign`](traits::NegModAssign) |
1342///
1343/// [`CeilingMod`](traits::CeilingMod) and [`NegMod`](traits::NegMod) are similar. The difference is
1344/// that [`CeilingMod`](traits::CeilingMod) returns a remainder less than or equal to 0, so that the
1345/// usual relation $x = qy + r$ is satisfied, while [`NegMod`](traits::NegMod) returns a remainder
1346/// greater than or equal to zero. This allows the remainder to have an unsigned type, but modifies
1347/// the relation to $x = qy - r$.
1348///
1349/// The [`Rem`](std::ops::Rem) trait in the standard library rounds towards 0.
1350///
1351/// # mod_op
1352/// ```
1353/// use malachite_base::num::arithmetic::traits::Mod;
1354///
1355/// // 2 * 10 + 3 = 23
1356/// assert_eq!(23u8.mod_op(10), 3);
1357///
1358/// // 9 * 5 + 0 = 45
1359/// assert_eq!(45u32.mod_op(5), 0);
1360///
1361/// // 2 * 10 + 3 = 23
1362/// assert_eq!(23i8.mod_op(10), 3);
1363///
1364/// // -3 * -10 + -7 = 23
1365/// assert_eq!(23i16.mod_op(-10), -7);
1366///
1367/// // -3 * 10 + 7 = -23
1368/// assert_eq!((-23i32).mod_op(10), 7);
1369///
1370/// // 2 * -10 + -3 = -23
1371/// assert_eq!((-23i64).mod_op(-10), -3);
1372/// ```
1373///
1374/// # mod_assign
1375/// ```
1376/// use malachite_base::num::arithmetic::traits::ModAssign;
1377///
1378/// // 2 * 10 + 3 = 23
1379/// let mut x = 23u8;
1380/// x.mod_assign(10);
1381/// assert_eq!(x, 3);
1382///
1383/// // 9 * 5 + 0 = 45
1384/// let mut x = 45u32;
1385/// x.mod_assign(5);
1386/// assert_eq!(x, 0);
1387///
1388/// // 2 * 10 + 3 = 23
1389/// let mut x = 23i8;
1390/// x.mod_assign(10);
1391/// assert_eq!(x, 3);
1392///
1393/// // -3 * -10 + -7 = 23
1394/// let mut x = 23i16;
1395/// x.mod_assign(-10);
1396/// assert_eq!(x, -7);
1397///
1398/// // -3 * 10 + 7 = -23
1399/// let mut x = -23i32;
1400/// x.mod_assign(10);
1401/// assert_eq!(x, 7);
1402///
1403/// // 2 * -10 + -3 = -23
1404/// let mut x = -23i64;
1405/// x.mod_assign(-10);
1406/// assert_eq!(x, -3);
1407/// ```
1408///
1409/// # neg_mod
1410/// ```
1411/// use malachite_base::num::arithmetic::traits::NegMod;
1412///
1413/// // 3 * 10 - 7 = 23
1414/// assert_eq!(23u8.neg_mod(10), 7);
1415///
1416/// // 9 * 5 + 0 = 45
1417/// assert_eq!(45u32.neg_mod(5), 0);
1418/// ```
1419///
1420/// # neg_mod_assign
1421/// ```
1422/// use malachite_base::num::arithmetic::traits::NegModAssign;
1423///
1424/// // 3 * 10 - 7 = 23
1425/// let mut x = 23u8;
1426/// x.neg_mod_assign(10);
1427/// assert_eq!(x, 7);
1428///
1429/// // 9 * 5 + 0 = 45
1430/// let mut x = 45u32;
1431/// x.neg_mod_assign(5);
1432/// assert_eq!(x, 0);
1433/// ```
1434///
1435/// # ceiling_mod
1436/// ```
1437/// use malachite_base::num::arithmetic::traits::CeilingMod;
1438///
1439/// // 3 * 10 + -7 = 23
1440/// assert_eq!(23i8.ceiling_mod(10), -7);
1441///
1442/// // -2 * -10 + 3 = 23
1443/// assert_eq!(23i16.ceiling_mod(-10), 3);
1444///
1445/// // -2 * 10 + -3 = -23
1446/// assert_eq!((-23i32).ceiling_mod(10), -3);
1447///
1448/// // 3 * -10 + 7 = -23
1449/// assert_eq!((-23i64).ceiling_mod(-10), 7);
1450/// ```
1451///
1452/// # ceiling_mod_assign
1453/// ```
1454/// use malachite_base::num::arithmetic::traits::CeilingModAssign;
1455///
1456/// // 3 * 10 + -7 = 23
1457/// let mut x = 23i8;
1458/// x.ceiling_mod_assign(10);
1459/// assert_eq!(x, -7);
1460///
1461/// // -2 * -10 + 3 = 23
1462/// let mut x = 23i16;
1463/// x.ceiling_mod_assign(-10);
1464/// assert_eq!(x, 3);
1465///
1466/// // -2 * 10 + -3 = -23
1467/// let mut x = -23i32;
1468/// x.ceiling_mod_assign(10);
1469/// assert_eq!(x, -3);
1470///
1471/// // 3 * -10 + 7 = -23
1472/// let mut x = -23i64;
1473/// x.ceiling_mod_assign(-10);
1474/// assert_eq!(x, 7);
1475/// ```
1476pub mod mod_op;
1477/// Traits for raising a number to a power modulo another number.
1478///
1479/// The traits are [`ModPow`](traits::ModPow), [`ModPowAssign`](traits::ModPowAssign), and
1480/// [`ModPowPrecomputed`](traits::ModPowPrecomputed).
1481/// [`ModPowPrecomputed`](traits::ModPowPrecomputed) is useful when having to make several
1482/// exponentiations modulo the same modulus.
1483///
1484/// # mod_pow
1485/// ```
1486/// use malachite_base::num::arithmetic::traits::ModPow;
1487///
1488/// assert_eq!(4u16.mod_pow(13, 497), 445);
1489/// assert_eq!(10u32.mod_pow(1000, 30), 10);
1490/// ```
1491///
1492/// # mod_pow_assign
1493/// ```
1494/// use malachite_base::num::arithmetic::traits::ModPowAssign;
1495///
1496/// let mut n = 4u16;
1497/// n.mod_pow_assign(13, 497);
1498/// assert_eq!(n, 445);
1499///
1500/// let mut n = 10u32;
1501/// n.mod_pow_assign(1000, 30);
1502/// assert_eq!(n, 10);
1503/// ```
1504///
1505/// # mod_pow_precomputed
1506/// ```
1507/// use malachite_base::num::arithmetic::traits::ModPowPrecomputed;
1508///
1509/// let data = u32::precompute_mod_pow_data(&497);
1510/// assert_eq!(4u32.mod_pow_precomputed(13, 497, &data), 445);
1511/// assert_eq!(5u32.mod_pow_precomputed(3, 497, &data), 125);
1512/// assert_eq!(4u32.mod_pow_precomputed(100, 497, &data), 116);
1513///
1514/// let data = u64::precompute_mod_pow_data(&30);
1515/// assert_eq!(10u64.mod_pow_precomputed(1000, 30, &data), 10);
1516/// assert_eq!(4u64.mod_pow_precomputed(9, 30, &data), 4);
1517/// assert_eq!(5u64.mod_pow_precomputed(8, 30, &data), 25);
1518///
1519/// let data = u16::precompute_mod_pow_data(&497);
1520/// assert_eq!(4u16.mod_pow_precomputed(13, 497, &data), 445);
1521/// assert_eq!(5u16.mod_pow_precomputed(3, 497, &data), 125);
1522/// assert_eq!(4u16.mod_pow_precomputed(100, 497, &data), 116);
1523///
1524/// let data = u8::precompute_mod_pow_data(&30);
1525/// assert_eq!(10u8.mod_pow_precomputed(1000, 30, &data), 10);
1526/// assert_eq!(4u8.mod_pow_precomputed(9, 30, &data), 4);
1527/// assert_eq!(5u8.mod_pow_precomputed(8, 30, &data), 25);
1528///
1529/// let data = u128::precompute_mod_pow_data(&497);
1530/// assert_eq!(4u128.mod_pow_precomputed(13, 497, &data), 445);
1531/// assert_eq!(5u128.mod_pow_precomputed(3, 497, &data), 125);
1532/// assert_eq!(4u128.mod_pow_precomputed(100, 497, &data), 116);
1533///
1534/// let data = u128::precompute_mod_pow_data(&30);
1535/// assert_eq!(10u128.mod_pow_precomputed(1000, 30, &data), 10);
1536/// assert_eq!(4u128.mod_pow_precomputed(9, 30, &data), 4);
1537/// assert_eq!(5u128.mod_pow_precomputed(8, 30, &data), 25);
1538/// ```
1539///
1540/// # mod_pow_precomputed_assign
1541/// ```
1542/// use malachite_base::num::arithmetic::traits::{ModPowPrecomputed, ModPowPrecomputedAssign};
1543///
1544/// let data = u32::precompute_mod_pow_data(&497);
1545///
1546/// let mut x = 4u32;
1547/// x.mod_pow_precomputed_assign(13, 497, &data);
1548/// assert_eq!(x, 445);
1549///
1550/// let mut x = 5u32;
1551/// x.mod_pow_precomputed_assign(3, 497, &data);
1552/// assert_eq!(x, 125);
1553///
1554/// let mut x = 4u32;
1555/// x.mod_pow_precomputed_assign(100, 497, &data);
1556/// assert_eq!(x, 116);
1557///
1558/// let data = u64::precompute_mod_pow_data(&30);
1559///
1560/// let mut x = 10u64;
1561/// x.mod_pow_precomputed_assign(1000, 30, &data);
1562/// assert_eq!(x, 10);
1563///
1564/// let mut x = 4u64;
1565/// x.mod_pow_precomputed_assign(9, 30, &data);
1566/// assert_eq!(x, 4);
1567///
1568/// let mut x = 5u64;
1569/// x.mod_pow_precomputed_assign(8, 30, &data);
1570/// assert_eq!(x, 25);
1571/// ```
1572pub mod mod_pow;
1573/// Traits for finding the remainder of a number divided by $2^k$, subject to various rounding
1574/// rules.
1575///
1576/// These are the traits:
1577///
1578/// | rounding | by value or reference | by mutable reference (assignment) |
1579/// |----------|-----------------------|-----------------------------------|
1580/// | towards $-\infty$ | [`ModPowerOf2`](traits::ModPowerOf2) | [`ModPowerOf2Assign`](traits::ModPowerOf2Assign)       |
1581/// | towards 0 | [`RemPowerOf2`](traits::RemPowerOf2) | [`RemPowerOf2Assign`](traits::RemPowerOf2Assign)       |
1582/// | towards $\infty$  | [`CeilingModPowerOf2`](traits::CeilingModPowerOf2) | [`CeilingModPowerOf2Assign`](traits::CeilingModPowerOf2Assign) |
1583/// | towards $\infty$  | [`NegModPowerOf2`](traits::NegModPowerOf2) | [`NegModPowerOf2Assign`](traits::NegModPowerOf2Assign) |
1584///
1585/// [`CeilingModPowerOf2`](traits::CeilingModPowerOf2) and
1586/// [`NegModPowerOf2`](traits::NegModPowerOf2) are similar. The difference is that
1587/// [`CeilingModPowerOf2`](traits::CeilingModPowerOf2) returns a remainder less than or equal to 0,
1588/// so that the usual relation $x = q2^k + r$ is satisfied, while
1589/// [`NegModPowerOf2`](traits::NegModPowerOf2) returns a remainder greater than or equal to zero.
1590/// This allows the remainder to have an unsigned type, but modifies the relation to $x = q2^k - r$.
1591///
1592/// # mod_power_of_2
1593/// ```
1594/// use malachite_base::num::arithmetic::traits::ModPowerOf2;
1595///
1596/// // 1 * 2^8 + 4 = 260
1597/// assert_eq!(260u16.mod_power_of_2(8), 4);
1598///
1599/// // 100 * 2^4 + 11 = 1611
1600/// assert_eq!(1611u32.mod_power_of_2(4), 11);
1601///
1602/// // 1 * 2^8 + 4 = 260
1603/// assert_eq!(260i16.mod_power_of_2(8), 4);
1604///
1605/// // -101 * 2^4 + 5 = -1611
1606/// assert_eq!((-1611i32).mod_power_of_2(4), 5);
1607/// ```
1608///
1609/// # mod_power_of_2_assign
1610/// ```
1611/// use malachite_base::num::arithmetic::traits::ModPowerOf2Assign;
1612///
1613/// // 1 * 2^8 + 4 = 260
1614/// let mut x = 260u16;
1615/// x.mod_power_of_2_assign(8);
1616/// assert_eq!(x, 4);
1617///
1618/// // 100 * 2^4 + 11 = 1611
1619/// let mut x = 1611u32;
1620/// x.mod_power_of_2_assign(4);
1621/// assert_eq!(x, 11);
1622///
1623/// // 1 * 2^8 + 4 = 260
1624/// let mut x = 260i16;
1625/// x.mod_power_of_2_assign(8);
1626/// assert_eq!(x, 4);
1627///
1628/// // -101 * 2^4 + 5 = -1611
1629/// let mut x = -1611i32;
1630/// x.mod_power_of_2_assign(4);
1631/// assert_eq!(x, 5);
1632/// ```
1633///
1634/// # rem_power_of_2
1635/// ```
1636/// use malachite_base::num::arithmetic::traits::RemPowerOf2;
1637///
1638/// // 1 * 2^8 + 4 = 260
1639/// assert_eq!(260u16.rem_power_of_2(8), 4);
1640///
1641/// // 100 * 2^4 + 11 = 1611
1642/// assert_eq!(1611u32.rem_power_of_2(4), 11);
1643///
1644/// // 1 * 2^8 + 4 = 260
1645/// assert_eq!(260i16.rem_power_of_2(8), 4);
1646///
1647/// // -100 * 2^4 + -11 = -1611
1648/// assert_eq!((-1611i32).rem_power_of_2(4), -11);
1649/// ```
1650///
1651/// # rem_power_of_2_assign
1652/// ```
1653/// use malachite_base::num::arithmetic::traits::RemPowerOf2Assign;
1654///
1655/// // 1 * 2^8 + 4 = 260
1656/// let mut x = 260u16;
1657/// x.rem_power_of_2_assign(8);
1658/// assert_eq!(x, 4);
1659///
1660/// // 100 * 2^4 + 11 = 1611
1661/// let mut x = 1611u32;
1662/// x.rem_power_of_2_assign(4);
1663/// assert_eq!(x, 11);
1664///
1665/// // 1 * 2^8 + 4 = 260
1666/// let mut x = 260i16;
1667/// x.rem_power_of_2_assign(8);
1668/// assert_eq!(x, 4);
1669///
1670/// // -100 * 2^4 + -11 = -1611
1671/// let mut x = -1611i32;
1672/// x.rem_power_of_2_assign(4);
1673/// assert_eq!(x, -11);
1674/// ```
1675///
1676/// # neg_mod_power_of_2
1677/// ```
1678/// use malachite_base::num::arithmetic::traits::NegModPowerOf2;
1679///
1680/// // 2 * 2^8 - 252 = 260
1681/// assert_eq!(260u16.neg_mod_power_of_2(8), 252);
1682///
1683/// // 101 * 2^4 - 5 = 1611
1684/// assert_eq!(1611u32.neg_mod_power_of_2(4), 5);
1685/// ```
1686///
1687/// # neg_mod_power_of_2_assign
1688/// ```
1689/// use malachite_base::num::arithmetic::traits::NegModPowerOf2Assign;
1690///
1691/// // 2 * 2^8 - 252 = 260
1692/// let mut x = 260u16;
1693/// x.neg_mod_power_of_2_assign(8);
1694/// assert_eq!(x, 252);
1695///
1696/// // 101 * 2^4 - 5 = 1611
1697/// let mut x = 1611u32;
1698/// x.neg_mod_power_of_2_assign(4);
1699/// assert_eq!(x, 5);
1700/// ```
1701///
1702/// # ceiling_mod_power_of_2
1703/// ```
1704/// use malachite_base::num::arithmetic::traits::CeilingModPowerOf2;
1705///
1706/// // 2 * 2^8 + -252 = 260
1707/// assert_eq!(260i16.ceiling_mod_power_of_2(8), -252);
1708///
1709/// // -100 * 2^4 + -11 = -1611
1710/// assert_eq!((-1611i32).ceiling_mod_power_of_2(4), -11);
1711/// ```
1712///
1713/// # ceiling_mod_power_of_2_assign
1714/// ```
1715/// use malachite_base::num::arithmetic::traits::CeilingModPowerOf2Assign;
1716///
1717/// // 2 * 2^8 + -252 = 260
1718/// let mut x = 260i16;
1719/// x.ceiling_mod_power_of_2_assign(8);
1720/// assert_eq!(x, -252);
1721///
1722/// // -100 * 2^4 + -11 = -1611
1723/// let mut x = -1611i32;
1724/// x.ceiling_mod_power_of_2_assign(4);
1725/// assert_eq!(x, -11);
1726/// ```
1727pub mod mod_power_of_2;
1728/// [`ModPowerOf2Add`](traits::ModPowerOf2Add) and
1729/// [`ModPowerOf2AddAssign`](traits::ModPowerOf2AddAssign), traits for adding two numbers modulo
1730/// $2^k$.
1731///
1732/// # mod_power_of_2_add
1733/// ```
1734/// use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
1735///
1736/// assert_eq!(0u8.mod_power_of_2_add(2, 5), 2);
1737/// assert_eq!(10u32.mod_power_of_2_add(14, 4), 8);
1738/// ```
1739///
1740/// # mod_power_of_2_add_assign
1741/// ```
1742/// use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
1743///
1744/// let mut n = 0u8;
1745/// n.mod_power_of_2_add_assign(2, 5);
1746/// assert_eq!(n, 2);
1747///
1748/// let mut n = 10u32;
1749/// n.mod_power_of_2_add_assign(14, 4);
1750/// assert_eq!(n, 8);
1751/// ```
1752pub mod mod_power_of_2_add;
1753/// [`ModPowerOf2Inverse`](traits::ModPowerOf2Inverse), a trait for finding the multiplicative
1754/// inverse of a number modulo $2^k$.
1755///
1756/// # mod_inverse
1757/// ```
1758/// use malachite_base::num::arithmetic::traits::ModPowerOf2Inverse;
1759///
1760/// assert_eq!(7u8.mod_power_of_2_inverse(4), Some(7));
1761/// assert_eq!(8u8.mod_power_of_2_inverse(4), None);
1762/// assert_eq!(123u32.mod_power_of_2_inverse(7), Some(51));
1763/// ```
1764pub mod mod_power_of_2_inverse;
1765/// [`ModPowerOf2IsReduced`](traits::ModPowerOf2IsReduced), a trait for checking whether a number is
1766/// reduced modulo $2^k$.
1767///
1768/// # mod_power_of_2_is_reduced
1769/// ```
1770/// use malachite_base::num::arithmetic::traits::ModPowerOf2IsReduced;
1771///
1772/// assert_eq!(0u8.mod_power_of_2_is_reduced(5), true);
1773/// assert_eq!(100u64.mod_power_of_2_is_reduced(5), false);
1774/// assert_eq!(100u16.mod_power_of_2_is_reduced(8), true);
1775/// ```
1776pub mod mod_power_of_2_is_reduced;
1777/// [`ModPowerOf2Mul`](traits::ModPowerOf2Mul) and
1778/// [`ModPowerOf2MulAssign`](traits::ModPowerOf2MulAssign), traits for multiplying two numbers
1779/// modulo $2^k$.
1780///
1781/// # mod_power_of_2_mul
1782/// ```
1783/// use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
1784///
1785/// assert_eq!(3u8.mod_power_of_2_mul(2, 5), 6);
1786/// assert_eq!(10u32.mod_power_of_2_mul(14, 4), 12);
1787/// ```
1788///
1789/// # mod_power_of_2_mul_assign
1790/// ```
1791/// use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
1792///
1793/// let mut n = 3u8;
1794/// n.mod_power_of_2_mul_assign(2, 5);
1795/// assert_eq!(n, 6);
1796///
1797/// let mut n = 10u32;
1798/// n.mod_power_of_2_mul_assign(14, 4);
1799/// assert_eq!(n, 12);
1800/// ```
1801pub mod mod_power_of_2_mul;
1802/// [`ModPowerOf2Neg`](traits::ModPowerOf2Neg) and
1803/// [`ModPowerOf2NegAssign`](traits::ModPowerOf2NegAssign), traits for negating a number modulo
1804/// $2^k$.
1805///
1806/// # mod_power_of_2_neg
1807/// ```
1808/// use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
1809///
1810/// assert_eq!(0u8.mod_power_of_2_neg(5), 0);
1811/// assert_eq!(10u32.mod_power_of_2_neg(4), 6);
1812/// assert_eq!(100u16.mod_power_of_2_neg(8), 156);
1813/// ```
1814///
1815/// # mod_power_of_2_neg_assign
1816/// ```
1817/// use malachite_base::num::arithmetic::traits::ModPowerOf2NegAssign;
1818///
1819/// let mut n = 0u8;
1820/// n.mod_power_of_2_neg_assign(5);
1821/// assert_eq!(n, 0);
1822///
1823/// let mut n = 10u32;
1824/// n.mod_power_of_2_neg_assign(4);
1825/// assert_eq!(n, 6);
1826///
1827/// let mut n = 100u16;
1828/// n.mod_power_of_2_neg_assign(8);
1829/// assert_eq!(n, 156);
1830/// ```
1831pub mod mod_power_of_2_neg;
1832/// [`ModPowerOf2Pow`](traits::ModPowerOf2Pow) and
1833/// [`ModPowerOf2PowAssign`](traits::ModPowerOf2PowAssign), traits for raising a number to a power
1834/// modulo $2^k$.
1835///
1836/// # mod_power_of_2_pow
1837/// ```
1838/// use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
1839///
1840/// assert_eq!(5u8.mod_power_of_2_pow(13, 3), 5);
1841/// assert_eq!(7u32.mod_power_of_2_pow(1000, 6), 1);
1842/// ```
1843///
1844/// # mod_power_of_2_pow_assign
1845/// ```
1846/// use malachite_base::num::arithmetic::traits::ModPowerOf2PowAssign;
1847///
1848/// let mut n = 5u8;
1849/// n.mod_power_of_2_pow_assign(13, 3);
1850/// assert_eq!(n, 5);
1851///
1852/// let mut n = 7u32;
1853/// n.mod_power_of_2_pow_assign(1000, 6);
1854/// assert_eq!(n, 1);
1855/// ```
1856pub mod mod_power_of_2_pow;
1857/// [`ModPowerOf2Shl`](traits::ModPowerOf2Shl) and
1858/// [`ModPowerOf2ShlAssign`](traits::ModPowerOf2ShlAssign), traits for left-shifting a number modulo
1859/// $2^k$.
1860///
1861/// # mod_power_of_2_shl
1862/// ```
1863/// use malachite_base::num::arithmetic::traits::ModPowerOf2Shl;
1864///
1865/// assert_eq!(12u32.mod_power_of_2_shl(2u8, 5), 16);
1866/// assert_eq!(10u8.mod_power_of_2_shl(100u64, 4), 0);
1867///
1868/// assert_eq!(12u32.mod_power_of_2_shl(2i8, 5), 16);
1869/// assert_eq!(10u8.mod_power_of_2_shl(-2i64, 4), 2);
1870/// ```
1871///
1872/// # mod_power_of_2_shl_assign
1873/// ```
1874/// use malachite_base::num::arithmetic::traits::ModPowerOf2ShlAssign;
1875///
1876/// let mut n = 12u32;
1877/// n.mod_power_of_2_shl_assign(2u8, 5);
1878/// assert_eq!(n, 16);
1879///
1880/// let mut n = 10u8;
1881/// n.mod_power_of_2_shl_assign(100u64, 4);
1882/// assert_eq!(n, 0);
1883///
1884/// let mut n = 12u32;
1885/// n.mod_power_of_2_shl_assign(2i8, 5);
1886/// assert_eq!(n, 16);
1887///
1888/// let mut n = 10u8;
1889/// n.mod_power_of_2_shl_assign(-2i64, 4);
1890/// assert_eq!(n, 2);
1891/// ```
1892pub mod mod_power_of_2_shl;
1893/// [`ModPowerOf2Shr`](traits::ModPowerOf2Shr) and
1894/// [`ModPowerOf2ShrAssign`](traits::ModPowerOf2ShrAssign), traits for right-shifting a number
1895/// modulo $2^k$.
1896///
1897/// # mod_power_of_2_shr
1898/// ```
1899/// use malachite_base::num::arithmetic::traits::ModPowerOf2Shr;
1900///
1901/// assert_eq!(10u8.mod_power_of_2_shr(2i64, 4), 2);
1902/// assert_eq!(12u32.mod_power_of_2_shr(-2i8, 5), 16);
1903/// ```
1904///
1905/// # mod_power_of_2_shr_assign
1906/// ```
1907/// use malachite_base::num::arithmetic::traits::ModPowerOf2ShrAssign;
1908///
1909/// let mut n = 10u8;
1910/// n.mod_power_of_2_shr_assign(2i64, 4);
1911/// assert_eq!(n, 2);
1912///
1913/// let mut n = 12u32;
1914/// n.mod_power_of_2_shr_assign(-2i8, 5);
1915/// assert_eq!(n, 16);
1916/// ```
1917pub mod mod_power_of_2_shr;
1918/// [`ModPowerOf2Square`](traits::ModPowerOf2Square) and
1919/// [`ModPowerOf2SquareAssign`](traits::ModPowerOf2SquareAssign), traits for squaring a number
1920/// modulo $2^k$.
1921///
1922/// # mod_power_of_2_square
1923/// ```
1924/// use malachite_base::num::arithmetic::traits::ModPowerOf2Square;
1925///
1926/// assert_eq!(5u8.mod_power_of_2_square(3), 1);
1927/// assert_eq!(100u32.mod_power_of_2_square(8), 16);
1928/// ```
1929///
1930/// # mod_power_of_2_square_assign
1931/// ```
1932/// use malachite_base::num::arithmetic::traits::ModPowerOf2SquareAssign;
1933///
1934/// let mut n = 5u8;
1935/// n.mod_power_of_2_square_assign(3);
1936/// assert_eq!(n, 1);
1937///
1938/// let mut n = 100u32;
1939/// n.mod_power_of_2_square_assign(8);
1940/// assert_eq!(n, 16);
1941/// ```
1942pub mod mod_power_of_2_square;
1943/// [`ModPowerOf2Sub`](traits::ModPowerOf2Sub) and
1944/// [`ModPowerOf2SubAssign`](traits::ModPowerOf2SubAssign), traits for subtracting one number by
1945/// another modulo $2^k$.
1946///
1947/// # mod_power_of_2_sub
1948/// ```
1949/// use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
1950///
1951/// assert_eq!(5u8.mod_power_of_2_sub(2, 5), 3);
1952/// assert_eq!(10u32.mod_power_of_2_sub(14, 4), 12);
1953/// ```
1954///
1955/// # mod_power_of_2_sub_assign
1956/// ```
1957/// use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
1958///
1959/// let mut n = 5u8;
1960/// n.mod_power_of_2_sub_assign(2, 5);
1961/// assert_eq!(n, 3);
1962///
1963/// let mut n = 10u32;
1964/// n.mod_power_of_2_sub_assign(14, 4);
1965/// assert_eq!(n, 12);
1966/// ```
1967pub mod mod_power_of_2_sub;
1968/// [`ModShl`](traits::ModShl) and [`ModShlAssign`](traits::ModShlAssign), traits for left-shifting
1969/// a number modulo another number.
1970///
1971/// # mod_shl
1972/// ```
1973/// use malachite_base::num::arithmetic::traits::ModShl;
1974///
1975/// assert_eq!(8u32.mod_shl(2u8, 10), 2);
1976/// assert_eq!(10u8.mod_shl(100u64, 17), 7);
1977///
1978/// assert_eq!(8u32.mod_shl(2i8, 10), 2);
1979/// assert_eq!(10u8.mod_shl(-2i64, 15), 2);
1980/// ```
1981///
1982/// # mod_shl_assign
1983/// ```
1984/// use malachite_base::num::arithmetic::traits::ModShlAssign;
1985///
1986/// let mut n = 8u32;
1987/// n.mod_shl_assign(2u8, 10);
1988/// assert_eq!(n, 2);
1989///
1990/// let mut n = 10u8;
1991/// n.mod_shl_assign(100u64, 17);
1992/// assert_eq!(n, 7);
1993///
1994/// let mut n = 8u32;
1995/// n.mod_shl_assign(2i8, 10);
1996/// assert_eq!(n, 2);
1997///
1998/// let mut n = 10u8;
1999/// n.mod_shl_assign(-2i64, 15);
2000/// assert_eq!(n, 2);
2001/// ```
2002pub mod mod_shl;
2003/// [`ModShr`](traits::ModShr) and [`ModShrAssign`](traits::ModShrAssign), traits for right-shifting
2004/// a number modulo another number.
2005///
2006/// # mod_shr
2007/// ```
2008/// use malachite_base::num::arithmetic::traits::ModShr;
2009///
2010/// assert_eq!(10u8.mod_shr(2i64, 15), 2);
2011/// assert_eq!(8u32.mod_shr(-2i8, 10), 2);
2012/// ```
2013///
2014/// # mod_shr_assign
2015/// ```
2016/// use malachite_base::num::arithmetic::traits::ModShrAssign;
2017///
2018/// let mut n = 10u8;
2019/// n.mod_shr_assign(2i64, 15);
2020/// assert_eq!(n, 2);
2021///
2022/// let mut n = 8u32;
2023/// n.mod_shr_assign(-2i8, 10);
2024/// assert_eq!(n, 2);
2025/// ```
2026pub mod mod_shr;
2027/// Traits for squaring a number modulo another number.
2028///
2029/// The traits are [`ModSquare`](traits::ModSquare), [`ModSquareAssign`](traits::ModSquareAssign),
2030/// and [`ModSquarePrecomputed`](traits::ModSquarePrecomputed).
2031/// [`ModSquarePrecomputed`](traits::ModSquarePrecomputed) is useful when having to make several
2032/// squarings modulo the same modulus.
2033///
2034/// # mod_square
2035/// ```
2036/// use malachite_base::num::arithmetic::traits::ModSquare;
2037///
2038/// assert_eq!(2u8.mod_square(10), 4);
2039/// assert_eq!(100u32.mod_square(497), 60);
2040/// ```
2041///
2042/// # mod_square_assign
2043/// ```
2044/// use malachite_base::num::arithmetic::traits::ModSquareAssign;
2045///
2046/// let mut n = 2u8;
2047/// n.mod_square_assign(10);
2048/// assert_eq!(n, 4);
2049///
2050/// let mut n = 100u32;
2051/// n.mod_square_assign(497);
2052/// assert_eq!(n, 60);
2053/// ```
2054///
2055/// # mod_square_precomputed
2056/// ```
2057/// use malachite_base::num::arithmetic::traits::{ModPowPrecomputed, ModSquarePrecomputed};
2058///
2059/// let data = u16::precompute_mod_pow_data(&497);
2060/// assert_eq!(100u16.mod_square_precomputed(497, &data), 60);
2061/// assert_eq!(200u16.mod_square_precomputed(497, &data), 240);
2062/// assert_eq!(300u16.mod_square_precomputed(497, &data), 43);
2063/// ```
2064///
2065/// # mod_square_precomputed_assign
2066/// ```
2067/// use malachite_base::num::arithmetic::traits::{ModPowPrecomputed, ModSquarePrecomputedAssign};
2068///
2069/// let data = u32::precompute_mod_pow_data(&497);
2070///
2071/// let mut x = 100u32;
2072/// x.mod_square_precomputed_assign(497, &data);
2073/// assert_eq!(x, 60);
2074///
2075/// let mut x = 200u32;
2076/// x.mod_square_precomputed_assign(497, &data);
2077/// assert_eq!(x, 240);
2078///
2079/// let mut x = 300u32;
2080/// x.mod_square_precomputed_assign(497, &data);
2081/// assert_eq!(x, 43);
2082/// ```
2083pub mod mod_square;
2084/// [`ModSub`](traits::ModSub) and [`ModSubAssign`](traits::ModSubAssign), traits for subtracting
2085/// two numbers modulo another number.
2086///
2087/// # mod_sub
2088/// ```
2089/// use malachite_base::num::arithmetic::traits::ModSub;
2090///
2091/// assert_eq!(4u8.mod_sub(3, 5), 1);
2092/// assert_eq!(7u32.mod_sub(9, 10), 8);
2093/// ```
2094///
2095/// # mod_sub_assign
2096/// ```
2097/// use malachite_base::num::arithmetic::traits::ModSubAssign;
2098///
2099/// let mut n = 4u8;
2100/// n.mod_sub_assign(3, 5);
2101/// assert_eq!(n, 1);
2102///
2103/// let mut n = 7u32;
2104/// n.mod_sub_assign(9, 10);
2105/// assert_eq!(n, 8);
2106/// ```
2107pub mod mod_sub;
2108/// [`NegAssign`](traits::NegAssign), a trait for negating a number in place.
2109///
2110/// # neg_assign
2111/// ```
2112/// use malachite_base::num::arithmetic::traits::NegAssign;
2113///
2114/// let mut x = 0i8;
2115/// x.neg_assign();
2116/// assert_eq!(x, 0i8);
2117///
2118/// let mut x = 100i64;
2119/// x.neg_assign();
2120/// assert_eq!(x, -100i64);
2121///
2122/// let mut x = -100i64;
2123/// x.neg_assign();
2124/// assert_eq!(x, 100i64);
2125///
2126/// let mut x = 1.2f32;
2127/// x.neg_assign();
2128/// assert_eq!(x, -1.2f32);
2129/// ```
2130pub mod neg;
2131/// [`NextPowerOf2`](traits::NextPowerOf2) and [`NextPowerOf2Assign`](traits::NextPowerOf2Assign),
2132/// traits for getting the next-highest power of 2.
2133///
2134/// # next_power_of_2
2135/// ```
2136/// use malachite_base::num::arithmetic::traits::NextPowerOf2;
2137///
2138/// assert_eq!(100.0f32.next_power_of_2(), 128.0);
2139/// assert_eq!(0.01f32.next_power_of_2(), 0.015625);
2140/// ```
2141///
2142/// # next_power_of_2_assign
2143/// ```
2144/// use malachite_base::num::arithmetic::traits::NextPowerOf2Assign;
2145///
2146/// let mut x = 0u8;
2147/// x.next_power_of_2_assign();
2148/// assert_eq!(x, 1);
2149///
2150/// let mut x = 4u16;
2151/// x.next_power_of_2_assign();
2152/// assert_eq!(x, 4);
2153///
2154/// let mut x = 10u32;
2155/// x.next_power_of_2_assign();
2156/// assert_eq!(x, 16);
2157///
2158/// let mut x = (1u64 << 40) - 5;
2159/// x.next_power_of_2_assign();
2160/// assert_eq!(x, 1 << 40);
2161///
2162/// let mut x = 100.0f32;
2163/// x.next_power_of_2_assign();
2164/// assert_eq!(x, 128.0);
2165///
2166/// let mut x = 0.01f32;
2167/// x.next_power_of_2_assign();
2168/// assert_eq!(x, 0.015625);
2169/// ```
2170pub mod next_power_of_2;
2171/// [`OverflowingAbs`](traits::OverflowingAbs) and
2172/// [`OverflowingAbsAssign`](traits::OverflowingAbsAssign), traits for taking the absolute value of
2173/// a number and returning a boolean indicating whether an overflow occurred.
2174///
2175/// # overflowing_abs_assign
2176/// ```
2177/// use malachite_base::num::arithmetic::traits::OverflowingAbsAssign;
2178///
2179/// let mut x = 0i8;
2180/// assert_eq!(x.overflowing_abs_assign(), false);
2181/// assert_eq!(x, 0);
2182///
2183/// let mut x = 100i64;
2184/// assert_eq!(x.overflowing_abs_assign(), false);
2185/// assert_eq!(x, 100);
2186///
2187/// let mut x = -100i64;
2188/// assert_eq!(x.overflowing_abs_assign(), false);
2189/// assert_eq!(x, 100);
2190///
2191/// let mut x = -128i8;
2192/// assert_eq!(x.overflowing_abs_assign(), true);
2193/// assert_eq!(x, -128);
2194/// ```
2195pub mod overflowing_abs;
2196/// [`OverflowingAdd`](traits::OverflowingAdd) and
2197/// [`OverflowingAddAssign`](traits::OverflowingAddAssign), traits for adding two numbers and
2198/// returning a boolean indicating whether an overflow occurred.
2199///
2200/// # overflowing_add_assign
2201/// ```
2202/// use malachite_base::num::arithmetic::traits::OverflowingAddAssign;
2203///
2204/// let mut x = 123u16;
2205/// assert_eq!(x.overflowing_add_assign(456), false);
2206/// assert_eq!(x, 579);
2207///
2208/// let mut x = 123u8;
2209/// assert_eq!(x.overflowing_add_assign(200), true);
2210/// assert_eq!(x, 67);
2211/// ```
2212pub mod overflowing_add;
2213/// [`OverflowingAddMul`](traits::OverflowingAddMul) and
2214/// [`OverflowingAddMulAssign`](traits::OverflowingAddMulAssign), traits for adding the product of
2215/// two other numbers to a number and returning a boolean indicating whether an overflow occurred.
2216///
2217/// # overflowing_add_mul
2218/// ```
2219/// use malachite_base::num::arithmetic::traits::OverflowingAddMul;
2220///
2221/// assert_eq!(2u8.overflowing_add_mul(3, 7), (23, false));
2222/// assert_eq!(2u8.overflowing_add_mul(20, 20), (146, true));
2223///
2224/// assert_eq!(127i8.overflowing_add_mul(-2, 100), (-73, false));
2225/// assert_eq!((-127i8).overflowing_add_mul(-2, 100), (-71, true));
2226/// ```
2227///
2228/// # overflowing_add_mul_assign
2229/// ```
2230/// use malachite_base::num::arithmetic::traits::OverflowingAddMulAssign;
2231///
2232/// let mut x = 2u8;
2233/// assert_eq!(x.overflowing_add_mul_assign(3, 7), false);
2234/// assert_eq!(x, 23);
2235///
2236/// let mut x = 2u8;
2237/// assert_eq!(x.overflowing_add_mul_assign(20, 20), true);
2238/// assert_eq!(x, 146);
2239///
2240/// let mut x = 127i8;
2241/// assert_eq!(x.overflowing_add_mul_assign(-2, 100), false);
2242/// assert_eq!(x, -73);
2243///
2244/// let mut x = -127i8;
2245/// assert_eq!(x.overflowing_add_mul_assign(-2, 100), true);
2246/// assert_eq!(x, -71);
2247/// ```
2248pub mod overflowing_add_mul;
2249/// [`OverflowingDiv`](traits::OverflowingDiv) and
2250/// [`OverflowingDivAssign`](traits::OverflowingDivAssign), traits for dividing two numbers and
2251/// returning a boolean indicating whether an overflow occurred.
2252///
2253/// # overflowing_div_assign
2254/// ```
2255/// use malachite_base::num::arithmetic::traits::OverflowingDivAssign;
2256///
2257/// let mut x = 100u16;
2258/// assert_eq!(x.overflowing_div_assign(3), false);
2259/// assert_eq!(x, 33);
2260///
2261/// let mut x = -128i8;
2262/// assert_eq!(x.overflowing_div_assign(-1), true);
2263/// assert_eq!(x, -128);
2264/// ```
2265pub mod overflowing_div;
2266/// [`OverflowingMul`](traits::OverflowingMul) and
2267/// [`OverflowingMulAssign`](traits::OverflowingMulAssign), traits for multiplying two numbers and
2268/// returning a boolean indicating whether an overflow occurred.
2269///
2270/// # overflowing_mul_assign
2271/// ```
2272/// use malachite_base::num::arithmetic::traits::OverflowingMulAssign;
2273///
2274/// let mut x = 123u16;
2275/// assert_eq!(x.overflowing_mul_assign(456), false);
2276/// assert_eq!(x, 56088);
2277///
2278/// let mut x = 123u8;
2279/// assert_eq!(x.overflowing_mul_assign(200), true);
2280/// assert_eq!(x, 24);
2281/// ```
2282pub mod overflowing_mul;
2283/// [`OverflowingNeg`](traits::OverflowingNeg) and
2284/// [`OverflowingNegAssign`](traits::OverflowingNegAssign), traits for negating a number and
2285/// returning a boolean indicating whether an overflow occurred.
2286///
2287/// # overflowing_neg_assign
2288/// ```
2289/// use malachite_base::num::arithmetic::traits::OverflowingNegAssign;
2290///
2291/// let mut x = 0i8;
2292/// assert_eq!(x.overflowing_neg_assign(), false);
2293/// assert_eq!(x, 0);
2294///
2295/// let mut x = 100u64;
2296/// assert_eq!(x.overflowing_neg_assign(), true);
2297/// assert_eq!(x, 18446744073709551516);
2298///
2299/// let mut x = -100i64;
2300/// assert_eq!(x.overflowing_neg_assign(), false);
2301/// assert_eq!(x, 100);
2302///
2303/// let mut x = -128i8;
2304/// assert_eq!(x.overflowing_neg_assign(), true);
2305/// assert_eq!(x, -128);
2306/// ```
2307pub mod overflowing_neg;
2308/// [`OverflowingPow`](traits::OverflowingPow) and
2309/// [`OverflowingPowAssign`](traits::OverflowingPowAssign), traits for raising a number to a power
2310/// and returning a boolean indicating whether an overflow occurred.
2311///
2312/// # overflowing_pow_assign
2313/// ```
2314/// use malachite_base::num::arithmetic::traits::OverflowingPowAssign;
2315///
2316/// let mut x = 3u8;
2317/// assert_eq!(x.overflowing_pow_assign(3), false);
2318/// assert_eq!(x, 27);
2319///
2320/// let mut x = -10i32;
2321/// assert_eq!(x.overflowing_pow_assign(9), false);
2322/// assert_eq!(x, -1000000000);
2323///
2324/// let mut x = -10i16;
2325/// assert_eq!(x.overflowing_pow_assign(9), true);
2326/// assert_eq!(x, 13824);
2327/// ```
2328pub mod overflowing_pow;
2329/// [`OverflowingSquare`](traits::OverflowingSquare) and
2330/// [`OverflowingSquareAssign`](traits::OverflowingSquareAssign), traits for squaring a number and
2331/// returning a boolean indicating whether an overflow occurred.
2332///
2333/// # overflowing_square_assign
2334/// ```
2335/// use malachite_base::num::arithmetic::traits::OverflowingSquareAssign;
2336///
2337/// let mut x = 3u8;
2338/// assert_eq!(x.overflowing_square_assign(), false);
2339/// assert_eq!(x, 9);
2340///
2341/// let mut x = -1000i32;
2342/// assert_eq!(x.overflowing_square_assign(), false);
2343/// assert_eq!(x, 1000000);
2344///
2345/// let mut x = 1000u16;
2346/// assert_eq!(x.overflowing_square_assign(), true);
2347/// assert_eq!(x, 16960);
2348/// ```
2349pub mod overflowing_square;
2350/// [`OverflowingSub`](traits::OverflowingSub) and
2351/// [`OverflowingSubAssign`](traits::OverflowingSubAssign), traits for subtracting two numbers and
2352/// returning a boolean indicating whether an overflow occurred.
2353///
2354/// # overflowing_sub
2355/// ```
2356/// use malachite_base::num::arithmetic::traits::OverflowingSquare;
2357///
2358/// assert_eq!(3u8.overflowing_square(), (9, false));
2359/// assert_eq!((-1000i32).overflowing_square(), (1000000, false));
2360/// assert_eq!(1000u16.overflowing_square(), (16960, true));
2361/// ```
2362///
2363/// # overflowing_sub_assign
2364/// ```
2365/// use malachite_base::num::arithmetic::traits::OverflowingSubAssign;
2366///
2367/// let mut x = 456u16;
2368/// assert_eq!(x.overflowing_sub_assign(123), false);
2369/// assert_eq!(x, 333);
2370///
2371/// let mut x = 123u16;
2372/// assert_eq!(x.overflowing_sub_assign(456), true);
2373/// assert_eq!(x, 65203);
2374/// ```
2375pub mod overflowing_sub;
2376/// [`OverflowingSubMul`](traits::OverflowingSubMul) and
2377/// [`OverflowingSubMulAssign`](traits::OverflowingSubMulAssign), traits for subtracting the product
2378/// of two other numbers from a number and returning a boolean indicating whether an overflow
2379/// occurred.
2380///
2381/// # overflowing_sub_mul
2382/// ```
2383/// use malachite_base::num::arithmetic::traits::OverflowingSubMul;
2384///
2385/// assert_eq!(60u8.overflowing_sub_mul(5, 10), (10, false));
2386/// assert_eq!(2u8.overflowing_sub_mul(10, 5), (208, true));
2387///
2388/// assert_eq!(127i8.overflowing_sub_mul(2, 100), (-73, false));
2389/// assert_eq!((-127i8).overflowing_sub_mul(2, 100), (-71, true));
2390/// ```
2391///
2392/// # overflowing_sub_mul_assign
2393/// ```
2394/// use malachite_base::num::arithmetic::traits::OverflowingSubMulAssign;
2395///
2396/// let mut x = 60u8;
2397/// assert_eq!(x.overflowing_sub_mul_assign(5, 10), false);
2398/// assert_eq!(x, 10);
2399///
2400/// let mut x = 2u8;
2401/// assert_eq!(x.overflowing_sub_mul_assign(10, 5), true);
2402/// assert_eq!(x, 208);
2403///
2404/// let mut x = 127i8;
2405/// assert_eq!(x.overflowing_sub_mul_assign(2, 100), false);
2406/// assert_eq!(x, -73);
2407///
2408/// let mut x = -127i8;
2409/// assert_eq!(x.overflowing_sub_mul_assign(2, 100), true);
2410/// assert_eq!(x, -71);
2411/// ```
2412pub mod overflowing_sub_mul;
2413/// [`Parity`](traits::Parity), a trait for determining whether a number is even or odd.
2414///
2415/// # even
2416/// ```
2417/// use malachite_base::num::arithmetic::traits::Parity;
2418///
2419/// assert_eq!(0u8.even(), true);
2420/// assert_eq!((-5i16).even(), false);
2421/// assert_eq!(4u32.even(), true);
2422/// ```
2423///
2424/// # odd
2425/// ```
2426/// use malachite_base::num::arithmetic::traits::Parity;
2427///
2428/// assert_eq!(0u8.odd(), false);
2429/// assert_eq!((-5i16).odd(), true);
2430/// assert_eq!(4u32.odd(), false);
2431/// ```
2432pub mod parity;
2433/// [`Pow`](traits::Pow) and [`PowAssign`](traits::PowAssign), traits for raising a number to a
2434/// power.
2435///
2436/// # pow_assign
2437/// ```
2438/// use malachite_base::num::arithmetic::traits::PowAssign;
2439///
2440/// let mut x = 3u8;
2441/// x.pow_assign(3);
2442/// assert_eq!(x, 27);
2443///
2444/// let mut x = -10i32;
2445/// x.pow_assign(9);
2446/// assert_eq!(x, -1000000000);
2447///
2448/// let mut x = 2.0f32;
2449/// x.pow_assign(5);
2450/// assert_eq!(x, 32.0);
2451///
2452/// let mut x = 2.0f32;
2453/// x.pow_assign(5.0);
2454/// assert_eq!(x, 32.0);
2455/// ```
2456pub mod pow;
2457/// [`PowerOf2`](traits::PowerOf2), a trait for computing a power of 2.
2458///
2459/// # power_of_2
2460/// ```
2461/// use malachite_base::num::arithmetic::traits::PowerOf2;
2462///
2463/// assert_eq!(u16::power_of_2(0), 1);
2464/// assert_eq!(u8::power_of_2(3), 8);
2465/// assert_eq!(u64::power_of_2(40), 1 << 40);
2466///
2467/// assert_eq!(i16::power_of_2(0), 1);
2468/// assert_eq!(i8::power_of_2(3), 8);
2469/// assert_eq!(i64::power_of_2(40), 1 << 40);
2470///
2471/// assert_eq!(f32::power_of_2(0u64), 1.0);
2472/// assert_eq!(f32::power_of_2(3u64), 8.0);
2473/// assert_eq!(f32::power_of_2(-3i64), 0.125);
2474/// ```
2475pub mod power_of_2;
2476/// Traits for computing the primorial and the product of the first $n$ primes. There is a trait
2477/// whose implementations panic if the result cannot be represented, and a checked trait whose
2478/// implementations return `None` in that case: [`Primorial`](traits::Primorial) and
2479/// [`CheckedPrimorial`](traits::CheckedPrimorial).
2480///
2481/// # primorial
2482/// ```
2483/// use malachite_base::num::arithmetic::traits::Primorial;
2484///
2485/// assert_eq!(u8::primorial(0), 1);
2486/// assert_eq!(u8::primorial(1), 1);
2487/// assert_eq!(u8::primorial(2), 2);
2488/// assert_eq!(u8::primorial(3), 6);
2489/// assert_eq!(u8::primorial(4), 6);
2490/// assert_eq!(u8::primorial(5), 30);
2491/// assert_eq!(u32::primorial(20), 9699690);
2492/// ```
2493///
2494/// # product_of_first_n_primes
2495/// ```
2496/// use malachite_base::num::arithmetic::traits::Primorial;
2497///
2498/// assert_eq!(u8::product_of_first_n_primes(0), 1);
2499/// assert_eq!(u8::product_of_first_n_primes(1), 2);
2500/// assert_eq!(u8::product_of_first_n_primes(2), 6);
2501/// assert_eq!(u8::product_of_first_n_primes(3), 30);
2502/// assert_eq!(u8::product_of_first_n_primes(4), 210);
2503/// assert_eq!(u32::product_of_first_n_primes(9), 223092870);
2504/// ```
2505///
2506/// # checked_primorial
2507/// ```
2508/// use malachite_base::num::arithmetic::traits::CheckedPrimorial;
2509///
2510/// assert_eq!(u8::checked_primorial(0), Some(1));
2511/// assert_eq!(u8::checked_primorial(1), Some(1));
2512/// assert_eq!(u8::checked_primorial(2), Some(2));
2513/// assert_eq!(u8::checked_primorial(3), Some(6));
2514/// assert_eq!(u8::checked_primorial(4), Some(6));
2515/// assert_eq!(u8::checked_primorial(5), Some(30));
2516///
2517/// assert_eq!(u8::checked_primorial(11), None);
2518/// assert_eq!(u32::checked_primorial(20), Some(9699690));
2519/// assert_eq!(u32::checked_primorial(100), None);
2520/// ```
2521///
2522/// # checked_product_of_first_n_primes
2523/// ```
2524/// use malachite_base::num::arithmetic::traits::CheckedPrimorial;
2525///
2526/// assert_eq!(u8::checked_product_of_first_n_primes(0), Some(1));
2527/// assert_eq!(u8::checked_product_of_first_n_primes(1), Some(2));
2528/// assert_eq!(u8::checked_product_of_first_n_primes(2), Some(6));
2529/// assert_eq!(u8::checked_product_of_first_n_primes(3), Some(30));
2530/// assert_eq!(u8::checked_product_of_first_n_primes(4), Some(210));
2531/// assert_eq!(u32::checked_product_of_first_n_primes(9), Some(223092870));
2532///
2533/// assert_eq!(u8::checked_product_of_first_n_primes(5), None);
2534/// assert_eq!(u32::checked_product_of_first_n_primes(100), None);
2535/// ```
2536pub mod primorial;
2537/// [`Reciprocal`](traits::Reciprocal) and [`ReciprocalAssign`](traits::ReciprocalAssign), traits
2538/// for computing the reciprocal (multiplicative inverse) of a number.
2539///
2540/// # reciprocal
2541/// ```
2542/// use malachite_base::num::arithmetic::traits::Reciprocal;
2543///
2544/// assert_eq!(0.0f32.reciprocal(), f32::INFINITY);
2545/// assert_eq!(1.5f32.reciprocal(), 0.6666667);
2546/// ```
2547///
2548/// # reciprocal_assign
2549/// ```
2550/// use malachite_base::num::arithmetic::traits::ReciprocalAssign;
2551///
2552/// let mut x = 0.0f32;
2553/// x.reciprocal_assign();
2554/// assert_eq!(x, f32::INFINITY);
2555///
2556/// let mut x = 1.5f32;
2557/// x.reciprocal_assign();
2558/// assert_eq!(x, 0.6666667);
2559/// ```
2560pub mod reciprocal;
2561/// Traits for taking the $n$th root of a number.
2562///
2563/// The traits are [`FloorRoot`](traits::FloorRoot), [`FloorRootAssign`](traits::FloorRootAssign),
2564/// [`CeilingRoot`](traits::CeilingRoot), [`CeilingRootAssign`](traits::CeilingRootAssign),
2565/// [`CheckedRoot`](traits::CheckedRoot), [`RootRem`](traits::RootRem), and
2566/// [`RootAssignRem`](traits::RootAssignRem).
2567///
2568/// # floor_root
2569/// ```
2570/// use malachite_base::num::arithmetic::traits::FloorRoot;
2571///
2572/// assert_eq!(999u16.floor_root(3), 9);
2573/// assert_eq!(1000u16.floor_root(3), 10);
2574/// assert_eq!(1001u16.floor_root(3), 10);
2575/// assert_eq!(100000000000i64.floor_root(5), 158);
2576/// assert_eq!((-100000000000i64).floor_root(5), -159);
2577/// ```
2578///
2579/// # floor_root_assign
2580/// ```
2581/// use malachite_base::num::arithmetic::traits::FloorRootAssign;
2582///
2583/// let mut x = 999u16;
2584/// x.floor_root_assign(3);
2585/// assert_eq!(x, 9);
2586///
2587/// let mut x = 1000u16;
2588/// x.floor_root_assign(3);
2589/// assert_eq!(x, 10);
2590///
2591/// let mut x = 1001u16;
2592/// x.floor_root_assign(3);
2593/// assert_eq!(x, 10);
2594///
2595/// let mut x = 100000000000i64;
2596/// x.floor_root_assign(5);
2597/// assert_eq!(x, 158);
2598///
2599/// let mut x = -100000000000i64;
2600/// x.floor_root_assign(5);
2601/// assert_eq!(x, -159);
2602/// ```
2603///
2604/// # ceiling_root
2605/// ```
2606/// use malachite_base::num::arithmetic::traits::CeilingRoot;
2607///
2608/// assert_eq!(999u16.ceiling_root(3), 10);
2609/// assert_eq!(1000u16.ceiling_root(3), 10);
2610/// assert_eq!(1001u16.ceiling_root(3), 11);
2611/// assert_eq!(100000000000i64.ceiling_root(5), 159);
2612/// assert_eq!((-100000000000i64).ceiling_root(5), -158);
2613/// ```
2614///
2615/// # ceiling_root_assign
2616/// ```
2617/// use malachite_base::num::arithmetic::traits::CeilingRootAssign;
2618///
2619/// let mut x = 999u16;
2620/// x.ceiling_root_assign(3);
2621/// assert_eq!(x, 10);
2622///
2623/// let mut x = 1000u16;
2624/// x.ceiling_root_assign(3);
2625/// assert_eq!(x, 10);
2626///
2627/// let mut x = 1001u16;
2628/// x.ceiling_root_assign(3);
2629/// assert_eq!(x, 11);
2630///
2631/// let mut x = 100000000000i64;
2632/// x.ceiling_root_assign(5);
2633/// assert_eq!(x, 159);
2634///
2635/// let mut x = -100000000000i64;
2636/// x.ceiling_root_assign(5);
2637/// assert_eq!(x, -158);
2638/// ```
2639///
2640/// # checked_root
2641/// ```
2642/// use malachite_base::num::arithmetic::traits::CheckedRoot;
2643///
2644/// assert_eq!(999u16.checked_root(3), None);
2645/// assert_eq!(1000u16.checked_root(3), Some(10));
2646/// assert_eq!(1001u16.checked_root(3), None);
2647/// assert_eq!(100000000000i64.checked_root(5), None);
2648/// assert_eq!((-100000000000i64).checked_root(5), None);
2649/// assert_eq!(10000000000i64.checked_root(5), Some(100));
2650/// assert_eq!((-10000000000i64).checked_root(5), Some(-100));
2651/// ```
2652///
2653/// # root_rem
2654/// ```
2655/// use malachite_base::num::arithmetic::traits::RootRem;
2656///
2657/// assert_eq!(999u16.root_rem(3), (9, 270));
2658/// assert_eq!(1000u16.root_rem(3), (10, 0));
2659/// assert_eq!(1001u16.root_rem(3), (10, 1));
2660/// assert_eq!(100000000000u64.root_rem(5), (158, 1534195232));
2661/// ```
2662///
2663/// # root_assign_rem
2664/// ```
2665/// use malachite_base::num::arithmetic::traits::RootAssignRem;
2666///
2667/// let mut x = 999u16;
2668/// assert_eq!(x.root_assign_rem(3), 270);
2669/// assert_eq!(x, 9);
2670///
2671/// let mut x = 1000u16;
2672/// assert_eq!(x.root_assign_rem(3), 0);
2673/// assert_eq!(x, 10);
2674///
2675/// let mut x = 1001u16;
2676/// assert_eq!(x.root_assign_rem(3), 1);
2677/// assert_eq!(x, 10);
2678///
2679/// let mut x = 100000000000u64;
2680/// assert_eq!(x.root_assign_rem(5), 1534195232);
2681/// assert_eq!(x, 158);
2682/// ```
2683pub mod root;
2684/// [`RotateLeft`](traits::RotateLeft), [`RotateLeftAssign`](traits::RotateLeftAssign),
2685/// [`RotateRight`](traits::RotateRight), and [`RotateRightAssign`](traits::RotateRightAssign),
2686/// traits for rotating a number's bits.
2687///
2688/// # rotate_left_assign
2689/// ```
2690/// use malachite_base::num::arithmetic::traits::RotateLeftAssign;
2691///
2692/// let mut x: u32 = 0xabcd6789;
2693/// x.rotate_left_assign(4);
2694/// assert_eq!(x, 0xbcd6789a);
2695///
2696/// x = 0xabcd6789;
2697/// x.rotate_left_assign(32);
2698/// assert_eq!(x, 0xabcd6789);
2699///
2700/// x = 0xabcd6789;
2701/// x.rotate_left_assign(36);
2702/// assert_eq!(x, 0xbcd6789a);
2703/// ```
2704///
2705/// # rotate_right_assign
2706/// ```
2707/// use malachite_base::num::arithmetic::traits::RotateRightAssign;
2708///
2709/// let mut x: u32 = 0xabcd6789;
2710/// x.rotate_right_assign(4);
2711/// assert_eq!(x, 0x9abcd678);
2712///
2713/// x = 0xabcd6789;
2714/// x.rotate_right_assign(32);
2715/// assert_eq!(x, 0xabcd6789);
2716///
2717/// x = 0xabcd6789;
2718/// x.rotate_right_assign(36);
2719/// assert_eq!(x, 0x9abcd678);
2720/// ```
2721pub mod rotate;
2722/// [`RoundToMultiple`](traits::RoundToMultiple) and
2723/// [`RoundToMultipleAssign`](traits::RoundToMultipleAssign), traits for rounding a number to a
2724/// multiple of another number.
2725///
2726/// # round_to_multiple
2727/// ```
2728/// use malachite_base::num::arithmetic::traits::RoundToMultiple;
2729/// use malachite_base::rounding_modes::RoundingMode::*;
2730/// use std::cmp::Ordering::*;
2731///
2732/// assert_eq!(5u32.round_to_multiple(0, Down), (0, Less));
2733///
2734/// assert_eq!(10u8.round_to_multiple(4, Down), (8, Less));
2735/// assert_eq!(10u16.round_to_multiple(4, Up), (12, Greater));
2736/// assert_eq!(10u32.round_to_multiple(5, Exact), (10, Equal));
2737/// assert_eq!(10u64.round_to_multiple(3, Nearest), (9, Less));
2738/// assert_eq!(20u128.round_to_multiple(3, Nearest), (21, Greater));
2739/// assert_eq!(10usize.round_to_multiple(4, Nearest), (8, Less));
2740/// assert_eq!(14u8.round_to_multiple(4, Nearest), (16, Greater));
2741///
2742/// assert_eq!((-5i32).round_to_multiple(0, Down), (0, Greater));
2743///
2744/// assert_eq!((-10i8).round_to_multiple(4, Down), (-8, Greater));
2745/// assert_eq!((-10i16).round_to_multiple(4, Up), (-12, Less));
2746/// assert_eq!((-10i32).round_to_multiple(5, Exact), (-10, Equal));
2747/// assert_eq!((-10i64).round_to_multiple(3, Nearest), (-9, Greater));
2748/// assert_eq!((-20i128).round_to_multiple(3, Nearest), (-21, Less));
2749/// assert_eq!((-10isize).round_to_multiple(4, Nearest), (-8, Greater));
2750/// assert_eq!((-14i8).round_to_multiple(4, Nearest), (-16, Less));
2751///
2752/// assert_eq!((-10i16).round_to_multiple(-4, Down), (-8, Greater));
2753/// assert_eq!((-10i32).round_to_multiple(-4, Up), (-12, Less));
2754/// assert_eq!((-10i64).round_to_multiple(-5, Exact), (-10, Equal));
2755/// assert_eq!((-10i128).round_to_multiple(-3, Nearest), (-9, Greater));
2756/// assert_eq!((-20isize).round_to_multiple(-3, Nearest), (-21, Less));
2757/// assert_eq!((-10i8).round_to_multiple(-4, Nearest), (-8, Greater));
2758/// assert_eq!((-14i16).round_to_multiple(-4, Nearest), (-16, Less));
2759/// ```
2760///
2761/// # round_to_multiple_assign
2762/// ```
2763/// use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
2764/// use malachite_base::rounding_modes::RoundingMode::*;
2765/// use std::cmp::Ordering::*;
2766///
2767/// let mut x = 5u32;
2768/// assert_eq!(x.round_to_multiple_assign(0, Down), Less);
2769/// assert_eq!(x, 0);
2770///
2771/// let mut x = 10u8;
2772/// assert_eq!(x.round_to_multiple_assign(4, Down), Less);
2773/// assert_eq!(x, 8);
2774///
2775/// let mut x = 10u16;
2776/// assert_eq!(x.round_to_multiple_assign(4, Up), Greater);
2777/// assert_eq!(x, 12);
2778///
2779/// let mut x = 10u32;
2780/// assert_eq!(x.round_to_multiple_assign(5, Exact), Equal);
2781/// assert_eq!(x, 10);
2782///
2783/// let mut x = 10u64;
2784/// assert_eq!(x.round_to_multiple_assign(3, Nearest), Less);
2785/// assert_eq!(x, 9);
2786///
2787/// let mut x = 20u128;
2788/// assert_eq!(x.round_to_multiple_assign(3, Nearest), Greater);
2789/// assert_eq!(x, 21);
2790///
2791/// let mut x = 10usize;
2792/// assert_eq!(x.round_to_multiple_assign(4, Nearest), Less);
2793/// assert_eq!(x, 8);
2794///
2795/// let mut x = 14u8;
2796/// assert_eq!(x.round_to_multiple_assign(4, Nearest), Greater);
2797/// assert_eq!(x, 16);
2798///
2799/// let mut x = -5i32;
2800/// assert_eq!(x.round_to_multiple_assign(0, Down), Greater);
2801/// assert_eq!(x, 0);
2802///
2803/// let mut x = -10i8;
2804/// assert_eq!(x.round_to_multiple_assign(4, Down), Greater);
2805/// assert_eq!(x, -8);
2806///
2807/// let mut x = -10i16;
2808/// assert_eq!(x.round_to_multiple_assign(4, Up), Less);
2809/// assert_eq!(x, -12);
2810///
2811/// let mut x = -10i32;
2812/// assert_eq!(x.round_to_multiple_assign(5, Exact), Equal);
2813/// assert_eq!(x, -10);
2814///
2815/// let mut x = -10i64;
2816/// assert_eq!(x.round_to_multiple_assign(3, Nearest), Greater);
2817/// assert_eq!(x, -9);
2818///
2819/// let mut x = -20i128;
2820/// assert_eq!(x.round_to_multiple_assign(3, Nearest), Less);
2821/// assert_eq!(x, -21);
2822///
2823/// let mut x = -10isize;
2824/// assert_eq!(x.round_to_multiple_assign(4, Nearest), Greater);
2825/// assert_eq!(x, -8);
2826///
2827/// let mut x = -14i8;
2828/// assert_eq!(x.round_to_multiple_assign(4, Nearest), Less);
2829/// assert_eq!(x, -16);
2830///
2831/// let mut x = -10i16;
2832/// assert_eq!(x.round_to_multiple_assign(-4, Down), Greater);
2833/// assert_eq!(x, -8);
2834///
2835/// let mut x = -10i32;
2836/// assert_eq!(x.round_to_multiple_assign(-4, Up), Less);
2837/// assert_eq!(x, -12);
2838///
2839/// let mut x = -10i64;
2840/// assert_eq!(x.round_to_multiple_assign(-5, Exact), Equal);
2841/// assert_eq!(x, -10);
2842///
2843/// let mut x = -10i128;
2844/// assert_eq!(x.round_to_multiple_assign(-3, Nearest), Greater);
2845/// assert_eq!(x, -9);
2846///
2847/// let mut x = -20isize;
2848/// assert_eq!(x.round_to_multiple_assign(-3, Nearest), Less);
2849/// assert_eq!(x, -21);
2850///
2851/// let mut x = -10i8;
2852/// assert_eq!(x.round_to_multiple_assign(-4, Nearest), Greater);
2853/// assert_eq!(x, -8);
2854///
2855/// let mut x = -14i16;
2856/// assert_eq!(x.round_to_multiple_assign(-4, Nearest), Less);
2857/// assert_eq!(x, -16);
2858/// ```
2859pub mod round_to_multiple;
2860/// [`RoundToMultipleOfPowerOf2`](traits::RoundToMultipleOfPowerOf2) and
2861/// [`RoundToMultipleOfPowerOf2Assign`](traits::RoundToMultipleOfPowerOf2Assign), traits for
2862/// rounding a number to a multiple of a power of 2.
2863///
2864/// # round_to_multiple_of_power_of_2
2865/// ```
2866/// use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2;
2867/// use malachite_base::rounding_modes::RoundingMode::*;
2868/// use std::cmp::Ordering::*;
2869///
2870/// assert_eq!(10u8.round_to_multiple_of_power_of_2(2, Floor), (8, Less));
2871/// assert_eq!(
2872///     10u8.round_to_multiple_of_power_of_2(2, Ceiling),
2873///     (12, Greater)
2874/// );
2875/// assert_eq!(10u8.round_to_multiple_of_power_of_2(2, Down), (8, Less));
2876/// assert_eq!(10u8.round_to_multiple_of_power_of_2(2, Up), (12, Greater));
2877/// assert_eq!(10u8.round_to_multiple_of_power_of_2(2, Nearest), (8, Less));
2878/// assert_eq!(12u8.round_to_multiple_of_power_of_2(2, Exact), (12, Equal));
2879///
2880/// assert_eq!(
2881///     (-10i8).round_to_multiple_of_power_of_2(2, Floor),
2882///     (-12, Less)
2883/// );
2884/// assert_eq!(
2885///     (-10i8).round_to_multiple_of_power_of_2(2, Ceiling),
2886///     (-8, Greater)
2887/// );
2888/// assert_eq!(
2889///     (-10i8).round_to_multiple_of_power_of_2(2, Down),
2890///     (-8, Greater)
2891/// );
2892/// assert_eq!((-10i8).round_to_multiple_of_power_of_2(2, Up), (-12, Less));
2893/// assert_eq!(
2894///     (-10i8).round_to_multiple_of_power_of_2(2, Nearest),
2895///     (-8, Greater)
2896/// );
2897/// assert_eq!(
2898///     (-12i8).round_to_multiple_of_power_of_2(2, Exact),
2899///     (-12, Equal)
2900/// );
2901/// ```
2902///
2903/// # round_to_multiple_of_power_of_2_assign
2904/// ```
2905/// use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign;
2906/// use malachite_base::rounding_modes::RoundingMode::*;
2907/// use std::cmp::Ordering::*;
2908///
2909/// let mut x = 10u8;
2910/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Floor), Less);
2911/// assert_eq!(x, 8);
2912///
2913/// let mut x = 10u8;
2914/// assert_eq!(
2915///     x.round_to_multiple_of_power_of_2_assign(2, Ceiling),
2916///     Greater
2917/// );
2918/// assert_eq!(x, 12);
2919///
2920/// let mut x = 10u8;
2921/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Down), Less);
2922/// assert_eq!(x, 8);
2923///
2924/// let mut x = 10u8;
2925/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Up), Greater);
2926/// assert_eq!(x, 12);
2927///
2928/// let mut x = 10u8;
2929/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Nearest), Less);
2930/// assert_eq!(x, 8);
2931///
2932/// let mut x = 12u8;
2933/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Exact), Equal);
2934/// assert_eq!(x, 12);
2935///
2936/// let mut x = -10i8;
2937/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Floor), Less);
2938/// assert_eq!(x, -12);
2939///
2940/// let mut x = -10i8;
2941/// assert_eq!(
2942///     x.round_to_multiple_of_power_of_2_assign(2, Ceiling),
2943///     Greater
2944/// );
2945/// assert_eq!(x, -8);
2946///
2947/// let mut x = -10i8;
2948/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Down), Greater);
2949/// assert_eq!(x, -8);
2950///
2951/// let mut x = -10i8;
2952/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Up), Less);
2953/// assert_eq!(x, -12);
2954///
2955/// let mut x = -10i8;
2956/// assert_eq!(
2957///     x.round_to_multiple_of_power_of_2_assign(2, Nearest),
2958///     Greater
2959/// );
2960/// assert_eq!(x, -8);
2961///
2962/// let mut x = -12i8;
2963/// assert_eq!(x.round_to_multiple_of_power_of_2_assign(2, Exact), Equal);
2964/// assert_eq!(x, -12);
2965/// ```
2966pub mod round_to_multiple_of_power_of_2;
2967/// [`SaturatingAbs`](traits::SaturatingAbs) and
2968/// [`SaturatingAbsAssign`](traits::SaturatingAbsAssign), traits for taking the absolute value of a
2969/// number and saturating at numeric bounds instead of overflowing.
2970///
2971/// # saturating_abs_assign
2972/// ```
2973/// use malachite_base::num::arithmetic::traits::SaturatingAbsAssign;
2974///
2975/// let mut x = 0i8;
2976/// x.saturating_abs_assign();
2977/// assert_eq!(x, 0);
2978///
2979/// let mut x = 100i64;
2980/// x.saturating_abs_assign();
2981/// assert_eq!(x, 100);
2982///
2983/// let mut x = -100i64;
2984/// x.saturating_abs_assign();
2985/// assert_eq!(x, 100);
2986///
2987/// let mut x = -128i8;
2988/// x.saturating_abs_assign();
2989/// assert_eq!(x, 127);
2990/// ```
2991pub mod saturating_abs;
2992/// [`SaturatingAdd`](traits::SaturatingAdd) and
2993/// [`SaturatingAddAssign`](traits::SaturatingAddAssign), traits for adding two numbers and
2994/// saturating at numeric bounds instead of overflowing.
2995///
2996/// # saturating_add_assign
2997/// ```
2998/// use malachite_base::num::arithmetic::traits::SaturatingAddAssign;
2999///
3000/// let mut x = 123u16;
3001/// x.saturating_add_assign(456);
3002/// assert_eq!(x, 579);
3003///
3004/// let mut x = 123u8;
3005/// x.saturating_add_assign(200);
3006/// assert_eq!(x, 255);
3007/// ```
3008pub mod saturating_add;
3009/// [`SaturatingAddMul`](traits::SaturatingAddMul) and
3010/// [`SaturatingAddMulAssign`](traits::SaturatingAddMulAssign), traits for adding the product of two
3011/// numbers to a number and saturating at numeric bounds instead of overflowing.
3012///
3013/// # saturating_add_mul
3014/// ```
3015/// use malachite_base::num::arithmetic::traits::SaturatingAddMul;
3016///
3017/// assert_eq!(2u8.saturating_add_mul(3, 7), 23);
3018/// assert_eq!(2u8.saturating_add_mul(20, 20), 255);
3019///
3020/// assert_eq!(127i8.saturating_add_mul(-2, 100), -73);
3021/// assert_eq!((-127i8).saturating_add_mul(-2, 100), -128);
3022/// ```
3023///
3024/// # saturating_add_mul_assign
3025/// ```
3026/// use malachite_base::num::arithmetic::traits::SaturatingAddMulAssign;
3027///
3028/// let mut x = 2u8;
3029/// x.saturating_add_mul_assign(3, 7);
3030/// assert_eq!(x, 23);
3031///
3032/// let mut x = 2u8;
3033/// x.saturating_add_mul_assign(20, 20);
3034/// assert_eq!(x, 255);
3035///
3036/// let mut x = 127i8;
3037/// x.saturating_add_mul_assign(-2, 100);
3038/// assert_eq!(x, -73);
3039///
3040/// let mut x = -127i8;
3041/// x.saturating_add_mul_assign(-2, 100);
3042/// assert_eq!(x, -128);
3043/// ```
3044pub mod saturating_add_mul;
3045/// [`SaturatingMul`](traits::SaturatingMul) and
3046/// [`SaturatingMulAssign`](traits::SaturatingMulAssign), traits for multiplying two numbers and
3047/// saturating at numeric bounds instead of overflowing.
3048///
3049/// # saturating_mul_assign
3050/// ```
3051/// use malachite_base::num::arithmetic::traits::SaturatingMulAssign;
3052///
3053/// let mut x = 123u16;
3054/// x.saturating_mul_assign(456);
3055/// assert_eq!(x, 56088);
3056///
3057/// let mut x = 123u8;
3058/// x.saturating_mul_assign(200);
3059/// assert_eq!(x, 255);
3060/// ```
3061pub mod saturating_mul;
3062/// [`SaturatingNeg`](traits::SaturatingNeg) and
3063/// [`SaturatingNegAssign`](traits::SaturatingNegAssign), traits for negating a number and
3064/// saturating at numeric bounds instead of overflowing.
3065///
3066/// # saturating_neg_assign
3067/// ```
3068/// use malachite_base::num::arithmetic::traits::SaturatingNegAssign;
3069///
3070/// let mut x = 0i8;
3071/// x.saturating_neg_assign();
3072/// assert_eq!(x, 0);
3073///
3074/// let mut x = 100i64;
3075/// x.saturating_neg_assign();
3076/// assert_eq!(x, -100);
3077///
3078/// let mut x = -100i64;
3079/// x.saturating_neg_assign();
3080/// assert_eq!(x, 100);
3081///
3082/// let mut x = -128i8;
3083/// x.saturating_neg_assign();
3084/// assert_eq!(x, 127);
3085/// ```
3086pub mod saturating_neg;
3087/// [`SaturatingPow`](traits::SaturatingPow) and
3088/// [`SaturatingPowAssign`](traits::SaturatingPowAssign), traits for raising a number to a power and
3089/// saturating at numeric bounds instead of overflowing.
3090///
3091/// # saturating_pow_assign
3092/// ```
3093/// use malachite_base::num::arithmetic::traits::SaturatingPowAssign;
3094///
3095/// let mut x = 3u8;
3096/// x.saturating_pow_assign(3);
3097/// assert_eq!(x, 27);
3098///
3099/// let mut x = -10i32;
3100/// x.saturating_pow_assign(9);
3101/// assert_eq!(x, -1000000000);
3102///
3103/// let mut x = -10i16;
3104/// x.saturating_pow_assign(9);
3105/// assert_eq!(x, -32768);
3106/// ```
3107pub mod saturating_pow;
3108/// [`SaturatingSquare`](traits::SaturatingSquare) and
3109/// [`SaturatingSquareAssign`](traits::SaturatingSquareAssign), traits for squaring a number and
3110/// saturating at numeric bounds instead of overflowing.
3111///
3112/// # saturating_square
3113/// ```
3114/// use malachite_base::num::arithmetic::traits::SaturatingSquare;
3115///
3116/// assert_eq!(3u8.saturating_square(), 9);
3117/// assert_eq!((-1000i32).saturating_square(), 1000000);
3118/// assert_eq!(1000u16.saturating_square(), u16::MAX);
3119/// ```
3120///
3121/// # saturating_square_assign
3122/// ```
3123/// use malachite_base::num::arithmetic::traits::SaturatingSquareAssign;
3124///
3125/// let mut x = 3u8;
3126/// x.saturating_square_assign();
3127/// assert_eq!(x, 9);
3128///
3129/// let mut x = -1000i32;
3130/// x.saturating_square_assign();
3131/// assert_eq!(x, 1000000);
3132///
3133/// let mut x = 1000u16;
3134/// x.saturating_square_assign();
3135/// assert_eq!(x, u16::MAX);
3136/// ```
3137pub mod saturating_square;
3138/// [`SaturatingSub`](traits::SaturatingSub) and
3139/// [`SaturatingSubAssign`](traits::SaturatingSubAssign), traits for subtracting two numbers and
3140/// saturating at numeric bounds instead of overflowing.
3141///
3142/// # saturating_sub_assign
3143/// ```
3144/// use malachite_base::num::arithmetic::traits::SaturatingSubAssign;
3145///
3146/// let mut x = 456u16;
3147/// x.saturating_sub_assign(123);
3148/// assert_eq!(x, 333);
3149///
3150/// let mut x = 123u16;
3151/// x.saturating_sub_assign(456);
3152/// assert_eq!(x, 0);
3153/// ```
3154pub mod saturating_sub;
3155/// [`SaturatingSubMul`](traits::SaturatingSubMul) and
3156/// [`SaturatingSubMulAssign`](traits::SaturatingSubMulAssign), traits for subtracting a number by
3157/// the product of two numbers and saturating at numeric bounds instead of overflowing.
3158///
3159/// # saturating_sub_mul
3160/// ```
3161/// use malachite_base::num::arithmetic::traits::SaturatingSubMul;
3162///
3163/// assert_eq!(60u8.saturating_sub_mul(5, 10), 10);
3164/// assert_eq!(2u8.saturating_sub_mul(10, 5), 0);
3165///
3166/// assert_eq!(127i8.saturating_sub_mul(2, 100), -73);
3167/// assert_eq!((-127i8).saturating_sub_mul(2, 100), -128);
3168/// ```
3169///
3170/// # saturating_sub_mul_assign
3171/// ```
3172/// use malachite_base::num::arithmetic::traits::SaturatingSubMulAssign;
3173///
3174/// let mut x = 60u8;
3175/// x.saturating_sub_mul_assign(5, 10);
3176/// assert_eq!(x, 10);
3177///
3178/// let mut x = 2u8;
3179/// x.saturating_sub_mul_assign(10, 5);
3180/// assert_eq!(x, 0);
3181///
3182/// let mut x = 127i8;
3183/// x.saturating_sub_mul_assign(2, 100);
3184/// assert_eq!(x, -73);
3185///
3186/// let mut x = -127i8;
3187/// x.saturating_sub_mul_assign(2, 100);
3188/// assert_eq!(x, -128);
3189/// ```
3190pub mod saturating_sub_mul;
3191/// [`ShlRound`](traits::ShlRound) and [`ShlRoundAssign`](traits::ShlRoundAssign), traits for
3192/// multiplying a number by a power of 2 and rounding according to a specified
3193/// [`RoundingMode`](crate::rounding_modes::RoundingMode).
3194///
3195/// # shl_round
3196/// ```
3197/// use malachite_base::num::arithmetic::traits::ShlRound;
3198/// use malachite_base::rounding_modes::RoundingMode::*;
3199/// use std::cmp::Ordering::*;
3200///
3201/// assert_eq!(0x101u16.shl_round(-8i8, Down), (1, Less));
3202/// assert_eq!(0x101u32.shl_round(-8i16, Up), (2, Greater));
3203///
3204/// assert_eq!((-0x101i16).shl_round(-9i32, Down), (0, Greater));
3205/// assert_eq!((-0x101i32).shl_round(-9i64, Up), (-1, Less));
3206/// assert_eq!((-0x101i64).shl_round(-9i8, Nearest), (-1, Less));
3207/// assert_eq!((-0xffi32).shl_round(-9i16, Nearest), (0, Greater));
3208/// assert_eq!((-0x100i16).shl_round(-9i32, Nearest), (0, Greater));
3209///
3210/// assert_eq!(0x100u64.shl_round(-8i64, Exact), (1, Equal));
3211/// ```
3212///
3213/// # shl_round_assign
3214/// ```
3215/// use malachite_base::num::arithmetic::traits::ShlRoundAssign;
3216/// use malachite_base::rounding_modes::RoundingMode::*;
3217/// use std::cmp::Ordering::*;
3218///
3219/// let mut x = 0x101u16;
3220/// assert_eq!(x.shl_round_assign(-8i8, Down), Less);
3221/// assert_eq!(x, 1);
3222///
3223/// let mut x = 0x101u32;
3224/// assert_eq!(x.shl_round_assign(-8i16, Up), Greater);
3225/// assert_eq!(x, 2);
3226///
3227/// let mut x = -0x101i16;
3228/// assert_eq!(x.shl_round_assign(-9i32, Down), Greater);
3229/// assert_eq!(x, 0);
3230///
3231/// let mut x = -0x101i32;
3232/// assert_eq!(x.shl_round_assign(-9i64, Up), Less);
3233/// assert_eq!(x, -1);
3234///
3235/// let mut x = -0x101i64;
3236/// assert_eq!(x.shl_round_assign(-9i8, Nearest), Less);
3237/// assert_eq!(x, -1);
3238///
3239/// let mut x = -0xffi32;
3240/// assert_eq!(x.shl_round_assign(-9i16, Nearest), Greater);
3241/// assert_eq!(x, 0);
3242///
3243/// let mut x = -0x100i16;
3244/// assert_eq!(x.shl_round_assign(-9i32, Nearest), Greater);
3245/// assert_eq!(x, 0);
3246///
3247/// let mut x = 0x100u64;
3248/// assert_eq!(x.shl_round_assign(-8i64, Exact), Equal);
3249/// assert_eq!(x, 1);
3250/// ```
3251pub mod shl_round;
3252/// [`ShrRound`](traits::ShrRound) and [`ShrRoundAssign`](traits::ShrRoundAssign), traits for
3253/// dividing a number by a power of 2 and rounding according to a specified
3254/// [`RoundingMode`](crate::rounding_modes::RoundingMode).
3255///
3256/// # shr_round
3257/// ```
3258/// use malachite_base::num::arithmetic::traits::ShrRound;
3259/// use malachite_base::rounding_modes::RoundingMode::*;
3260/// use std::cmp::Ordering::*;
3261///
3262/// assert_eq!(0x101u32.shr_round(8u8, Down), (1, Less));
3263/// assert_eq!(0x101u16.shr_round(8u16, Up), (2, Greater));
3264///
3265/// assert_eq!(0x101u64.shr_round(9u32, Down), (0, Less));
3266/// assert_eq!(0x101u32.shr_round(9u64, Up), (1, Greater));
3267/// assert_eq!(0x101u16.shr_round(9u8, Nearest), (1, Greater));
3268/// assert_eq!(0xffu8.shr_round(9u16, Nearest), (0, Less));
3269/// assert_eq!(0x100u32.shr_round(9u32, Nearest), (0, Less));
3270///
3271/// assert_eq!(0x100u32.shr_round(8u64, Exact), (1, Equal));
3272///
3273/// assert_eq!(0x101i32.shr_round(8u8, Down), (1, Less));
3274/// assert_eq!(0x101i16.shr_round(8u16, Up), (2, Greater));
3275///
3276/// assert_eq!((-0x101i32).shr_round(9u32, Down), (0, Greater));
3277/// assert_eq!((-0x101i64).shr_round(9u64, Up), (-1, Less));
3278/// assert_eq!((-0x101i16).shr_round(9u8, Nearest), (-1, Less));
3279/// assert_eq!((-0xffi32).shr_round(9u16, Nearest), (0, Greater));
3280/// assert_eq!((-0x100i64).shr_round(9u32, Nearest), (0, Greater));
3281///
3282/// assert_eq!(0x100i32.shr_round(8u64, Exact), (1, Equal));
3283///
3284/// assert_eq!(0x101u32.shr_round(8i8, Down), (1, Less));
3285/// assert_eq!(0x101u16.shr_round(8i16, Up), (2, Greater));
3286///
3287/// assert_eq!((-0x101i32).shr_round(9i32, Down), (0, Greater));
3288/// assert_eq!((-0x101i64).shr_round(9i64, Up), (-1, Less));
3289/// assert_eq!((-0x101i16).shr_round(9i8, Nearest), (-1, Less));
3290/// assert_eq!((-0xffi32).shr_round(9i16, Nearest), (0, Greater));
3291/// assert_eq!((-0x100i64).shr_round(9i32, Nearest), (0, Greater));
3292///
3293/// assert_eq!(0x100u32.shr_round(8i64, Exact), (1, Equal));
3294/// ```
3295///
3296/// # shr_round_assign
3297/// ```
3298/// use malachite_base::num::arithmetic::traits::ShrRoundAssign;
3299/// use malachite_base::rounding_modes::RoundingMode::*;
3300/// use std::cmp::Ordering::*;
3301///
3302/// let mut x = 0x101u32;
3303/// assert_eq!(x.shr_round_assign(8u8, Down), Less);
3304/// assert_eq!(x, 1);
3305///
3306/// let mut x = 0x101u16;
3307/// assert_eq!(x.shr_round_assign(8u16, Up), Greater);
3308/// assert_eq!(x, 2);
3309///
3310/// let mut x = 0x101u64;
3311/// assert_eq!(x.shr_round_assign(9u32, Down), Less);
3312/// assert_eq!(x, 0);
3313///
3314/// let mut x = 0x101u32;
3315/// assert_eq!(x.shr_round_assign(9u64, Up), Greater);
3316/// assert_eq!(x, 1);
3317///
3318/// let mut x = 0x101u16;
3319/// assert_eq!(x.shr_round_assign(9u8, Nearest), Greater);
3320/// assert_eq!(x, 1);
3321///
3322/// let mut x = 0xffu8;
3323/// assert_eq!(x.shr_round_assign(9u16, Nearest), Less);
3324/// assert_eq!(x, 0);
3325///
3326/// let mut x = 0x100u32;
3327/// assert_eq!(x.shr_round_assign(9u32, Nearest), Less);
3328/// assert_eq!(x, 0);
3329///
3330/// let mut x = 0x100u32;
3331/// assert_eq!(x.shr_round_assign(8u64, Exact), Equal);
3332/// assert_eq!(x, 1);
3333///
3334/// let mut x = 0x101i32;
3335/// assert_eq!(x.shr_round_assign(8u8, Down), Less);
3336/// assert_eq!(x, 1);
3337///
3338/// let mut x = 0x101i16;
3339/// assert_eq!(x.shr_round_assign(8u16, Up), Greater);
3340/// assert_eq!(x, 2);
3341///
3342/// let mut x = -0x101i32;
3343/// assert_eq!(x.shr_round_assign(9u32, Down), Greater);
3344/// assert_eq!(x, 0);
3345///
3346/// let mut x = -0x101i64;
3347/// assert_eq!(x.shr_round_assign(9u64, Up), Less);
3348/// assert_eq!(x, -1);
3349///
3350/// let mut x = -0x101i16;
3351/// assert_eq!(x.shr_round_assign(9u8, Nearest), Less);
3352/// assert_eq!(x, -1);
3353///
3354/// let mut x = -0xffi32;
3355/// assert_eq!(x.shr_round_assign(9u16, Nearest), Greater);
3356/// assert_eq!(x, 0);
3357///
3358/// let mut x = -0x100i64;
3359/// assert_eq!(x.shr_round_assign(9u32, Nearest), Greater);
3360/// assert_eq!(x, 0);
3361///
3362/// let mut x = 0x100u32;
3363/// assert_eq!(x.shr_round_assign(8i64, Exact), Equal);
3364/// assert_eq!(x, 1);
3365///
3366/// let mut x = 0x101u32;
3367/// assert_eq!(x.shr_round_assign(8i8, Down), Less);
3368/// assert_eq!(x, 1);
3369///
3370/// let mut x = 0x101u16;
3371/// assert_eq!(x.shr_round_assign(8i16, Up), Greater);
3372/// assert_eq!(x, 2);
3373///
3374/// let mut x = -0x101i32;
3375/// assert_eq!(x.shr_round_assign(9i32, Down), Greater);
3376/// assert_eq!(x, 0);
3377///
3378/// let mut x = -0x101i64;
3379/// assert_eq!(x.shr_round_assign(9i64, Up), Less);
3380/// assert_eq!(x, -1);
3381///
3382/// let mut x = -0x101i16;
3383/// assert_eq!(x.shr_round_assign(9i8, Nearest), Less);
3384/// assert_eq!(x, -1);
3385///
3386/// let mut x = -0xffi32;
3387/// assert_eq!(x.shr_round_assign(9i16, Nearest), Greater);
3388/// assert_eq!(x, 0);
3389///
3390/// let mut x = -0x100i64;
3391/// assert_eq!(x.shr_round_assign(9i32, Nearest), Greater);
3392/// assert_eq!(x, 0);
3393///
3394/// let mut x = 0x100u32;
3395/// assert_eq!(x.shr_round_assign(8i64, Exact), Equal);
3396/// assert_eq!(x, 1);
3397/// ```
3398pub mod shr_round;
3399/// [`Sign`](traits::Sign), a trait for determining the sign of a number.
3400///
3401/// # sign
3402/// ```
3403/// use malachite_base::num::arithmetic::traits::Sign;
3404/// use malachite_base::num::basic::traits::NegativeInfinity;
3405/// use std::cmp::Ordering::*;
3406///
3407/// assert_eq!(0u8.sign(), Equal);
3408/// assert_eq!(100u64.sign(), Greater);
3409/// assert_eq!((-100i16).sign(), Less);
3410///
3411/// assert_eq!(0.0.sign(), Greater);
3412/// assert_eq!(1.0.sign(), Greater);
3413/// assert_eq!(f64::INFINITY.sign(), Greater);
3414///
3415/// assert_eq!((-0.0).sign(), Less);
3416/// assert_eq!((-1.0).sign(), Less);
3417/// assert_eq!(f64::NEGATIVE_INFINITY.sign(), Less);
3418///
3419/// assert_eq!(f64::NAN.sign(), Equal);
3420/// ```
3421pub mod sign;
3422/// Traits for taking the square root of a number.
3423///
3424/// The traits are [`FloorSqrt`](traits::FloorSqrt), [`FloorSqrtAssign`](traits::FloorSqrtAssign),
3425/// [`CeilingSqrt`](traits::CeilingSqrt), [`CeilingSqrtAssign`](traits::CeilingSqrtAssign),
3426/// [`CheckedSqrt`](traits::CheckedSqrt), [`SqrtRem`](traits::SqrtRem),
3427/// [`SqrtAssignRem`](traits::SqrtAssignRem), and [`SqrtAssign`](traits::SqrtAssign).
3428///
3429/// # floor_sqrt
3430/// ```
3431/// use malachite_base::num::arithmetic::traits::FloorSqrt;
3432///
3433/// assert_eq!(99u8.floor_sqrt(), 9);
3434/// assert_eq!(100u8.floor_sqrt(), 10);
3435/// assert_eq!(101u8.floor_sqrt(), 10);
3436/// assert_eq!(1000000000i32.floor_sqrt(), 31622);
3437/// assert_eq!(10000000000i64.floor_sqrt(), 100000);
3438/// ```
3439///
3440/// # floor_sqrt_assign
3441/// ```
3442/// use malachite_base::num::arithmetic::traits::FloorSqrtAssign;
3443///
3444/// let mut x = 99u8;
3445/// x.floor_sqrt_assign();
3446/// assert_eq!(x, 9);
3447///
3448/// let mut x = 100u8;
3449/// x.floor_sqrt_assign();
3450/// assert_eq!(x, 10);
3451///
3452/// let mut x = 101u8;
3453/// x.floor_sqrt_assign();
3454/// assert_eq!(x, 10);
3455///
3456/// let mut x = 1000000000i32;
3457/// x.floor_sqrt_assign();
3458/// assert_eq!(x, 31622);
3459///
3460/// let mut x = 10000000000i64;
3461/// x.floor_sqrt_assign();
3462/// assert_eq!(x, 100000);
3463/// ```
3464///
3465/// # ceiling_sqrt
3466/// ```
3467/// use malachite_base::num::arithmetic::traits::CeilingSqrt;
3468///
3469/// assert_eq!(99u8.ceiling_sqrt(), 10);
3470/// assert_eq!(100u8.ceiling_sqrt(), 10);
3471/// assert_eq!(101u8.ceiling_sqrt(), 11);
3472/// assert_eq!(1000000000u32.ceiling_sqrt(), 31623);
3473/// assert_eq!(10000000000u64.ceiling_sqrt(), 100000);
3474/// ```
3475///
3476/// # ceiling_sqrt_assign
3477/// ```
3478/// use malachite_base::num::arithmetic::traits::CeilingSqrtAssign;
3479///
3480/// let mut x = 99u8;
3481/// x.ceiling_sqrt_assign();
3482/// assert_eq!(x, 10);
3483///
3484/// let mut x = 100u8;
3485/// x.ceiling_sqrt_assign();
3486/// assert_eq!(x, 10);
3487///
3488/// let mut x = 101u8;
3489/// x.ceiling_sqrt_assign();
3490/// assert_eq!(x, 11);
3491///
3492/// let mut x = 1000000000i32;
3493/// x.ceiling_sqrt_assign();
3494/// assert_eq!(x, 31623);
3495///
3496/// let mut x = 10000000000i64;
3497/// x.ceiling_sqrt_assign();
3498/// assert_eq!(x, 100000);
3499/// ```
3500///
3501/// # checked_sqrt
3502/// ```
3503/// use malachite_base::num::arithmetic::traits::CheckedSqrt;
3504///
3505/// assert_eq!(99u8.checked_sqrt(), None);
3506/// assert_eq!(100u8.checked_sqrt(), Some(10));
3507/// assert_eq!(101u8.checked_sqrt(), None);
3508/// assert_eq!(1000000000i32.checked_sqrt(), None);
3509/// assert_eq!(10000000000i64.checked_sqrt(), Some(100000));
3510/// ```
3511///
3512/// # sqrt_rem
3513/// ```
3514/// use malachite_base::num::arithmetic::traits::SqrtRem;
3515///
3516/// assert_eq!(99u8.sqrt_rem(), (9, 18));
3517/// assert_eq!(100u8.sqrt_rem(), (10, 0));
3518/// assert_eq!(101u8.sqrt_rem(), (10, 1));
3519/// assert_eq!(1000000000u32.sqrt_rem(), (31622, 49116));
3520/// assert_eq!(10000000000u64.sqrt_rem(), (100000, 0));
3521/// ```
3522///
3523/// # sqrt_assign_rem
3524/// ```
3525/// use malachite_base::num::arithmetic::traits::SqrtAssignRem;
3526///
3527/// let mut x = 99u8;
3528/// assert_eq!(x.sqrt_assign_rem(), 18);
3529/// assert_eq!(x, 9);
3530///
3531/// let mut x = 100u8;
3532/// assert_eq!(x.sqrt_assign_rem(), 0);
3533/// assert_eq!(x, 10);
3534///
3535/// let mut x = 101u8;
3536/// assert_eq!(x.sqrt_assign_rem(), 1);
3537/// assert_eq!(x, 10);
3538///
3539/// let mut x = 1000000000u32;
3540/// assert_eq!(x.sqrt_assign_rem(), 49116);
3541/// assert_eq!(x, 31622);
3542///
3543/// let mut x = 10000000000u64;
3544/// assert_eq!(x.sqrt_assign_rem(), 0);
3545/// assert_eq!(x, 100000);
3546/// ```
3547///
3548/// # sqrt_assign
3549/// ```
3550/// use malachite_base::num::arithmetic::traits::SqrtAssign;
3551/// use malachite_base::num::float::NiceFloat;
3552///
3553/// let mut x = 4.0f64;
3554/// x.sqrt_assign();
3555/// assert_eq!(NiceFloat(x), NiceFloat(2.0));
3556///
3557/// let mut x = 2.0f64;
3558/// x.sqrt_assign();
3559/// assert_eq!(NiceFloat(x), NiceFloat(std::f64::consts::SQRT_2));
3560/// ```
3561pub mod sqrt;
3562/// [`Square`](traits::Square) and [`SquareAssign`](traits::SquareAssign), traits for squaring a
3563/// number.
3564///
3565/// # square
3566/// ```
3567/// use malachite_base::num::arithmetic::traits::Square;
3568///
3569/// assert_eq!(3u8.square(), 9);
3570/// assert_eq!((-1000i32).square(), 1000000);
3571/// assert_eq!(1.5f32.square(), 2.25);
3572/// ```
3573///
3574/// # square_assign
3575/// ```
3576/// use malachite_base::num::arithmetic::traits::SquareAssign;
3577///
3578/// let mut x = 3u8;
3579/// x.square_assign();
3580/// assert_eq!(x, 9);
3581///
3582/// let mut x = -1000i32;
3583/// x.square_assign();
3584/// assert_eq!(x, 1000000);
3585///
3586/// let mut x = 1.5f32;
3587/// x.square_assign();
3588/// assert_eq!(x, 2.25);
3589/// ```
3590pub mod square;
3591/// [`SubMul`](traits::SubMul) and [`SubMulAssign`](traits::SubMulAssign), traits for subtracting
3592/// the product of two numbers from a number.
3593///
3594/// # sub_mul
3595/// ```
3596/// use malachite_base::num::arithmetic::traits::SubMul;
3597///
3598/// assert_eq!(60u32.sub_mul(5, 10), 10);
3599/// assert_eq!(127i8.sub_mul(2, 100), -73);
3600/// assert_eq!(1.0f32.sub_mul(2.0, 3.0), -5.0);
3601/// ```
3602///
3603/// # sub_mul_assign
3604/// ```
3605/// use malachite_base::num::arithmetic::traits::SubMulAssign;
3606///
3607/// let mut x = 60u32;
3608/// x.sub_mul_assign(5, 10);
3609/// assert_eq!(x, 10);
3610///
3611/// let mut x = 127i8;
3612/// x.sub_mul_assign(2, 100);
3613/// assert_eq!(x, -73);
3614///
3615/// let mut x = 1.0f32;
3616/// x.sub_mul_assign(2.0, 3.0);
3617/// assert_eq!(x, -5.0);
3618/// ```
3619pub mod sub_mul;
3620/// Various traits for performing arithmetic operations on numbers.
3621pub mod traits;
3622/// [`WrappingAbs`](traits::WrappingAbs) and [`WrappingAbsAssign`](traits::WrappingAbsAssign),
3623/// traits for computing the absolute value of a number and wrapping at the boundary of the type.
3624///
3625/// # wrapping_abs_assign
3626/// ```
3627/// use malachite_base::num::arithmetic::traits::WrappingAbsAssign;
3628///
3629/// let mut x = 0i8;
3630/// x.wrapping_abs_assign();
3631/// assert_eq!(x, 0);
3632///
3633/// let mut x = 100i64;
3634/// x.wrapping_abs_assign();
3635/// assert_eq!(x, 100);
3636///
3637/// let mut x = -100i64;
3638/// x.wrapping_abs_assign();
3639/// assert_eq!(x, 100);
3640///
3641/// let mut x = -128i8;
3642/// x.wrapping_abs_assign();
3643/// assert_eq!(x, -128);
3644/// ```
3645pub mod wrapping_abs;
3646/// [`WrappingAdd`](traits::WrappingAdd) and [`WrappingAddAssign`](traits::WrappingAddAssign),
3647/// traits for adding two numbers and wrapping at the boundary of the type.
3648///
3649/// # wrapping_add_assign
3650/// ```
3651/// use malachite_base::num::arithmetic::traits::WrappingAddAssign;
3652///
3653/// let mut x = 123u16;
3654/// x.wrapping_add_assign(456);
3655/// assert_eq!(x, 579);
3656///
3657/// let mut x = 123u8;
3658/// x.wrapping_add_assign(200);
3659/// assert_eq!(x, 67);
3660/// ```
3661pub mod wrapping_add;
3662/// [`WrappingAddMul`](traits::WrappingAddMul) and
3663/// [`WrappingAddMulAssign`](traits::WrappingAddMulAssign), traits for adding the product of two
3664/// numbers to a third and wrapping at the boundary of the type.
3665///
3666/// # wrapping_add_mul
3667/// ```
3668/// use malachite_base::num::arithmetic::traits::WrappingAddMul;
3669///
3670/// assert_eq!(2u8.wrapping_add_mul(3, 7), 23);
3671/// assert_eq!((-127i8).wrapping_add_mul(-2, 100), -71);
3672/// ```
3673///
3674/// # wrapping_add_mul_assign
3675/// ```
3676/// use malachite_base::num::arithmetic::traits::WrappingAddMulAssign;
3677///
3678/// let mut x = 2u8;
3679/// x.wrapping_add_mul_assign(3, 7);
3680/// assert_eq!(x, 23);
3681///
3682/// let mut x = -127i8;
3683/// x.wrapping_add_mul_assign(-2, 100);
3684/// assert_eq!(x, -71);
3685/// ```
3686pub mod wrapping_add_mul;
3687/// [`WrappingDiv`](traits::WrappingDiv) and [`WrappingDivAssign`](traits::WrappingDivAssign),
3688/// traits for dividing two numbers and wrapping at the boundary of the type.
3689///
3690/// # wrapping_div_assign
3691/// ```
3692/// use malachite_base::num::arithmetic::traits::WrappingDivAssign;
3693///
3694/// let mut x = 100u16;
3695/// x.wrapping_div_assign(3);
3696/// assert_eq!(x, 33);
3697///
3698/// let mut x = -128i8;
3699/// x.wrapping_div_assign(-1);
3700/// assert_eq!(x, -128);
3701/// ```
3702pub mod wrapping_div;
3703/// [`WrappingMul`](traits::WrappingMul) and [`WrappingMulAssign`](traits::WrappingMulAssign),
3704/// traits for multiplying two numbers and wrapping at the boundary of the type.
3705///
3706/// # wrapping_mul_assign
3707/// ```
3708/// use malachite_base::num::arithmetic::traits::WrappingMulAssign;
3709///
3710/// let mut x = 123u16;
3711/// x.wrapping_mul_assign(456);
3712/// assert_eq!(x, 56088);
3713///
3714/// let mut x = 123u8;
3715/// x.wrapping_mul_assign(200);
3716/// assert_eq!(x, 24);
3717/// ```
3718pub mod wrapping_mul;
3719/// [`WrappingNeg`](traits::WrappingNeg) and [`WrappingNegAssign`](traits::WrappingNegAssign) for
3720/// negating a number and wrapping at the boundary of the type.
3721///
3722/// # wrapping_neg_assign
3723/// ```
3724/// use malachite_base::num::arithmetic::traits::WrappingNegAssign;
3725///
3726/// let mut x = 0i8;
3727/// x.wrapping_neg_assign();
3728/// assert_eq!(x, 0);
3729///
3730/// let mut x = 100u64;
3731/// x.wrapping_neg_assign();
3732/// assert_eq!(x, 18446744073709551516);
3733///
3734/// let mut x = -100i64;
3735/// x.wrapping_neg_assign();
3736/// assert_eq!(x, 100);
3737///
3738/// let mut x = -128i8;
3739/// x.wrapping_neg_assign();
3740/// assert_eq!(x, -128);
3741/// ```
3742pub mod wrapping_neg;
3743/// [`WrappingPow`](traits::WrappingPow) and [`WrappingPowAssign`](traits::WrappingPowAssign),
3744/// traits for raising a number to a power and wrapping at the boundary of the type.
3745///
3746/// # wrapping_pow_assign
3747/// ```
3748/// use malachite_base::num::arithmetic::traits::WrappingPowAssign;
3749///
3750/// let mut x = 3u8;
3751/// x.wrapping_pow_assign(3);
3752/// assert_eq!(x, 27);
3753///
3754/// let mut x = -10i32;
3755/// x.wrapping_pow_assign(9);
3756/// assert_eq!(x, -1000000000);
3757///
3758/// let mut x = -10i16;
3759/// x.wrapping_pow_assign(9);
3760/// assert_eq!(x, 13824);
3761/// ```
3762pub mod wrapping_pow;
3763/// [`WrappingSquare`](traits::WrappingSquare) and
3764/// [`WrappingSquareAssign`](traits::WrappingAbsAssign), traits for squaring a number and wrapping
3765/// at the boundary of the type.
3766///
3767/// # wrapping_square
3768/// ```
3769/// use malachite_base::num::arithmetic::traits::WrappingSquare;
3770///
3771/// assert_eq!(3u8.wrapping_square(), 9);
3772/// assert_eq!((-1000i32).wrapping_square(), 1000000);
3773/// assert_eq!(1000u16.wrapping_square(), 16960);
3774/// ```
3775///
3776/// # wrapping_square_assign
3777/// ```
3778/// use malachite_base::num::arithmetic::traits::WrappingSquareAssign;
3779///
3780/// let mut x = 3u8;
3781/// x.wrapping_square_assign();
3782/// assert_eq!(x, 9);
3783///
3784/// let mut x = -1000i32;
3785/// x.wrapping_square_assign();
3786/// assert_eq!(x, 1000000);
3787///
3788/// let mut x = 1000u16;
3789/// x.wrapping_square_assign();
3790/// assert_eq!(x, 16960);
3791/// ```
3792pub mod wrapping_square;
3793/// [`WrappingSub`](traits::WrappingSub) and [`WrappingSubAssign`](traits::WrappingSubAssign),
3794/// traits for subtracting two numbers and wrapping at the boundary of the type.
3795///
3796/// # wrapping_sub_assign
3797/// ```
3798/// use malachite_base::num::arithmetic::traits::WrappingSubAssign;
3799///
3800/// let mut x = 456u16;
3801/// x.wrapping_sub_assign(123);
3802/// assert_eq!(x, 333);
3803///
3804/// let mut x = 123u16;
3805/// x.wrapping_sub_assign(456);
3806/// assert_eq!(x, 65203);
3807/// ```
3808pub mod wrapping_sub;
3809/// [`WrappingSubMul`](traits::WrappingSubMul) and
3810/// [`WrappingSubMulAssign`](traits::WrappingSubMulAssign), traits for subtracting a number by the
3811/// product of two other numbers and wrapping at the boundary of the type.
3812///
3813/// # wrapping_sub_mul
3814/// ```
3815/// use malachite_base::num::arithmetic::traits::WrappingSubMul;
3816///
3817/// assert_eq!(127i8.wrapping_sub_mul(2, 100), -73);
3818/// assert_eq!((-127i8).wrapping_sub_mul(2, 100), -71);
3819/// ```
3820///
3821/// # wrapping_sub_mul_assign
3822/// ```
3823/// use malachite_base::num::arithmetic::traits::WrappingAddMulAssign;
3824///
3825/// let mut x = 2u8;
3826/// x.wrapping_add_mul_assign(3, 7);
3827/// assert_eq!(x, 23);
3828///
3829/// let mut x = -127i8;
3830/// x.wrapping_add_mul_assign(-2, 100);
3831/// assert_eq!(x, -71);
3832/// ```
3833pub mod wrapping_sub_mul;
3834/// [`XMulYToZZ`](traits::XMulYToZZ), a trait for multiplying two numbers and returning the result
3835/// as a double-width number.
3836///
3837/// # x_mul_y_to_zz
3838/// ```
3839/// use malachite_base::num::arithmetic::traits::XMulYToZZ;
3840///
3841/// assert_eq!(u64::x_mul_y_to_zz(15, 3), (0, 45));
3842/// assert_eq!(u8::x_mul_y_to_zz(0x78, 0x9a), (0x48, 0x30));
3843/// ```
3844pub mod x_mul_y_to_zz;
3845/// [`XXAddYYToZZ`](traits::XXAddYYToZZ), a trait for adding two double-width numbers and returning
3846/// the result as a double-width number.
3847///
3848/// # xx_add_yy_to_zz
3849/// ```
3850/// use malachite_base::num::arithmetic::traits::XXAddYYToZZ;
3851///
3852/// assert_eq!(u64::xx_add_yy_to_zz(0x12, 0x34, 0x33, 0x33), (0x45, 0x67));
3853/// assert_eq!(u8::xx_add_yy_to_zz(0x78, 0x9a, 0xbc, 0xde), (0x35, 0x78));
3854/// ```
3855pub mod xx_add_yy_to_zz;
3856/// [`XXDivModYToQR`](traits::XXDivModYToQR), a trait for dividing a double-width number by a
3857/// single-width number and returning the quotient and remainder.
3858///
3859/// # xx_div_mod_y_to_qr
3860/// ```
3861/// use malachite_base::num::arithmetic::traits::XXDivModYToQR;
3862///
3863/// assert_eq!(
3864///     u64::xx_div_mod_y_to_qr(0x12, 0x34, 0x33),
3865///     (0x5a5a5a5a5a5a5a5b, 0x13)
3866/// );
3867/// assert_eq!(u8::xx_div_mod_y_to_qr(0x78, 0x9a, 0xbc), (0xa4, 0x2a));
3868/// ```
3869pub mod xx_div_mod_y_to_qr;
3870/// [`XXSubYYToZZ`](traits::XXSubYYToZZ), a trait for subtracting two double-width numbers and
3871/// returning the result as a double-width number.
3872///
3873/// # xx_sub_yy_to_zz
3874/// ```
3875/// use malachite_base::num::arithmetic::traits::XXSubYYToZZ;
3876///
3877/// assert_eq!(u64::xx_sub_yy_to_zz(0x67, 0x89, 0x33, 0x33), (0x34, 0x56));
3878/// assert_eq!(u8::xx_sub_yy_to_zz(0x78, 0x9a, 0xbc, 0xde), (0xbb, 0xbc));
3879/// ```
3880pub mod xx_sub_yy_to_zz;
3881/// [`XXXAddYYYToZZZ`](traits::XXXAddYYYToZZZ), a trait for adding two triple-width numbers and
3882/// returning the result as a triple-width number.
3883///
3884/// # xxx_add_yyy_to_zzz
3885/// ```
3886/// use malachite_base::num::arithmetic::traits::XXXAddYYYToZZZ;
3887///
3888/// assert_eq!(
3889///     u64::xxx_add_yyy_to_zzz(0x12, 0x34, 0x56, 0x33, 0x33, 0x33),
3890///     (0x45, 0x67, 0x89)
3891/// );
3892/// assert_eq!(
3893///     u8::xxx_add_yyy_to_zzz(0x78, 0x9a, 0xbc, 0xde, 0xfe, 0xdc),
3894///     (0x57, 0x99, 0x98)
3895/// );
3896/// ```
3897pub mod xxx_add_yyy_to_zzz;
3898/// [`XXXSubYYYToZZZ`](traits::XXXSubYYYToZZZ), a trait for subtracting two triple-width numbers and
3899/// returning the result as a triple-width number.
3900///
3901/// # xxx_sub_yyy_to_zzz
3902/// ```
3903/// use malachite_base::num::arithmetic::traits::XXXSubYYYToZZZ;
3904///
3905/// assert_eq!(
3906///     u64::xxx_sub_yyy_to_zzz(0x67, 0x89, 0xab, 0x33, 0x33, 0x33),
3907///     (0x34, 0x56, 0x78)
3908/// );
3909/// assert_eq!(
3910///     u8::xxx_sub_yyy_to_zzz(0x78, 0x9a, 0xbc, 0xde, 0xfe, 0xdc),
3911///     (0x99, 0x9b, 0xe0)
3912/// );
3913/// ```
3914pub mod xxx_sub_yyy_to_zzz;
3915/// [`XXXXAddYYYYToZZZZ`](traits::XXXXAddYYYYToZZZZ), a trait for adding two quadruple-width numbers
3916/// and returning the result as a quadruple-width number.
3917///
3918/// # xxxx_add_yyyy_to_zzzz
3919/// ```
3920/// use malachite_base::num::arithmetic::traits::XXXXAddYYYYToZZZZ;
3921///
3922/// assert_eq!(
3923///     u64::xxxx_add_yyyy_to_zzzz(0x12, 0x34, 0x56, 0x78, 0x33, 0x33, 0x33, 0x33),
3924///     (0x45, 0x67, 0x89, 0xab)
3925/// );
3926/// assert_eq!(
3927///     u8::xxxx_add_yyyy_to_zzzz(0x78, 0x9a, 0xbc, 0xde, 0xfe, 0xdc, 0xba, 0x98),
3928///     (0x77, 0x77, 0x77, 0x76)
3929/// );
3930/// ```
3931pub mod xxxx_add_yyyy_to_zzzz;