Skip to main content

malachite_base/num/arithmetic/
traits.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
9use crate::num::basic::traits::Two;
10use crate::rounding_modes::RoundingMode;
11use core::cmp::Ordering;
12
13/// Takes the absolute value of a number. Assumes that the number has a representable absolute
14/// value.
15pub trait Abs {
16    type Output;
17
18    fn abs(self) -> Self::Output;
19}
20
21/// Replaces a number with its absolute value. Assumes that the number has a representable absolute
22/// value.
23pub trait AbsAssign {
24    fn abs_assign(&mut self);
25}
26
27/// Takes the absolute value of a number and converts to the unsigned equivalent.
28pub trait UnsignedAbs {
29    type Output;
30
31    fn unsigned_abs(self) -> Self::Output;
32}
33
34/// Subtracts two numbers and takes the absolute value of the difference.
35pub trait AbsDiff<RHS = Self> {
36    type Output;
37
38    fn abs_diff(self, other: RHS) -> Self::Output;
39}
40
41/// Replaces a number with the absolute value of its difference with another number.
42pub trait AbsDiffAssign<RHS = Self> {
43    fn abs_diff_assign(&mut self, other: RHS);
44}
45
46/// Adds a number and the product of two other numbers.
47pub trait AddMul<Y = Self, Z = Self> {
48    type Output;
49
50    fn add_mul(self, y: Y, z: Z) -> Self::Output;
51}
52
53/// Adds a number and the product of two other numbers, in place.
54pub trait AddMulAssign<Y = Self, Z = Self> {
55    fn add_mul_assign(&mut self, y: Y, z: Z);
56}
57
58/// Calculates the AGM (arithmetic-geometric mean) of two numbers.
59pub trait Agm<RHS = Self> {
60    type Output;
61
62    fn agm(self, other: RHS) -> Self::Output;
63}
64
65/// Replaces a number with the AGM (arithmetic-geometric mean) of it and another number.
66pub trait AgmAssign<RHS = Self> {
67    fn agm_assign(&mut self, other: RHS);
68}
69
70/// Left-shifts a number (multiplies it by a power of 2), returning `None` if the result is not
71/// representable.
72pub trait ArithmeticCheckedShl<RHS> {
73    type Output;
74
75    fn arithmetic_checked_shl(self, other: RHS) -> Option<Self::Output>;
76}
77
78/// Right-shifts a number (divides it by a power of 2), returning `None` if the result is not
79/// representable.
80pub trait ArithmeticCheckedShr<RHS> {
81    type Output;
82
83    fn arithmetic_checked_shr(self, other: RHS) -> Option<Self::Output>;
84}
85
86pub trait BinomialCoefficient<T = Self> {
87    fn binomial_coefficient(n: T, k: T) -> Self;
88}
89
90pub trait CheckedBinomialCoefficient<T = Self>: Sized {
91    fn checked_binomial_coefficient(n: T, k: T) -> Option<Self>;
92}
93
94/// Takes the ceiling of a number.
95pub trait Ceiling {
96    type Output;
97
98    fn ceiling(self) -> Self::Output;
99}
100
101/// Replaces a number with its ceiling.
102pub trait CeilingAssign {
103    fn ceiling_assign(&mut self);
104}
105
106/// Takes the absolute valie of a number, returning `None` if the result is not representable.
107pub trait CheckedAbs {
108    type Output;
109
110    fn checked_abs(self) -> Option<Self::Output>;
111}
112
113/// Adds two numbers, returning `None` if the result is not representable.
114pub trait CheckedAdd<RHS = Self> {
115    type Output;
116
117    fn checked_add(self, other: RHS) -> Option<Self::Output>;
118}
119
120/// Adds a number and the product of two other numbers, returning `None` if the result is not
121/// representable.
122pub trait CheckedAddMul<Y = Self, Z = Self> {
123    type Output;
124
125    fn checked_add_mul(self, y: Y, z: Z) -> Option<Self::Output>;
126}
127
128/// Divides two numbers, returning `None` if the result is not representable.
129pub trait CheckedDiv<RHS = Self> {
130    type Output;
131
132    fn checked_div(self, other: RHS) -> Option<Self::Output>;
133}
134
135/// Multiplies two numbers, returning `None` if the result is not representable.
136pub trait CheckedMul<RHS = Self> {
137    type Output;
138
139    fn checked_mul(self, other: RHS) -> Option<Self::Output>;
140}
141
142/// Negates a number, returning `None` if the result is not representable.
143pub trait CheckedNeg {
144    type Output;
145
146    fn checked_neg(self) -> Option<Self::Output>;
147}
148
149/// Finds the smallest integer power of 2 greater than or equal to a number, returning `None` if the
150/// result is not representable.
151pub trait CheckedNextPowerOf2 {
152    type Output;
153
154    fn checked_next_power_of_2(self) -> Option<Self::Output>;
155}
156
157/// Raises a number to a power, returning `None` if the result is not representable.
158pub trait CheckedPow<RHS> {
159    type Output;
160
161    fn checked_pow(self, exp: RHS) -> Option<Self::Output>;
162}
163
164/// Squares a number, returning `None` if the result is not representable.
165pub trait CheckedSquare {
166    type Output;
167
168    fn checked_square(self) -> Option<Self::Output>;
169}
170
171/// Subtracts two numbers, returning `None` if the result is not representable.
172pub trait CheckedSub<RHS = Self> {
173    type Output;
174
175    fn checked_sub(self, other: RHS) -> Option<Self::Output>;
176}
177
178/// Subtracts a number by the product of two other numbers, returning `None` if the result is not
179/// representable.
180pub trait CheckedSubMul<Y = Self, Z = Self> {
181    type Output;
182
183    fn checked_sub_mul(self, y: Y, z: Z) -> Option<Self::Output>;
184}
185
186/// Determines whether two numbers are coprime.
187pub trait CoprimeWith<RHS = Self> {
188    fn coprime_with(self, other: RHS) -> bool;
189}
190
191/// Divides two numbers, assuming the first exactly divides the second.
192///
193/// If it doesn't, the `div_exact` function may panic or return a meaningless result.
194pub trait DivExact<RHS = Self> {
195    type Output;
196
197    fn div_exact(self, other: RHS) -> Self::Output;
198}
199
200/// Divides a number by another number in place, assuming the first exactly divides the second.
201///
202/// If it doesn't, this function may panic or assign a meaningless number to the first number.
203pub trait DivExactAssign<RHS = Self> {
204    fn div_exact_assign(&mut self, other: RHS);
205}
206
207/// Divides two numbers, returning the quotient and remainder. The quotient is rounded towards
208/// negative infinity, and the remainder has the same sign as the divisor (second input).
209///
210/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
211pub trait DivMod<RHS = Self> {
212    type DivOutput;
213    type ModOutput;
214
215    fn div_mod(self, other: RHS) -> (Self::DivOutput, Self::ModOutput);
216}
217
218/// Divides two numbers, returning the quotient and remainder. The quotient is rounded towards the
219/// quotient that makes the remainder nonnegative, and the remainder is always nonnegative.
220///
221/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.
222pub trait DivEuclidean<RHS = Self> {
223    type DivOutput;
224    type ModOutput;
225
226    fn div_euclidean(self, other: RHS) -> (Self::DivOutput, Self::ModOutput);
227}
228
229/// Divides a number by another number in place, returning the remainder. The quotient is rounded
230/// towards negative infinity, and the remainder has the same sign as the divisor (second input).
231///
232/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
233pub trait DivAssignMod<RHS = Self> {
234    type ModOutput;
235
236    fn div_assign_mod(&mut self, other: RHS) -> Self::ModOutput;
237}
238
239/// Divides a number by another number in place, returning the remainder. The quotient is rounded
240/// towards the quotient that makes the remainder nonnegative, and the remainder is always
241/// nonnegative.
242///
243/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.
244pub trait DivAssignEuclidean<RHS = Self> {
245    type ModOutput;
246
247    fn div_assign_euclidean(&mut self, other: RHS) -> Self::ModOutput;
248}
249
250/// Divides two numbers, returning the quotient and remainder. The quotient is rounded towards zero,
251/// and the remainder has the same sign as the dividend (first input).
252///
253/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
254pub trait DivRem<RHS = Self> {
255    type DivOutput;
256    type RemOutput;
257
258    fn div_rem(self, other: RHS) -> (Self::DivOutput, Self::RemOutput);
259}
260
261/// Divides a number by another number in place, returning the remainder. The quotient is rounded
262/// towards zero, and the remainder has the same sign as the dividend (first input).
263///
264/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
265pub trait DivAssignRem<RHS = Self> {
266    type RemOutput;
267
268    fn div_assign_rem(&mut self, other: RHS) -> Self::RemOutput;
269}
270
271/// Divides a number by another number, returning the ceiling of the quotient and the remainder of
272/// the negative of the first number divided by the second.
273///
274/// The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
275pub trait CeilingDivNegMod<RHS = Self> {
276    type DivOutput;
277    type ModOutput;
278
279    fn ceiling_div_neg_mod(self, other: RHS) -> (Self::DivOutput, Self::ModOutput);
280}
281
282/// Divides a number by another number in place, taking the ceiling of the quotient and returning
283/// the remainder of the negative of the first number divided by the second.
284///
285/// The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
286pub trait CeilingDivAssignNegMod<RHS = Self> {
287    type ModOutput;
288
289    fn ceiling_div_assign_neg_mod(&mut self, other: RHS) -> Self::ModOutput;
290}
291
292/// Divides a number by another number, returning the quotient and remainder. The quotient is
293/// rounded towards positive infinity and the remainder has the opposite sign as the divisor (second
294/// input).
295///
296/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
297pub trait CeilingDivMod<RHS = Self> {
298    type DivOutput;
299    type ModOutput;
300
301    fn ceiling_div_mod(self, other: RHS) -> (Self::DivOutput, Self::ModOutput);
302}
303
304/// Divides a number by another number in place, taking the quotient and returning the remainder.
305/// The quotient is rounded towards positive infinity and the remainder has the opposite sign of the
306/// divisor (second input).
307///
308/// The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
309pub trait CeilingDivAssignMod<RHS = Self> {
310    type ModOutput;
311
312    fn ceiling_div_assign_mod(&mut self, other: RHS) -> Self::ModOutput;
313}
314
315/// Divides a number by another number and rounds according to a specified rounding mode. An
316/// [`Ordering`] is also returned, indicating whether the returned value is less than, equal to, or
317/// greater than the exact value.
318pub trait DivRound<RHS = Self> {
319    type Output;
320
321    fn div_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
322}
323
324/// Divides a number by another number in place and rounds according to a specified rounding mode.
325/// An [`Ordering`] is returned, indicating whether the assigned value is less than, equal to, or
326/// greater than the exact value.
327pub trait DivRoundAssign<RHS = Self> {
328    fn div_round_assign(&mut self, other: RHS, rm: RoundingMode) -> Ordering;
329}
330
331/// Determines whether a number is divisible by $2^k$.
332pub trait DivisibleByPowerOf2 {
333    fn divisible_by_power_of_2(self, pow: u64) -> bool;
334}
335
336/// Determines whether a number is divisible by another number.
337pub trait DivisibleBy<RHS = Self> {
338    fn divisible_by(self, other: RHS) -> bool;
339}
340
341/// Determines whether a number is equivalent to another number modulo $2^k$.
342pub trait EqModPowerOf2<RHS = Self> {
343    fn eq_mod_power_of_2(self, other: RHS, pow: u64) -> bool;
344}
345
346/// Determines whether a number is equivalent to another number modulo $m$.
347pub trait EqMod<RHS = Self, M = Self> {
348    fn eq_mod(self, other: RHS, m: M) -> bool;
349}
350
351/// Computes the GCD (greatest common divisor) of two numbers $a$ and $b$, and also the coefficients
352/// $x$ and $y$ in Bézout's identity $ax+by=\gcd(a,b)$.
353///
354/// The are infinitely many $x$, $y$ that satisfy the identity, so the full specification is more
355/// detailed:
356///
357/// - $f(0, 0) = (0, 0, 0)$.
358/// - $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
359/// - $f(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
360/// - $f(bk, b) = (b, 0, 1)$ if $b > 0$.
361/// - $f(bk, b) = (-b, 0, -1)$ if $b < 0$.
362/// - $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(|a|, |b|)$, where
363///   $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g
364///   \rfloor$.
365pub trait ExtendedGcd<RHS = Self> {
366    type Gcd;
367    type Cofactor;
368
369    fn extended_gcd(self, other: RHS) -> (Self::Gcd, Self::Cofactor, Self::Cofactor);
370}
371
372/// Computes the factorial of a `u64`.
373pub trait Factorial {
374    fn factorial(n: u64) -> Self;
375}
376
377/// Computes the factorial of a `u64`, returning `None` if the result is too large to be
378/// represented.
379pub trait CheckedFactorial: Sized {
380    fn checked_factorial(n: u64) -> Option<Self>;
381}
382
383/// Computes the double factorial of a `u64`. The double factorial of a non-negative integer is the
384/// product of all the positive integers that are less than or equal to it and have the same parity
385/// as it.
386pub trait DoubleFactorial {
387    fn double_factorial(n: u64) -> Self;
388}
389
390/// Computes the double factorial of a `u64`, returning `None` if the result is too large to be
391/// represented. The double factorial of a non-negative integer is the product of all the positive
392/// integers that are less than or equal to it and have the same parity as it.
393pub trait CheckedDoubleFactorial: Sized {
394    fn checked_double_factorial(n: u64) -> Option<Self>;
395}
396
397/// Computes the $m$-multifactorial of a `u64`. The $m$-multifactorial of a non-negative integer $n$
398/// is the product of all integers $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$.
399pub trait Multifactorial {
400    fn multifactorial(n: u64, m: u64) -> Self;
401}
402
403/// Computes the $m$-multifactorial of a `u64`, returning `None` if the result is too large to be
404/// represented. The $m$-multifactorial of a non-negative integer $n$ is the product of all integers
405/// $k$ such that $0<k\leq n$ and $k\equiv n \pmod m$.
406pub trait CheckedMultifactorial: Sized {
407    fn checked_multifactorial(n: u64, m: u64) -> Option<Self>;
408}
409
410/// Computes the subfactorial of a `u64`. The subfactorial of a non-negative integer $n$ counts the
411/// number of derangements of $n$ elements, which are the permutations in which no element is fixed.
412pub trait Subfactorial {
413    fn subfactorial(n: u64) -> Self;
414}
415
416/// Computes the subfactorial of a `u64`, returning `None` if the result is too large to be
417/// represented. The subfactorial of a non-negative integer $n$ counts the number of derangements of
418/// $n$ elements, which are the permutations in which no element is fixed.
419pub trait CheckedSubfactorial: Sized {
420    fn checked_subfactorial(n: u64) -> Option<Self>;
421}
422
423/// Takes the floor of a number.
424pub trait Floor {
425    type Output;
426
427    fn floor(self) -> Self::Output;
428}
429
430/// Replaces a number with its floor.
431pub trait FloorAssign {
432    fn floor_assign(&mut self);
433}
434
435/// Calculates the GCD (greatest common divisor) of two numbers.
436pub trait Gcd<RHS = Self> {
437    type Output;
438
439    fn gcd(self, other: RHS) -> Self::Output;
440}
441
442/// Replaces a number with the GCD (greatest common divisor) of it and another number.
443pub trait GcdAssign<RHS = Self> {
444    fn gcd_assign(&mut self, other: RHS);
445}
446
447/// Determines whether a number is an integer power of 2.
448pub trait IsPowerOf2 {
449    fn is_power_of_2(&self) -> bool;
450}
451
452/// Calculates the LCM (least common multiple) of two numbers.
453pub trait Lcm<RHS = Self> {
454    type Output;
455
456    fn lcm(self, other: RHS) -> Self::Output;
457}
458
459/// Replaces a number with the LCM (least common multiple) of it and another number.
460pub trait LcmAssign<RHS = Self> {
461    fn lcm_assign(&mut self, other: RHS);
462}
463
464/// Computes $e^x$, the exponential of a number.
465pub trait Exp {
466    type Output;
467
468    fn exp(self) -> Self::Output;
469}
470
471/// Replaces a number with its exponential, $e^x$.
472pub trait ExpAssign {
473    fn exp_assign(&mut self);
474}
475
476/// Computes $e^x-1$, the exponential of a number, minus one.
477pub trait ExpXMinus1 {
478    type Output;
479
480    fn exp_x_minus_1(self) -> Self::Output;
481}
482
483/// Replaces a number $x$ with $e^x-1$.
484pub trait ExpXMinus1Assign {
485    fn exp_x_minus_1_assign(&mut self);
486}
487
488/// Computes $2^x-1$, two raised to the power of a number, minus one.
489pub trait PowerOf2XMinus1 {
490    type Output;
491
492    fn power_of_2_x_minus_1(self) -> Self::Output;
493}
494
495/// Replaces a number $x$ with $2^x-1$.
496pub trait PowerOf2XMinus1Assign {
497    fn power_of_2_x_minus_1_assign(&mut self);
498}
499
500/// Computes $10^x-1$, ten raised to the power of a number, minus one.
501pub trait PowerOf10XMinus1 {
502    type Output;
503
504    fn power_of_10_x_minus_1(self) -> Self::Output;
505}
506
507/// Replaces a number $x$ with $10^x-1$.
508pub trait PowerOf10XMinus1Assign {
509    fn power_of_10_x_minus_1_assign(&mut self);
510}
511
512/// Takes the natural logarithm of a number.
513pub trait Ln {
514    type Output;
515
516    fn ln(self) -> Self::Output;
517}
518
519/// Replaces a number with its natural logarithm.
520pub trait LnAssign {
521    fn ln_assign(&mut self);
522}
523
524/// Computes $\ln(1+x)$.
525pub trait Ln1PlusX {
526    type Output;
527
528    fn ln_1_plus_x(self) -> Self::Output;
529}
530
531/// Replaces a number $x$ by $\ln(1+x)$.
532pub trait Ln1PlusXAssign {
533    fn ln_1_plus_x_assign(&mut self);
534}
535
536/// Calculates the LCM (least common multiple) of two numbers, returning `None` if the result is not
537/// representable.
538pub trait CheckedLcm<RHS = Self> {
539    type Output;
540
541    fn checked_lcm(self, other: RHS) -> Option<Self::Output>;
542}
543
544/// Calculates the Legendre symbol of two numbers. Typically the implementations will be identical
545/// to those of [`JacobiSymbol`].
546pub trait LegendreSymbol<RHS = Self> {
547    fn legendre_symbol(self, other: RHS) -> i8;
548}
549
550/// Calculates the Jacobi symbol of two numbers.
551pub trait JacobiSymbol<RHS = Self> {
552    fn jacobi_symbol(self, other: RHS) -> i8;
553}
554
555/// Calculates the Kronecker symbol of two numbers.
556pub trait KroneckerSymbol<RHS = Self> {
557    fn kronecker_symbol(self, other: RHS) -> i8;
558}
559
560/// Calculates the base-$b$ logarithm of a number, or returns `None` if the number is not a perfect
561/// power of $b$.
562pub trait CheckedLogBase<B = Self> {
563    type Output;
564
565    fn checked_log_base(self, base: B) -> Option<Self::Output>;
566}
567
568/// Calculates the floor of the base-$b$ logarithm of a number.
569pub trait FloorLogBase<B = Self> {
570    type Output;
571
572    fn floor_log_base(self, base: B) -> Self::Output;
573}
574
575/// Calculates the ceiling of the base-$b$ logarithm of a number.
576pub trait CeilingLogBase<B = Self> {
577    type Output;
578
579    fn ceiling_log_base(self, base: B) -> Self::Output;
580}
581
582/// Calculates the base-2 logarithm of a number, or returns `None` if the number is not a perfect
583/// power of 2.
584pub trait CheckedLogBase2 {
585    type Output;
586
587    fn checked_log_base_2(self) -> Option<Self::Output>;
588}
589
590/// Calculates the base-2 logarithm of a number.
591pub trait LogBase2 {
592    type Output;
593
594    fn log_base_2(self) -> Self::Output;
595}
596
597/// Replaces a number with its base-2 logarithm.
598pub trait LogBase2Assign {
599    fn log_base_2_assign(&mut self);
600}
601
602/// Calculates the base-10 logarithm of a number, rounding the (generally irrational) result.
603pub trait LogBase10 {
604    type Output;
605
606    fn log_base_10(self) -> Self::Output;
607}
608
609/// Replaces a number with its base-10 logarithm, rounding the (generally irrational) result.
610pub trait LogBase10Assign {
611    fn log_base_10_assign(&mut self);
612}
613
614/// Computes $\log_2(1+x)$.
615pub trait LogBase2Of1PlusX {
616    type Output;
617
618    fn log_base_2_1_plus_x(self) -> Self::Output;
619}
620
621/// Replaces a number $x$ by $\log_2(1+x)$.
622pub trait LogBase2Of1PlusXAssign {
623    fn log_base_2_1_plus_x_assign(&mut self);
624}
625
626/// Computes $\log_{2^k}(1+x)$.
627pub trait LogBasePowerOf2Of1PlusX<POW> {
628    type Output;
629
630    fn log_base_power_of_2_1_plus_x(self, pow: POW) -> Self::Output;
631}
632
633/// Replaces a number $x$ by $\log_{2^k}(1+x)$.
634pub trait LogBasePowerOf2Of1PlusXAssign<POW> {
635    fn log_base_power_of_2_1_plus_x_assign(&mut self, pow: POW);
636}
637
638/// Computes $\log_b(1+x)$ for an integer base $b$.
639pub trait LogBaseOf1PlusX<B = Self> {
640    type Output;
641
642    fn log_base_1_plus_x(self, base: B) -> Self::Output;
643}
644
645/// Replaces a number $x$ by $\log_b(1+x)$ for an integer base $b$.
646pub trait LogBaseOf1PlusXAssign<B = Self> {
647    fn log_base_1_plus_x_assign(&mut self, base: B);
648}
649
650/// Computes $\log_{10}(1+x)$.
651pub trait LogBase10Of1PlusX {
652    type Output;
653
654    fn log_base_10_1_plus_x(self) -> Self::Output;
655}
656
657/// Replaces a number $x$ by $\log_{10}(1+x)$.
658pub trait LogBase10Of1PlusXAssign {
659    fn log_base_10_1_plus_x_assign(&mut self);
660}
661
662/// Calculates the floor of the base-2 logarithm of a number.
663pub trait FloorLogBase2 {
664    type Output;
665
666    fn floor_log_base_2(self) -> Self::Output;
667}
668
669/// Calculates the ceiling of the base-2 logarithm of a number.
670pub trait CeilingLogBase2 {
671    type Output;
672
673    fn ceiling_log_base_2(self) -> Self::Output;
674}
675
676/// Calculates the base-$2^k$ logarithm of a number, or returns `None` if the number is not a
677/// perfect power of $2^k$.
678pub trait CheckedLogBasePowerOf2<POW> {
679    type Output;
680
681    fn checked_log_base_power_of_2(self, pow: POW) -> Option<Self::Output>;
682}
683
684/// Calculates the floor of the base-$2^k$ logarithm of a number.
685pub trait FloorLogBasePowerOf2<POW> {
686    type Output;
687
688    fn floor_log_base_power_of_2(self, pow: POW) -> Self::Output;
689}
690
691/// Calculates the ceiling of the base-$2^k$ logarithm of a number.
692pub trait CeilingLogBasePowerOf2<POW> {
693    type Output;
694
695    fn ceiling_log_base_power_of_2(self, pow: POW) -> Self::Output;
696}
697
698/// Calculates the base-$2^k$ logarithm of a number.
699pub trait LogBasePowerOf2<POW> {
700    type Output;
701
702    fn log_base_power_of_2(self, pow: POW) -> Self::Output;
703}
704
705/// Replaces a number with its base-$2^k$ logarithm.
706pub trait LogBasePowerOf2Assign<POW> {
707    fn log_base_power_of_2_assign(&mut self, pow: POW);
708}
709
710/// Calculates the base-$b$ logarithm of a number, rounding the (generally irrational) result.
711pub trait LogBase<B = Self> {
712    type Output;
713
714    fn log_base(self, base: B) -> Self::Output;
715}
716
717/// Replaces a number with its base-$b$ logarithm, rounding the (generally irrational) result.
718pub trait LogBaseAssign<B = Self> {
719    fn log_base_assign(&mut self, base: B);
720}
721
722/// Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
723pub trait ModAdd<RHS = Self, M = Self> {
724    type Output;
725
726    fn mod_add(self, other: RHS, m: M) -> Self::Output;
727}
728
729/// Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo
730/// $m$.
731pub trait ModAddAssign<RHS = Self, M = Self> {
732    fn mod_add_assign(&mut self, other: RHS, m: M);
733}
734
735/// Finds the multiplicative inverse of a number modulo another number $m$. The input must be
736/// already reduced modulo $m$.
737pub trait ModInverse<M = Self> {
738    type Output;
739
740    fn mod_inverse(self, m: M) -> Option<Self::Output>;
741}
742
743/// Checks whether a number is reduced modulo another number $m$.
744pub trait ModIsReduced<M = Self> {
745    fn mod_is_reduced(&self, m: &M) -> bool;
746}
747
748/// Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
749pub trait ModMul<RHS = Self, M = Self> {
750    type Output;
751
752    fn mod_mul(self, other: RHS, m: M) -> Self::Output;
753}
754
755/// Multiplies two numbers modulo a third number $m$, in place. The inputs must be already reduced
756/// modulo $m$.
757pub trait ModMulAssign<RHS = Self, M = Self> {
758    fn mod_mul_assign(&mut self, other: RHS, m: M);
759}
760
761/// Multiplies two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
762///
763/// If multiple modular multiplications with the same modulus are necessary, it can be quicker to
764/// precompute some piece of data and reuse it in the multiplication calls. This trait provides a
765/// function for precomputing the data and a function for using it during multiplication.
766pub trait ModMulPrecomputed<RHS = Self, M = Self> {
767    type Output;
768    type Data;
769
770    /// Precomputes some data to use for modular multiplication.
771    fn precompute_mod_mul_data(m: &M) -> Self::Data;
772
773    fn mod_mul_precomputed(self, other: RHS, m: M, data: &Self::Data) -> Self::Output;
774}
775
776/// Multiplies two numbers modulo a third number $m$, in place.The inputs must be already reduced
777/// modulo $m$.
778///
779/// If multiple modular multiplications with the same modulus are necessary, it can be quicker to
780/// precompute some piece of data and reuse it in the multiplication calls. This trait provides a
781/// function for using precomputed data during multiplication. For precomputing the data, use the
782/// [`precompute_mod_mul_data`](ModMulPrecomputed::precompute_mod_mul_data) function in
783/// [`ModMulPrecomputed`].
784pub trait ModMulPrecomputedAssign<RHS = Self, M = Self>: ModMulPrecomputed<RHS, M> {
785    fn mod_mul_precomputed_assign(&mut self, other: RHS, m: M, data: &Self::Data);
786}
787
788/// Negates a number modulo another number $m$. The input must be already reduced modulo $m$.
789pub trait ModNeg<M = Self> {
790    type Output;
791
792    fn mod_neg(self, m: M) -> Self::Output;
793}
794
795/// Negates a number modulo another number $m$, in place. The input must be already reduced modulo
796/// $m$.
797pub trait ModNegAssign<M = Self> {
798    fn mod_neg_assign(&mut self, m: M);
799}
800
801/// Divides a number by another number, returning just the remainder. The remainder has the same
802/// sign as the divisor (second number).
803///
804/// If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq
805/// |r| < |y|$.
806pub trait Mod<RHS = Self> {
807    type Output;
808
809    fn mod_op(self, other: RHS) -> Self::Output;
810}
811
812/// Divides a number by another number, replacing the first number by the remainder. The remainder
813/// has the same sign as the divisor (second number).
814///
815/// If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq
816/// |r| < |y|$.
817pub trait ModAssign<RHS = Self> {
818    fn mod_assign(&mut self, other: RHS);
819}
820
821/// Divides the negative of a number by another number, returning the remainder.
822///
823/// If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq
824/// r < y$.
825pub trait NegMod<RHS = Self> {
826    type Output;
827
828    fn neg_mod(self, other: RHS) -> Self::Output;
829}
830
831/// Divides the negative of a number by another number, replacing the first number by the remainder.
832///
833/// If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq
834/// r < y$.
835pub trait NegModAssign<RHS = Self> {
836    fn neg_mod_assign(&mut self, other: RHS);
837}
838
839/// Divides a number by another number, returning just the remainder. The remainder has the opposite
840/// sign as the divisor (second number).
841///
842/// If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq
843/// |r| < |y|$.
844pub trait CeilingMod<RHS = Self> {
845    type Output;
846
847    fn ceiling_mod(self, other: RHS) -> Self::Output;
848}
849
850/// Divides a number by another number, replacing the first number by the remainder. The remainder
851/// has the same sign as the divisor (second number).
852///
853/// If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq
854/// |r| < |y|$.
855pub trait CeilingModAssign<RHS = Self> {
856    fn ceiling_mod_assign(&mut self, other: RHS);
857}
858
859/// Raises a number to a power modulo another number $m$. The base must be already reduced modulo
860/// $m$.
861pub trait ModPow<RHS = Self, M = Self> {
862    type Output;
863
864    fn mod_pow(self, exp: RHS, m: M) -> Self::Output;
865}
866
867/// Raises a number to a power modulo another number $m$, in place. The base must be already reduced
868/// modulo $m$.
869pub trait ModPowAssign<RHS = Self, M = Self> {
870    fn mod_pow_assign(&mut self, exp: RHS, m: M);
871}
872
873/// Raises a number to a power modulo another number $m$. The base must be already reduced modulo
874/// $m$.
875///
876/// If multiple modular exponentiations with the same modulus are necessary, it can be quicker to
877/// precompute some piece of data and reuse it in the exponentiation calls. This trait provides a
878/// function for precomputing the data and a function for using it during exponentiation.
879pub trait ModPowPrecomputed<RHS = Self, M = Self>
880where
881    Self: Sized,
882{
883    type Output;
884    type Data;
885
886    /// Precomputes some data to use for modular exponentiation.
887    fn precompute_mod_pow_data(m: &M) -> Self::Data;
888
889    fn mod_pow_precomputed(self, exp: RHS, m: M, data: &Self::Data) -> Self::Output;
890}
891
892/// Raises a number to a power modulo another number $m$, in place. The base must be already reduced
893/// modulo $m$.
894///
895/// If multiple modular exponentiations with the same modulus are necessary, it can be quicker to
896/// precompute some piece of data and reuse it in the exponentiation calls. This trait provides a
897/// function for using precomputed data during exponentiation. For precomputing the data, use the
898/// [`precompute_mod_pow_data`](ModPowPrecomputed::precompute_mod_pow_data) function in
899/// [`ModPowPrecomputed`].
900pub trait ModPowPrecomputedAssign<RHS: Two = Self, M = Self>: ModPowPrecomputed<RHS, M> {
901    fn mod_pow_precomputed_assign(&mut self, exp: RHS, m: M, data: &Self::Data);
902}
903
904/// Adds two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
905pub trait ModPowerOf2Add<RHS = Self> {
906    type Output;
907
908    fn mod_power_of_2_add(self, other: RHS, pow: u64) -> Self::Output;
909}
910
911/// Adds two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
912pub trait ModPowerOf2AddAssign<RHS = Self> {
913    fn mod_power_of_2_add_assign(&mut self, other: RHS, pow: u64);
914}
915
916/// Finds the multiplicative inverse of a number modulo $2^k$. The input must be already reduced
917/// modulo $2^k$.
918pub trait ModPowerOf2Inverse {
919    type Output;
920
921    fn mod_power_of_2_inverse(self, pow: u64) -> Option<Self::Output>;
922}
923
924/// Checks whether a number is reduced modulo $2^k$.
925pub trait ModPowerOf2IsReduced {
926    fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool;
927}
928
929/// Multiplies two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
930pub trait ModPowerOf2Mul<RHS = Self> {
931    type Output;
932
933    fn mod_power_of_2_mul(self, other: RHS, pow: u64) -> Self::Output;
934}
935
936/// Multiplies two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
937pub trait ModPowerOf2MulAssign<RHS = Self> {
938    fn mod_power_of_2_mul_assign(&mut self, other: RHS, pow: u64);
939}
940
941/// Negates a number modulo $2^k$. The input must be already reduced modulo $2^k$.
942pub trait ModPowerOf2Neg {
943    type Output;
944
945    fn mod_power_of_2_neg(self, pow: u64) -> Self::Output;
946}
947
948/// Negates a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
949pub trait ModPowerOf2NegAssign {
950    fn mod_power_of_2_neg_assign(&mut self, pow: u64);
951}
952
953/// Raises a number to a power modulo $2^k$. The base must be already reduced modulo $2^k$.
954pub trait ModPowerOf2Pow<RHS = Self> {
955    type Output;
956
957    fn mod_power_of_2_pow(self, exp: RHS, pow: u64) -> Self::Output;
958}
959
960/// Raises a number to a power modulo $2^k$, in place. The base must be already reduced modulo
961/// $2^k$.
962pub trait ModPowerOf2PowAssign<RHS = Self> {
963    fn mod_power_of_2_pow_assign(&mut self, exp: RHS, pow: u64);
964}
965
966/// Left-shifts a number (multiplies it by a power of 2) modulo $2^k$. The number must be already
967/// reduced modulo $2^k$.
968pub trait ModPowerOf2Shl<RHS> {
969    type Output;
970
971    fn mod_power_of_2_shl(self, other: RHS, pow: u64) -> Self::Output;
972}
973
974/// Left-shifts a number (multiplies it by a power of 2) modulo $2^k$, in place. The number must be
975/// already reduced modulo $2^k$.
976pub trait ModPowerOf2ShlAssign<RHS> {
977    fn mod_power_of_2_shl_assign(&mut self, other: RHS, pow: u64);
978}
979
980/// Right-shifts a number (divides it by a power of 2) modulo $2^k$. The number must be already
981/// reduced modulo $2^k$.
982pub trait ModPowerOf2Shr<RHS> {
983    type Output;
984
985    fn mod_power_of_2_shr(self, other: RHS, pow: u64) -> Self::Output;
986}
987
988/// Right-shifts a number (divides it by a power of 2) modulo $2^k$, in place. The number must be
989/// already reduced modulo $2^k$.
990pub trait ModPowerOf2ShrAssign<RHS> {
991    fn mod_power_of_2_shr_assign(&mut self, other: RHS, pow: u64);
992}
993
994/// Squares a number modulo $2^k$. The input must be already reduced modulo $2^k$.
995pub trait ModPowerOf2Square {
996    type Output;
997
998    fn mod_power_of_2_square(self, pow: u64) -> Self::Output;
999}
1000
1001/// Squares a number modulo $2^k$ in place. The input must be already reduced modulo $2^k$.
1002pub trait ModPowerOf2SquareAssign {
1003    fn mod_power_of_2_square_assign(&mut self, pow: u64);
1004}
1005
1006/// Subtracts two numbers modulo $2^k$. The inputs must be already reduced modulo $2^k$.
1007pub trait ModPowerOf2Sub<RHS = Self> {
1008    type Output;
1009
1010    fn mod_power_of_2_sub(self, other: RHS, pow: u64) -> Self::Output;
1011}
1012
1013/// Subtracts two numbers modulo $2^k$, in place. The inputs must be already reduced modulo $2^k$.
1014pub trait ModPowerOf2SubAssign<RHS = Self> {
1015    fn mod_power_of_2_sub_assign(&mut self, other: RHS, pow: u64);
1016}
1017
1018/// Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.
1019///
1020/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1021/// \leq r < 2^k$.
1022pub trait ModPowerOf2 {
1023    type Output;
1024
1025    fn mod_power_of_2(self, other: u64) -> Self::Output;
1026}
1027
1028/// Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-negative.
1029///
1030/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1031/// \leq r < 2^k$.
1032pub trait ModPowerOf2Assign {
1033    fn mod_power_of_2_assign(&mut self, other: u64);
1034}
1035
1036/// Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the
1037/// number.
1038///
1039/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1040/// \leq |r| < 2^k$.
1041pub trait RemPowerOf2 {
1042    type Output;
1043
1044    fn rem_power_of_2(self, other: u64) -> Self::Output;
1045}
1046
1047/// Divides a number by $2^k$, replacing the number by the remainder. The remainder has the same
1048/// sign as the number.
1049///
1050/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1051/// \leq |r| < 2^k$.
1052pub trait RemPowerOf2Assign {
1053    fn rem_power_of_2_assign(&mut self, other: u64);
1054}
1055
1056/// Divides the negative of a number by $2^k$, returning the remainder.
1057///
1058/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k - r$ and $0
1059/// \leq r < 2^k$.
1060pub trait NegModPowerOf2 {
1061    type Output;
1062
1063    fn neg_mod_power_of_2(self, other: u64) -> Self::Output;
1064}
1065
1066/// Divides the negative of a number by $2^k$, replacing the number by the remainder.
1067///
1068/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k - r$ and $0
1069/// \leq r < 2^k$.
1070pub trait NegModPowerOf2Assign {
1071    fn neg_mod_power_of_2_assign(&mut self, other: u64);
1072}
1073
1074/// Divides a number by $2^k$, returning just the remainder. The remainder is non-positive.
1075///
1076/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1077/// \leq -r < 2^k$.
1078pub trait CeilingModPowerOf2 {
1079    type Output;
1080
1081    fn ceiling_mod_power_of_2(self, other: u64) -> Self::Output;
1082}
1083
1084/// Divides a number by $2^k$, replacing the number by the remainder. The remainder is non-positive.
1085///
1086/// If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0
1087/// \leq -r < 2^k$.
1088pub trait CeilingModPowerOf2Assign {
1089    fn ceiling_mod_power_of_2_assign(&mut self, other: u64);
1090}
1091
1092/// Left-shifts a number (multiplies it by a power of 2) modulo another number $m$. The number must
1093/// be already reduced modulo $m$.
1094pub trait ModShl<RHS, M = Self> {
1095    type Output;
1096
1097    fn mod_shl(self, other: RHS, m: M) -> Self::Output;
1098}
1099
1100/// Left-shifts a number (multiplies it by a power of 2) modulo another number $m$, in place. The
1101/// number must be already reduced modulo $m$.
1102pub trait ModShlAssign<RHS, M = Self> {
1103    fn mod_shl_assign(&mut self, other: RHS, m: M);
1104}
1105
1106/// Left-shifts a number (divides it by a power of 2) modulo another number $m$. The number must be
1107/// already reduced modulo $m$.
1108pub trait ModShr<RHS, M = Self> {
1109    type Output;
1110
1111    fn mod_shr(self, other: RHS, m: M) -> Self::Output;
1112}
1113
1114/// Left-shifts a number (divides it by a power of 2) modulo another number $m$, in place. The
1115/// number must be already reduced modulo $m$.
1116pub trait ModShrAssign<RHS, M = Self> {
1117    fn mod_shr_assign(&mut self, other: RHS, m: M);
1118}
1119
1120/// Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
1121pub trait ModSquare<M = Self> {
1122    type Output;
1123
1124    fn mod_square(self, m: M) -> Self::Output;
1125}
1126
1127/// Squares a number modulo another number $m$, in place. The input must be already reduced modulo
1128/// $m$.
1129pub trait ModSquareAssign<M = Self> {
1130    fn mod_square_assign(&mut self, m: M);
1131}
1132
1133/// Squares a number modulo another number $m$. The input must be already reduced modulo $m$.
1134///
1135/// If multiple modular squarings with the same modulus are necessary, it can be quicker to
1136/// precompute some piece of data using
1137/// [`precompute_mod_pow_data`](ModPowPrecomputed::precompute_mod_pow_data) function in
1138/// [`ModMulPrecomputed`] and reuse it in the squaring calls.
1139pub trait ModSquarePrecomputed<RHS = Self, M = Self>: ModPowPrecomputed<RHS, M>
1140where
1141    Self: Sized,
1142{
1143    fn mod_square_precomputed(self, m: M, data: &Self::Data) -> Self::Output;
1144}
1145
1146/// Squares a number modulo another number $m$, in place. The input must be already reduced modulo
1147/// $m$.
1148///
1149/// If multiple modular squarings with the same modulus are necessary, it can be quicker to
1150/// precompute some piece of data using
1151/// [`precompute_mod_pow_data`](ModPowPrecomputed::precompute_mod_pow_data) function in
1152/// [`ModMulPrecomputed`] and reuse it in the squaring calls.
1153pub trait ModSquarePrecomputedAssign<RHS = Self, M = Self>: ModPowPrecomputed<RHS, M> {
1154    fn mod_square_precomputed_assign(&mut self, m: M, data: &Self::Data);
1155}
1156
1157/// Adds two numbers modulo a third number $m$. The inputs must be already reduced modulo $m$.
1158pub trait ModSub<RHS = Self, M = Self> {
1159    type Output;
1160
1161    fn mod_sub(self, other: RHS, m: M) -> Self::Output;
1162}
1163
1164/// Adds two numbers modulo a third number $m$, in place. The inputs must be already reduced modulo
1165/// $m$.
1166pub trait ModSubAssign<RHS = Self, M = Self> {
1167    fn mod_sub_assign(&mut self, other: RHS, m: M);
1168}
1169
1170/// Replaces a number with its negative. Assumes the result is representable.
1171pub trait NegAssign {
1172    fn neg_assign(&mut self);
1173}
1174
1175/// Returns the smallest power of 2 greater than or equal to a number. Assumes the result is
1176/// representable.
1177pub trait NextPowerOf2 {
1178    type Output;
1179
1180    fn next_power_of_2(self) -> Self::Output;
1181}
1182
1183/// Replaces a number with the smallest power of 2 greater than or equal it. Assumes the result is
1184/// representable.
1185pub trait NextPowerOf2Assign {
1186    fn next_power_of_2_assign(&mut self);
1187}
1188
1189/// Takes the absolute value of a number.
1190///
1191/// Returns a tuple of the result along with a boolean indicating whether an arithmetic overflow
1192/// occurred. If an overflow occurred, then the wrapped number is returned.
1193pub trait OverflowingAbs {
1194    type Output;
1195
1196    fn overflowing_abs(self) -> (Self::Output, bool);
1197}
1198
1199/// Replaces a number with its absolute value.
1200///
1201/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1202/// then the wrapped number is assigned.
1203pub trait OverflowingAbsAssign {
1204    fn overflowing_abs_assign(&mut self) -> bool;
1205}
1206
1207/// Adds two numbers.
1208///
1209/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1210/// occurred. If an overflow occurred, then the wrapped number is returned.
1211pub trait OverflowingAdd<RHS = Self> {
1212    type Output;
1213
1214    fn overflowing_add(self, other: RHS) -> (Self::Output, bool);
1215}
1216
1217/// Adds a number to another number in place.
1218///
1219/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1220/// then the wrapped number is assigned.
1221pub trait OverflowingAddAssign<RHS = Self> {
1222    fn overflowing_add_assign(&mut self, other: RHS) -> bool;
1223}
1224
1225/// Adds a number and the product of two other numbers.
1226///
1227/// Returns a tuple of the result along with a boolean indicating whether an arithmetic overflow
1228/// occurred. If an overflow occurred, then the wrapped number is returned.
1229pub trait OverflowingAddMul<Y = Self, Z = Self> {
1230    type Output;
1231
1232    fn overflowing_add_mul(self, y: Y, z: Z) -> (Self::Output, bool);
1233}
1234
1235/// Adds a number and the product of two other numbers, in place.
1236///
1237/// Returns a tuple of the result along with a boolean indicating whether an arithmetic overflow
1238/// occurred. If an overflow occurred, then the wrapped number is returned.
1239pub trait OverflowingAddMulAssign<Y = Self, Z = Self> {
1240    fn overflowing_add_mul_assign(&mut self, y: Y, z: Z) -> bool;
1241}
1242
1243/// Divides two numbers.
1244///
1245/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1246/// occurred. If an overflow occurred, then the wrapped number is returned.
1247pub trait OverflowingDiv<RHS = Self> {
1248    type Output;
1249
1250    fn overflowing_div(self, other: RHS) -> (Self::Output, bool);
1251}
1252
1253/// Divides a number by another number in place.
1254///
1255/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1256/// then the wrapped number is assigned.
1257pub trait OverflowingDivAssign<RHS = Self> {
1258    fn overflowing_div_assign(&mut self, other: RHS) -> bool;
1259}
1260
1261/// Multiplies two numbers.
1262///
1263/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1264/// occurred. If an overflow occurred, then the wrapped number is returned.
1265pub trait OverflowingMul<RHS = Self> {
1266    type Output;
1267
1268    fn overflowing_mul(self, other: RHS) -> (Self::Output, bool);
1269}
1270
1271/// Multiplies a number by another number in place.
1272///
1273/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1274/// then the wrapped number is assigned.
1275pub trait OverflowingMulAssign<RHS = Self> {
1276    fn overflowing_mul_assign(&mut self, other: RHS) -> bool;
1277}
1278
1279/// Negates a number.
1280///
1281/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1282/// occurred. If an overflow occurred, then the wrapped number is returned.
1283pub trait OverflowingNeg {
1284    type Output;
1285
1286    fn overflowing_neg(self) -> (Self::Output, bool);
1287}
1288
1289/// Negates a number in place.
1290///
1291/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1292/// then the wrapped number is assigned.
1293pub trait OverflowingNegAssign {
1294    fn overflowing_neg_assign(&mut self) -> bool;
1295}
1296
1297/// Raises a number to a power.
1298///
1299/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1300/// occurred. If an overflow occurred, then the wrapped number is returned.
1301pub trait OverflowingPow<RHS> {
1302    type Output;
1303
1304    fn overflowing_pow(self, exp: RHS) -> (Self::Output, bool);
1305}
1306
1307/// Raises a number to a power in place.
1308///
1309/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1310/// then the wrapped number is assigned.
1311pub trait OverflowingPowAssign<RHS = Self> {
1312    fn overflowing_pow_assign(&mut self, exp: RHS) -> bool;
1313}
1314
1315/// Squares a number.
1316///
1317/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1318/// occurred. If an overflow occurred, then the wrapped number is returned.
1319pub trait OverflowingSquare {
1320    type Output;
1321
1322    fn overflowing_square(self) -> (Self::Output, bool);
1323}
1324
1325/// Squares a number in place.
1326///
1327/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1328/// then the wrapped number is assigned.
1329pub trait OverflowingSquareAssign {
1330    fn overflowing_square_assign(&mut self) -> bool;
1331}
1332
1333/// Subtracts two numbers.
1334///
1335/// Returns a tuple of the sum along with a boolean indicating whether an arithmetic overflow
1336/// occurred. If an overflow occurred, then the wrapped number is returned.
1337pub trait OverflowingSub<RHS = Self> {
1338    type Output;
1339
1340    fn overflowing_sub(self, other: RHS) -> (Self::Output, bool);
1341}
1342
1343/// Subtracts a number by another number in place.
1344///
1345/// Returns a boolean indicating whether an arithmetic overflow occurred. If an overflow occurred,
1346/// then the wrapped number is assigned.
1347pub trait OverflowingSubAssign<RHS = Self> {
1348    fn overflowing_sub_assign(&mut self, other: RHS) -> bool;
1349}
1350
1351/// Subtracts a number by the product of two other numbers.
1352///
1353/// Returns a tuple of the result along with a boolean indicating whether an arithmetic overflow
1354/// occurred. If an overflow occurred, then the wrapped number is returned.
1355pub trait OverflowingSubMul<Y = Self, Z = Self> {
1356    type Output;
1357
1358    fn overflowing_sub_mul(self, y: Y, z: Z) -> (Self::Output, bool);
1359}
1360
1361/// Subtracts a number by the product of two other numbers, in place.
1362///
1363/// Returns a tuple of the result along with a boolean indicating whether an arithmetic overflow
1364/// occurred. If an overflow occurred, then the wrapped number is returned.
1365pub trait OverflowingSubMulAssign<Y = Self, Z = Self> {
1366    fn overflowing_sub_mul_assign(&mut self, y: Y, z: Z) -> bool;
1367}
1368
1369/// Determines whether a number is even or odd.
1370pub trait Parity {
1371    /// Determines whether a number is even.
1372    fn even(self) -> bool;
1373
1374    /// Determines whether a number is odd.
1375    fn odd(self) -> bool;
1376}
1377
1378/// Raises a number to a power. Assumes the result is representable.
1379pub trait Pow<RHS> {
1380    type Output;
1381
1382    fn pow(self, exp: RHS) -> Self::Output;
1383}
1384
1385/// Raises a number to a power in place. Assumes the result is representable.
1386pub trait PowAssign<RHS = Self> {
1387    fn pow_assign(&mut self, exp: RHS);
1388}
1389
1390/// Raises 2 to a power.
1391pub trait PowerOf2<POW> {
1392    fn power_of_2(pow: POW) -> Self;
1393}
1394
1395/// Replaces a number with 2 raised to the power of that number.
1396pub trait PowerOf2Assign {
1397    fn power_of_2_assign(&mut self);
1398}
1399
1400/// Raises 10 to a power.
1401pub trait PowerOf10<POW> {
1402    fn power_of_10(pow: POW) -> Self;
1403}
1404
1405/// Replaces a number with 10 raised to the power of that number.
1406pub trait PowerOf10Assign {
1407    fn power_of_10_assign(&mut self);
1408}
1409
1410pub trait Primorial {
1411    fn primorial(n: u64) -> Self;
1412
1413    fn product_of_first_n_primes(n: u64) -> Self;
1414}
1415
1416pub trait CheckedPrimorial: Sized {
1417    fn checked_primorial(n: u64) -> Option<Self>;
1418
1419    fn checked_product_of_first_n_primes(n: u64) -> Option<Self>;
1420}
1421
1422/// Finds the reciprocal (multiplicative inverse) of a number.
1423pub trait Reciprocal {
1424    type Output;
1425
1426    fn reciprocal(self) -> Self::Output;
1427}
1428
1429/// Replaces a number with its reciprocal (multiplicative inverse).
1430pub trait ReciprocalAssign {
1431    fn reciprocal_assign(&mut self);
1432}
1433
1434/// Takes the reciprocal of the square root of a number.
1435pub trait ReciprocalSqrt {
1436    type Output;
1437
1438    fn reciprocal_sqrt(self) -> Self::Output;
1439}
1440
1441/// Replaces a number with the reciprocal of its square root.
1442pub trait ReciprocalSqrtAssign {
1443    fn reciprocal_sqrt_assign(&mut self);
1444}
1445
1446/// Finds the floor of the $n$th root of a number.
1447pub trait FloorRoot<POW> {
1448    type Output;
1449
1450    fn floor_root(self, pow: POW) -> Self::Output;
1451}
1452
1453/// Replaces a number with the floor of its $n$th root.
1454pub trait FloorRootAssign<POW> {
1455    fn floor_root_assign(&mut self, pow: POW);
1456}
1457
1458/// Finds the ceiling of the $n$th root of a number.
1459pub trait CeilingRoot<POW> {
1460    type Output;
1461
1462    fn ceiling_root(self, pow: POW) -> Self::Output;
1463}
1464
1465/// Replaces a number with the ceiling of its $n$th root.
1466pub trait CeilingRootAssign<POW> {
1467    fn ceiling_root_assign(&mut self, pow: POW);
1468}
1469
1470/// Finds the $n$th root of a number, returning `None` if it is not a perfect $n$th power.
1471pub trait CheckedRoot<POW> {
1472    type Output;
1473
1474    fn checked_root(self, pow: POW) -> Option<Self::Output>;
1475}
1476
1477/// Finds the floor of the $n$th root of a number, returning both the root and the remainder.
1478pub trait RootRem<POW> {
1479    type RootOutput;
1480    type RemOutput;
1481
1482    fn root_rem(self, exp: POW) -> (Self::RootOutput, Self::RemOutput);
1483}
1484
1485/// Replaces a number with the floor of its $n$th root, returning the remainder.
1486pub trait RootAssignRem<POW> {
1487    type RemOutput;
1488
1489    fn root_assign_rem(&mut self, exp: POW) -> Self::RemOutput;
1490}
1491
1492/// Takes the $n$th root of a number.
1493pub trait Root<POW> {
1494    type Output;
1495
1496    fn root(self, pow: POW) -> Self::Output;
1497}
1498
1499/// Replaces a number with its $n$th root.
1500pub trait RootAssign<POW> {
1501    fn root_assign(&mut self, pow: POW);
1502}
1503
1504/// Takes the cube root of a number.
1505pub trait Cbrt {
1506    type Output;
1507
1508    fn cbrt(self) -> Self::Output;
1509}
1510
1511/// Replaces a number with its cube root.
1512pub trait CbrtAssign {
1513    fn cbrt_assign(&mut self);
1514}
1515
1516/// Rotates a number left, inserting the leftmost bits into the right end.
1517pub trait RotateLeft {
1518    type Output;
1519
1520    fn rotate_left(self, n: u64) -> Self::Output;
1521}
1522
1523/// Rotates a number left, inserting the leftmost bits into the right end, in place.
1524pub trait RotateLeftAssign {
1525    fn rotate_left_assign(&mut self, n: u64);
1526}
1527
1528/// Rotates a number right, inserting the leftmost bits into the left end.
1529pub trait RotateRight {
1530    type Output;
1531
1532    fn rotate_right(self, n: u64) -> Self::Output;
1533}
1534
1535/// Rotates a number right, inserting the leftmost bits into the left end, in place.
1536pub trait RotateRightAssign {
1537    fn rotate_right_assign(&mut self, n: u64);
1538}
1539
1540/// Rounds a number to a multiple of another number, according to a specified rounding mode. An
1541/// [`Ordering`] is also returned, indicating whether the returned value is less than, equal to, or
1542/// greater than the original value.
1543pub trait RoundToMultiple<RHS = Self> {
1544    type Output;
1545
1546    fn round_to_multiple(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
1547}
1548
1549/// Rounds a number to a multiple of another number in place, according to a specified rounding
1550/// mode. [`Ordering`] is returned, indicating whether the returned value is less than, equal to, or
1551/// greater than the original value.
1552pub trait RoundToMultipleAssign<RHS = Self> {
1553    fn round_to_multiple_assign(&mut self, other: RHS, rm: RoundingMode) -> Ordering;
1554}
1555
1556/// Rounds a number to a multiple of $2^k$, according to a specified rounding mode. An [`Ordering`]
1557/// is also returned, indicating whether the returned value is less than, equal to, or greater than
1558/// the original value.
1559pub trait RoundToMultipleOfPowerOf2<RHS> {
1560    type Output;
1561
1562    fn round_to_multiple_of_power_of_2(
1563        self,
1564        pow: RHS,
1565        rm: RoundingMode,
1566    ) -> (Self::Output, Ordering);
1567}
1568
1569/// Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode. An
1570/// [`Ordering`] is returned, indicating whether the returned value is less than, equal to, or
1571/// greater than the original value.
1572pub trait RoundToMultipleOfPowerOf2Assign<RHS> {
1573    fn round_to_multiple_of_power_of_2_assign(&mut self, pow: RHS, rm: RoundingMode) -> Ordering;
1574}
1575
1576/// Takes the absolute value of a number, saturating at the numeric bounds instead of overflowing.
1577pub trait SaturatingAbs {
1578    type Output;
1579
1580    fn saturating_abs(self) -> Self::Output;
1581}
1582
1583/// Replaces a number with its absolute value, saturating at the numeric bounds instead of
1584/// overflowing.
1585pub trait SaturatingAbsAssign {
1586    fn saturating_abs_assign(&mut self);
1587}
1588
1589/// Adds two numbers, saturating at the numeric bounds instead of overflowing.
1590pub trait SaturatingAdd<RHS = Self> {
1591    type Output;
1592
1593    fn saturating_add(self, other: RHS) -> Self::Output;
1594}
1595
1596/// Add a number to another number in place, saturating at the numeric bounds instead of
1597/// overflowing.
1598pub trait SaturatingAddAssign<RHS = Self> {
1599    fn saturating_add_assign(&mut self, other: RHS);
1600}
1601
1602/// Adds a number and the product of two other numbers, saturating at the numeric bounds instead of
1603/// overflowing.
1604pub trait SaturatingAddMul<Y = Self, Z = Self> {
1605    type Output;
1606
1607    fn saturating_add_mul(self, y: Y, z: Z) -> Self::Output;
1608}
1609
1610/// Adds a number and the product of two other numbers in place, saturating at the numeric bounds
1611/// instead of overflowing.
1612pub trait SaturatingAddMulAssign<Y = Self, Z = Self> {
1613    fn saturating_add_mul_assign(&mut self, y: Y, z: Z);
1614}
1615
1616/// Multiplies two numbers, saturating at the numeric bounds instead of overflowing.
1617pub trait SaturatingMul<RHS = Self> {
1618    type Output;
1619
1620    fn saturating_mul(self, other: RHS) -> Self::Output;
1621}
1622
1623/// Multiplies a number by another number in place, saturating at the numeric bounds instead of
1624/// overflowing.
1625pub trait SaturatingMulAssign<RHS = Self> {
1626    fn saturating_mul_assign(&mut self, other: RHS);
1627}
1628
1629/// Negates a number, saturating at the numeric bounds instead of overflowing.
1630pub trait SaturatingNeg {
1631    type Output;
1632
1633    fn saturating_neg(self) -> Self::Output;
1634}
1635
1636/// Negates a number in place, saturating at the numeric bounds instead of overflowing.
1637pub trait SaturatingNegAssign {
1638    fn saturating_neg_assign(&mut self);
1639}
1640
1641/// Raises a number to a power, saturating at the numeric bounds instead of overflowing.
1642pub trait SaturatingPow<RHS> {
1643    type Output;
1644
1645    fn saturating_pow(self, exp: RHS) -> Self::Output;
1646}
1647
1648/// Raises a number to a power in place, saturating at the numeric bounds instead of overflowing.
1649pub trait SaturatingPowAssign<RHS = Self> {
1650    fn saturating_pow_assign(&mut self, exp: RHS);
1651}
1652
1653/// Squares a number, saturating at the numeric bounds instead of overflowing.
1654pub trait SaturatingSquare {
1655    type Output;
1656
1657    fn saturating_square(self) -> Self::Output;
1658}
1659
1660/// Squares a number in place, saturating at the numeric bounds instead of overflowing.
1661pub trait SaturatingSquareAssign {
1662    fn saturating_square_assign(&mut self);
1663}
1664
1665/// Subtracts two numbers, saturating at the numeric bounds instead of overflowing.
1666pub trait SaturatingSub<RHS = Self> {
1667    type Output;
1668
1669    fn saturating_sub(self, other: RHS) -> Self::Output;
1670}
1671
1672/// Subtracts a number by another number in place, saturating at the numeric bounds instead of
1673/// overflowing.
1674pub trait SaturatingSubAssign<RHS = Self> {
1675    fn saturating_sub_assign(&mut self, other: RHS);
1676}
1677
1678/// Subtracts a number by the product of two other numbers, saturating at the numeric bounds instead
1679/// of overflowing.
1680pub trait SaturatingSubMul<Y = Self, Z = Self> {
1681    type Output;
1682
1683    fn saturating_sub_mul(self, y: Y, z: Z) -> Self::Output;
1684}
1685
1686/// Subtracts a number by the product of two other numbers in place, saturating at the numeric
1687/// bounds instead of overflowing.
1688pub trait SaturatingSubMulAssign<Y = Self, Z = Self> {
1689    fn saturating_sub_mul_assign(&mut self, y: Y, z: Z);
1690}
1691
1692/// Left-shifts a number (multiplies it by a power of 2), rounding the result according to a
1693/// specified rounding mode. An [`Ordering`] is also returned, indicating whether the returned value
1694/// is less than, equal to, or greater than the exact value.
1695///
1696/// Rounding might only be necessary if `other` is negative.
1697pub trait ShlRound<RHS> {
1698    type Output;
1699
1700    fn shl_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
1701}
1702
1703/// Left-shifts a number (multiplies it by a power of 2) in place, rounding the result according to
1704/// a specified rounding mode. An [`Ordering`] is also returned, indicating whether the assigned
1705/// value is less than, equal to, or greater than the exact value.
1706///
1707/// Rounding might only be necessary if `other` is negative.
1708pub trait ShlRoundAssign<RHS> {
1709    fn shl_round_assign(&mut self, other: RHS, rm: RoundingMode) -> Ordering;
1710}
1711
1712/// Right-shifts a number (divides it by a power of 2), rounding the result according to a specified
1713/// rounding mode. An [`Ordering`] is also returned, indicating whether the returned value is less
1714/// than, equal to, or greater than the exact value.
1715///
1716/// Rounding might only be necessary if `other` is positive.
1717pub trait ShrRound<RHS> {
1718    type Output;
1719
1720    fn shr_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
1721}
1722
1723/// Right-shifts a number (divides it by a power of 2) in place, rounding the result according to a
1724/// specified rounding mode. An [`Ordering`] is also returned, indicating whether the assigned value
1725/// is less than, equal to, or greater than the exact value.
1726///
1727/// Rounding might only be necessary if `other` is positive.
1728pub trait ShrRoundAssign<RHS> {
1729    fn shr_round_assign(&mut self, other: RHS, rm: RoundingMode) -> Ordering;
1730}
1731
1732/// Returns `Greater`, `Equal`, or `Less`, depending on whether a number is positive, zero, or
1733/// negative, respectively.
1734pub trait Sign {
1735    fn sign(&self) -> Ordering;
1736}
1737
1738/// Takes the square root of a number.
1739pub trait Sqrt {
1740    type Output;
1741
1742    fn sqrt(self) -> Self::Output;
1743}
1744
1745/// Replaces a number with its square root.
1746pub trait SqrtAssign {
1747    fn sqrt_assign(&mut self);
1748}
1749
1750/// Finds the floor of the square root of a number.
1751pub trait FloorSqrt {
1752    type Output;
1753
1754    fn floor_sqrt(self) -> Self::Output;
1755}
1756
1757/// Replaces a number with the floor of its square root.
1758pub trait FloorSqrtAssign {
1759    fn floor_sqrt_assign(&mut self);
1760}
1761
1762/// Finds the ceiling of the square root of a number.
1763pub trait CeilingSqrt {
1764    type Output;
1765
1766    fn ceiling_sqrt(self) -> Self::Output;
1767}
1768
1769/// Replaces a number with the ceiling of its square root.
1770pub trait CeilingSqrtAssign {
1771    fn ceiling_sqrt_assign(&mut self);
1772}
1773
1774/// Finds the square root of a number, returning `None` if it is not a perfect square.
1775pub trait CheckedSqrt {
1776    type Output;
1777
1778    fn checked_sqrt(self) -> Option<Self::Output>;
1779}
1780
1781/// Finds the floor of the square root of a number, returning both the root and the remainder.
1782pub trait SqrtRem {
1783    type SqrtOutput;
1784    type RemOutput;
1785
1786    fn sqrt_rem(self) -> (Self::SqrtOutput, Self::RemOutput);
1787}
1788
1789/// Replaces a number with the floor of its square root, returning the remainder.
1790pub trait SqrtAssignRem {
1791    type RemOutput;
1792
1793    fn sqrt_assign_rem(&mut self) -> Self::RemOutput;
1794}
1795
1796/// Squares a number.
1797pub trait Square {
1798    type Output;
1799
1800    fn square(self) -> Self::Output;
1801}
1802
1803/// Replaces a number with its square.
1804pub trait SquareAssign {
1805    fn square_assign(&mut self);
1806}
1807
1808/// Subtracts a number by the product of two other numbers.
1809pub trait SubMul<Y = Self, Z = Self> {
1810    type Output;
1811
1812    fn sub_mul(self, y: Y, z: Z) -> Self::Output;
1813}
1814
1815/// Subtracts a number by the product of two other numbers, in place.
1816pub trait SubMulAssign<Y = Self, Z = Self> {
1817    fn sub_mul_assign(&mut self, y: Y, z: Z);
1818}
1819
1820/// Takes the absolute value of a number, wrapping around at the boundary of the type.
1821pub trait WrappingAbs {
1822    type Output;
1823
1824    fn wrapping_abs(self) -> Self::Output;
1825}
1826
1827/// Replaces a number with its absolute value, wrapping around at the boundary of the type.
1828pub trait WrappingAbsAssign {
1829    fn wrapping_abs_assign(&mut self);
1830}
1831
1832/// Adds two numbers, wrapping around at the boundary of the type.
1833pub trait WrappingAdd<RHS = Self> {
1834    type Output;
1835
1836    fn wrapping_add(self, other: RHS) -> Self::Output;
1837}
1838
1839/// Adds a number to another number in place, wrapping around at the boundary of the type.
1840pub trait WrappingAddAssign<RHS = Self> {
1841    fn wrapping_add_assign(&mut self, other: RHS);
1842}
1843
1844/// Adds a number and the product of two other numbers, wrapping around at the boundary of the type.
1845pub trait WrappingAddMul<Y = Self, Z = Self> {
1846    type Output;
1847
1848    fn wrapping_add_mul(self, y: Y, z: Z) -> Self::Output;
1849}
1850
1851/// Adds a number and the product of two other numbers, in place, wrapping around at the boundary of
1852/// the type.
1853pub trait WrappingAddMulAssign<Y = Self, Z = Self> {
1854    fn wrapping_add_mul_assign(&mut self, y: Y, z: Z);
1855}
1856
1857/// Divides a number by another number, wrapping around at the boundary of the type.
1858pub trait WrappingDiv<RHS = Self> {
1859    type Output;
1860
1861    fn wrapping_div(self, other: RHS) -> Self::Output;
1862}
1863
1864/// Divides a number by another number in place, wrapping around at the boundary of the type.
1865pub trait WrappingDivAssign<RHS = Self> {
1866    fn wrapping_div_assign(&mut self, other: RHS);
1867}
1868
1869/// Multiplies two numbers, wrapping around at the boundary of the type.
1870pub trait WrappingMul<RHS = Self> {
1871    type Output;
1872
1873    fn wrapping_mul(self, other: RHS) -> Self::Output;
1874}
1875
1876/// Multiplies a number by another number in place, wrapping around at the boundary of the type.
1877pub trait WrappingMulAssign<RHS = Self> {
1878    fn wrapping_mul_assign(&mut self, other: RHS);
1879}
1880
1881/// Negates a number, wrapping around at the boundary of the type.
1882pub trait WrappingNeg {
1883    type Output;
1884
1885    fn wrapping_neg(self) -> Self::Output;
1886}
1887
1888/// Negates a number in place, wrapping around at the boundary of the type.
1889pub trait WrappingNegAssign {
1890    fn wrapping_neg_assign(&mut self);
1891}
1892
1893/// Raises a number to a power, wrapping around at the boundary of the type.
1894pub trait WrappingPow<RHS> {
1895    type Output;
1896
1897    fn wrapping_pow(self, exp: RHS) -> Self::Output;
1898}
1899
1900/// Raises a number to a power in place, wrapping around at the boundary of the type.
1901pub trait WrappingPowAssign<RHS = Self> {
1902    fn wrapping_pow_assign(&mut self, exp: RHS);
1903}
1904
1905/// Squares a number, wrapping around at the boundary of the type.
1906pub trait WrappingSquare {
1907    type Output;
1908
1909    fn wrapping_square(self) -> Self::Output;
1910}
1911
1912/// Squares a number in place, wrapping around at the boundary of the type.
1913pub trait WrappingSquareAssign {
1914    fn wrapping_square_assign(&mut self);
1915}
1916
1917/// Subtracts two numbers, wrapping around at the boundary of the type.
1918pub trait WrappingSub<RHS = Self> {
1919    type Output;
1920
1921    fn wrapping_sub(self, other: RHS) -> Self::Output;
1922}
1923
1924/// Subtracts a number by another number in place, wrapping around at the boundary of the type.
1925pub trait WrappingSubAssign<RHS = Self> {
1926    fn wrapping_sub_assign(&mut self, other: RHS);
1927}
1928
1929/// Subtracts a number by the product of two other numbers, wrapping around at the boundary of the
1930/// type.
1931pub trait WrappingSubMul<Y = Self, Z = Self> {
1932    type Output;
1933
1934    fn wrapping_sub_mul(self, y: Y, z: Z) -> Self::Output;
1935}
1936
1937/// Subtracts a number by the product of two other numbers, in place, wrapping around at the
1938/// boundary of the type.
1939pub trait WrappingSubMulAssign<Y = Self, Z = Self> {
1940    fn wrapping_sub_mul_assign(&mut self, y: Y, z: Z);
1941}
1942
1943/// Multiplies two numbers, returning the product as a pair of `Self` values.
1944///
1945/// The more significant number always comes first.
1946pub trait XMulYToZZ: Sized {
1947    fn x_mul_y_to_zz(x: Self, y: Self) -> (Self, Self);
1948}
1949
1950/// Adds two numbers, each composed of two `Self` values, returning the sum as a pair of `Self`
1951/// values.
1952///
1953/// The more significant number always comes first. Addition is wrapping, and overflow is not
1954/// indicated.
1955pub trait XXAddYYToZZ: Sized {
1956    fn xx_add_yy_to_zz(x_1: Self, x_0: Self, y_1: Self, y_0: Self) -> (Self, Self);
1957}
1958
1959/// Computes the quotient and remainder of two numbers. The first is composed of two `Self` values,
1960/// and the second of a single one.
1961///
1962/// `x_1` must be less than `y`.
1963pub trait XXDivModYToQR: Sized {
1964    fn xx_div_mod_y_to_qr(x_1: Self, x_0: Self, y: Self) -> (Self, Self);
1965}
1966
1967/// Subtracts two numbers, each composed of two `Self` values, returing the difference as a pair of
1968/// `Self` values.
1969///
1970/// The more significant number always comes first. Subtraction is wrapping, and overflow is not
1971/// indicated.
1972pub trait XXSubYYToZZ: Sized {
1973    fn xx_sub_yy_to_zz(x_1: Self, x_0: Self, y_1: Self, y_0: Self) -> (Self, Self);
1974}
1975
1976/// Adds two numbers, each composed of three `Self` values, returning the sum as a triple of `Self`
1977/// values.
1978///
1979/// The more significant number always comes first. Addition is wrapping, and overflow is not
1980/// indicated.
1981pub trait XXXAddYYYToZZZ: Sized {
1982    fn xxx_add_yyy_to_zzz(
1983        x_2: Self,
1984        x_1: Self,
1985        x_0: Self,
1986        y_2: Self,
1987        y_1: Self,
1988        y_0: Self,
1989    ) -> (Self, Self, Self);
1990}
1991
1992/// Subtracts two numbers, each composed of three `Self` values, returing the difference as a triple
1993/// of `Self` values.
1994///
1995/// The more significant number always comes first. Subtraction is wrapping, and overflow is not
1996/// indicated.
1997pub trait XXXSubYYYToZZZ: Sized {
1998    fn xxx_sub_yyy_to_zzz(
1999        x_2: Self,
2000        x_1: Self,
2001        x_0: Self,
2002        y_2: Self,
2003        y_1: Self,
2004        y_0: Self,
2005    ) -> (Self, Self, Self);
2006}
2007
2008/// Adds two numbers, each composed of four `Self` values, returning the sum as a quadruple of
2009/// `Self` values.
2010///
2011/// The more significant number always comes first. Addition is wrapping, and overflow is not
2012/// indicated.
2013pub trait XXXXAddYYYYToZZZZ: Sized {
2014    #[allow(clippy::too_many_arguments)]
2015    fn xxxx_add_yyyy_to_zzzz(
2016        x_3: Self,
2017        x_2: Self,
2018        x_1: Self,
2019        x_0: Self,
2020        y_3: Self,
2021        y_2: Self,
2022        y_1: Self,
2023        y_0: Self,
2024    ) -> (Self, Self, Self, Self);
2025}