Skip to main content

malachite_base/num/basic/
unsigneds.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::arithmetic::traits::{
10    AbsDiff, AbsDiffAssign, BalancedMod, BellNumber, CeilingDivAssignNegMod, CeilingDivNegMod,
11    CeilingLogBase, CeilingLogBase2, CeilingLogBasePowerOf2, CheckedBellNumber,
12    CheckedDoubleFactorial, CheckedFactorial, CheckedFibonacci, CheckedLcm, CheckedLogBase,
13    CheckedLogBase2, CheckedLogBasePowerOf2, CheckedLucasNumber, CheckedMultifactorial,
14    CheckedNextPowerOf2, CheckedPrimorial, CheckedSubfactorial, CoprimeWith, DoubleFactorial,
15    ExtendedGcd, Factorial, Fibonacci, FloorLogBase, FloorLogBase2, FloorLogBasePowerOf2, Gcd,
16    GcdAssign, IsPowerOf2, Lcm, LcmAssign, LucasNumber, ModAdd, ModAddAssign, ModInverse,
17    ModIsReduced, ModMul, ModMulAssign, ModMulPrecomputed, ModMulPrecomputedAssign, ModNeg,
18    ModNegAssign, ModPow, ModPowAssign, ModPowPrecomputed, ModPowPrecomputedAssign, ModPowerOf2,
19    ModPowerOf2Add, ModPowerOf2AddAssign, ModPowerOf2Inverse, ModPowerOf2IsReduced, ModPowerOf2Mul,
20    ModPowerOf2MulAssign, ModPowerOf2Neg, ModPowerOf2NegAssign, ModPowerOf2Pow,
21    ModPowerOf2PowAssign, ModPowerOf2Shl, ModPowerOf2ShlAssign, ModPowerOf2Shr,
22    ModPowerOf2ShrAssign, ModPowerOf2Square, ModPowerOf2SquareAssign, ModPowerOf2Sub,
23    ModPowerOf2SubAssign, ModSquare, ModSquareAssign, ModSquarePrecomputed,
24    ModSquarePrecomputedAssign, ModSub, ModSubAssign, Multifactorial, NegMod, NegModAssign,
25    NegModPowerOf2, NegModPowerOf2Assign, NextPowerOf2, NextPowerOf2Assign, Primorial,
26    RootAssignRem, RootRem, SqrtAssignRem, SqrtRem, Subfactorial, UnsignedAbs, XMulYToZZ,
27    XXAddYYToZZ, XXDivModYToQR, XXSubYYToZZ, XXXAddYYYToZZZ, XXXSubYYYToZZZ, XXXXAddYYYYToZZZZ,
28};
29use crate::num::basic::integers::PrimitiveInt;
30use crate::num::basic::signeds::PrimitiveSigned;
31use crate::num::comparison::traits::OrdDouble;
32use crate::num::conversion::traits::{
33    Digits, FromOtherTypeSlice, IntegerMantissaAndExponent, PowerOf2DigitIterable, PowerOf2Digits,
34    SciMantissaAndExponent, VecFromOtherType, VecFromOtherTypeSlice,
35};
36use crate::num::factorization::primes::{PrimesIterator, PrimesLessThanIterator};
37use crate::num::factorization::traits::Primes;
38use crate::num::logic::traits::{BitBlockAccess, HammingDistance};
39
40/// Defines functions on primitive unsigned integer types: uxx and usize.
41pub trait PrimitiveUnsigned:
42    AbsDiff<Self, Output = Self>
43    + AbsDiffAssign<Self>
44    + BalancedMod<Self, Output: PrimitiveSigned + UnsignedAbs<Output = Self>>
45    + BitBlockAccess<Bits = Self>
46    + CeilingLogBase<Output = u64>
47    + CeilingLogBase2<Output = u64>
48    + CeilingLogBasePowerOf2<u64, Output = u64>
49    + CeilingDivAssignNegMod<Self, ModOutput = Self>
50    + CeilingDivNegMod<Self, DivOutput = Self, ModOutput = Self>
51    + CheckedDoubleFactorial
52    + BellNumber
53    + CheckedBellNumber
54    + CheckedFactorial
55    + CheckedFibonacci
56    + CheckedMultifactorial
57    + CheckedLucasNumber
58    + CheckedPrimorial
59    + CheckedSubfactorial
60    + CheckedLcm<Self, Output = Self>
61    + CheckedLogBase<Output = u64>
62    + CheckedLogBase2<Output = u64>
63    + CheckedLogBasePowerOf2<u64, Output = u64>
64    + CheckedNextPowerOf2<Output = Self>
65    + CoprimeWith<Self>
66    + DoubleFactorial
67    + Digits<u8>
68    + Digits<u16>
69    + Digits<u32>
70    + Digits<u64>
71    + Digits<u128>
72    + Digits<usize>
73    + ExtendedGcd<Self, Gcd = Self>
74    + Factorial
75    + Fibonacci
76    + FloorLogBase<Output = u64>
77    + FloorLogBase2<Output = u64>
78    + FloorLogBasePowerOf2<u64, Output = u64>
79    + From<u8>
80    + FromOtherTypeSlice<u8>
81    + FromOtherTypeSlice<u16>
82    + FromOtherTypeSlice<u32>
83    + FromOtherTypeSlice<u64>
84    + FromOtherTypeSlice<u128>
85    + FromOtherTypeSlice<usize>
86    + Gcd<Self, Output = Self>
87    + GcdAssign<Self>
88    + HammingDistance
89    + IntegerMantissaAndExponent<Self, u64>
90    + IsPowerOf2
91    + Lcm<Self, Output = Self>
92    + LcmAssign<Self>
93    + LucasNumber
94    + ModIsReduced<Self>
95    + ModAdd<Self, Self, Output = Self>
96    + ModAddAssign<Self, Self>
97    + ModInverse<Self, Output = Self>
98    + ModMul<Self, Self, Output = Self>
99    + ModMulAssign<Self, Self>
100    + ModMulPrecomputed<Self, Self, Output = Self>
101    + ModMulPrecomputedAssign<Self, Self>
102    + ModNeg<Self, Output = Self>
103    + ModNegAssign<Self>
104    + ModPow<u64, Self, Output = Self>
105    + ModPowAssign<u64, Self>
106    + ModPowerOf2<Output = Self>
107    + ModPowerOf2Add<Self, Output = Self>
108    + ModPowerOf2AddAssign<Self>
109    + ModPowerOf2Inverse<Output = Self>
110    + ModPowerOf2IsReduced
111    + ModPowerOf2Mul<Self, Output = Self>
112    + ModPowerOf2MulAssign<Self>
113    + ModPowerOf2Neg<Output = Self>
114    + ModPowerOf2NegAssign
115    + ModPowerOf2Pow<u64, Output = Self>
116    + ModPowerOf2PowAssign<u64>
117    + ModPowerOf2Shl<i8, Output = Self>
118    + ModPowerOf2Shl<i16, Output = Self>
119    + ModPowerOf2Shl<i32, Output = Self>
120    + ModPowerOf2Shl<i64, Output = Self>
121    + ModPowerOf2Shl<i128, Output = Self>
122    + ModPowerOf2Shl<u8, Output = Self>
123    + ModPowerOf2Shl<u16, Output = Self>
124    + ModPowerOf2Shl<u32, Output = Self>
125    + ModPowerOf2Shl<u64, Output = Self>
126    + ModPowerOf2Shl<u128, Output = Self>
127    + ModPowerOf2ShlAssign<u8>
128    + ModPowerOf2ShlAssign<u16>
129    + ModPowerOf2ShlAssign<u32>
130    + ModPowerOf2ShlAssign<u64>
131    + ModPowerOf2ShlAssign<u128>
132    + ModPowerOf2ShlAssign<usize>
133    + ModPowerOf2ShlAssign<i8>
134    + ModPowerOf2ShlAssign<i16>
135    + ModPowerOf2ShlAssign<i32>
136    + ModPowerOf2ShlAssign<i64>
137    + ModPowerOf2ShlAssign<i128>
138    + ModPowerOf2ShlAssign<isize>
139    + ModPowerOf2Shr<i8, Output = Self>
140    + ModPowerOf2Shr<i16, Output = Self>
141    + ModPowerOf2Shr<i32, Output = Self>
142    + ModPowerOf2Shr<i64, Output = Self>
143    + ModPowerOf2Shr<i128, Output = Self>
144    + ModPowerOf2ShrAssign<i8>
145    + ModPowerOf2ShrAssign<i16>
146    + ModPowerOf2ShrAssign<i32>
147    + ModPowerOf2ShrAssign<i64>
148    + ModPowerOf2ShrAssign<i128>
149    + ModPowerOf2ShrAssign<isize>
150    + ModPowerOf2Square<Output = Self>
151    + ModPowerOf2SquareAssign
152    + ModPowerOf2Sub<Self, Output = Self>
153    + ModPowerOf2SubAssign<Self>
154    + ModPowPrecomputed<u64, Self, Output = Self>
155    + ModPowPrecomputedAssign<u64, Self>
156    + ModSquare<Self, Output = Self>
157    + ModSquareAssign<Self>
158    + ModSquarePrecomputed<u64, Self, Output = Self>
159    + ModSquarePrecomputedAssign<u64, Self>
160    + ModSub<Self, Self, Output = Self>
161    + ModSubAssign<Self, Self>
162    + Multifactorial
163    + NegMod<Self, Output = Self>
164    + NegModAssign<Self>
165    + NegModPowerOf2<Output = Self>
166    + NegModPowerOf2Assign
167    + NextPowerOf2<Output = Self>
168    + NextPowerOf2Assign
169    + OrdDouble<Self>
170    + PowerOf2Digits<u8>
171    + PowerOf2Digits<u16>
172    + PowerOf2Digits<u32>
173    + PowerOf2Digits<u64>
174    + PowerOf2Digits<u128>
175    + PowerOf2Digits<usize>
176    + PowerOf2DigitIterable<u8>
177    + PowerOf2DigitIterable<u16>
178    + PowerOf2DigitIterable<u32>
179    + PowerOf2DigitIterable<u64>
180    + PowerOf2DigitIterable<u128>
181    + PowerOf2DigitIterable<usize>
182    + Primes<I = PrimesIterator<Self>, LI = PrimesLessThanIterator<Self>>
183    + PrimitiveInt
184    + Primorial
185    + RootRem<u64, RootOutput = Self, RemOutput = Self>
186    + RootAssignRem<u64, RemOutput = Self>
187    + SciMantissaAndExponent<f32, u64>
188    + SciMantissaAndExponent<f64, u64>
189    + SqrtRem<SqrtOutput = Self, RemOutput = Self>
190    + SqrtAssignRem<RemOutput = Self>
191    + Subfactorial
192    + VecFromOtherType<u8>
193    + VecFromOtherType<u16>
194    + VecFromOtherType<u32>
195    + VecFromOtherType<u64>
196    + VecFromOtherType<u128>
197    + VecFromOtherType<usize>
198    + VecFromOtherTypeSlice<u8>
199    + VecFromOtherTypeSlice<u16>
200    + VecFromOtherTypeSlice<u32>
201    + VecFromOtherTypeSlice<u64>
202    + VecFromOtherTypeSlice<u128>
203    + VecFromOtherTypeSlice<usize>
204    + XXAddYYToZZ
205    + XXDivModYToQR
206    + XXSubYYToZZ
207    + XMulYToZZ
208    + XXXAddYYYToZZZ
209    + XXXSubYYYToZZZ
210    + XXXXAddYYYYToZZZZ
211{
212}
213
214macro_rules! impl_basic_traits {
215    ($u:ident) => {
216        impl PrimitiveUnsigned for $u {}
217    };
218}
219apply_to_unsigneds!(impl_basic_traits);