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