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