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, Lcm, LcmAssign, LucasNumber, ModAdd, ModAddAssign, ModInverse, ModIsReduced, ModMul,
17    ModMulAssign, ModMulPrecomputed, ModMulPrecomputedAssign, ModNeg, ModNegAssign, ModPow,
18    ModPowAssign, ModPowPrecomputed, ModPowPrecomputedAssign, ModPowerOf2, ModPowerOf2Add,
19    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    + Lcm<Self, Output = Self>
91    + LcmAssign<Self>
92    + LucasNumber
93    + ModIsReduced<Self>
94    + ModAdd<Self, Self, Output = Self>
95    + ModAddAssign<Self, Self>
96    + ModInverse<Self, Output = Self>
97    + ModMul<Self, Self, Output = Self>
98    + ModMulAssign<Self, Self>
99    + ModMulPrecomputed<Self, Self, Output = Self>
100    + ModMulPrecomputedAssign<Self, Self>
101    + ModNeg<Self, Output = Self>
102    + ModNegAssign<Self>
103    + ModPow<u64, Self, Output = Self>
104    + ModPowAssign<u64, Self>
105    + ModPowerOf2<Output = Self>
106    + ModPowerOf2Add<Self, Output = Self>
107    + ModPowerOf2AddAssign<Self>
108    + ModPowerOf2Inverse<Output = Self>
109    + ModPowerOf2IsReduced
110    + ModPowerOf2Mul<Self, Output = Self>
111    + ModPowerOf2MulAssign<Self>
112    + ModPowerOf2Neg<Output = Self>
113    + ModPowerOf2NegAssign
114    + ModPowerOf2Pow<u64, Output = Self>
115    + ModPowerOf2PowAssign<u64>
116    + ModPowerOf2Shl<i8, Output = Self>
117    + ModPowerOf2Shl<i16, Output = Self>
118    + ModPowerOf2Shl<i32, Output = Self>
119    + ModPowerOf2Shl<i64, Output = Self>
120    + ModPowerOf2Shl<i128, Output = Self>
121    + ModPowerOf2Shl<u8, Output = Self>
122    + ModPowerOf2Shl<u16, Output = Self>
123    + ModPowerOf2Shl<u32, Output = Self>
124    + ModPowerOf2Shl<u64, Output = Self>
125    + ModPowerOf2Shl<u128, Output = Self>
126    + ModPowerOf2ShlAssign<u8>
127    + ModPowerOf2ShlAssign<u16>
128    + ModPowerOf2ShlAssign<u32>
129    + ModPowerOf2ShlAssign<u64>
130    + ModPowerOf2ShlAssign<u128>
131    + ModPowerOf2ShlAssign<usize>
132    + ModPowerOf2ShlAssign<i8>
133    + ModPowerOf2ShlAssign<i16>
134    + ModPowerOf2ShlAssign<i32>
135    + ModPowerOf2ShlAssign<i64>
136    + ModPowerOf2ShlAssign<i128>
137    + ModPowerOf2ShlAssign<isize>
138    + ModPowerOf2Shr<i8, Output = Self>
139    + ModPowerOf2Shr<i16, Output = Self>
140    + ModPowerOf2Shr<i32, Output = Self>
141    + ModPowerOf2Shr<i64, Output = Self>
142    + ModPowerOf2Shr<i128, Output = Self>
143    + ModPowerOf2ShrAssign<i8>
144    + ModPowerOf2ShrAssign<i16>
145    + ModPowerOf2ShrAssign<i32>
146    + ModPowerOf2ShrAssign<i64>
147    + ModPowerOf2ShrAssign<i128>
148    + ModPowerOf2ShrAssign<isize>
149    + ModPowerOf2Square<Output = Self>
150    + ModPowerOf2SquareAssign
151    + ModPowerOf2Sub<Self, Output = Self>
152    + ModPowerOf2SubAssign<Self>
153    + ModPowPrecomputed<u64, Self, Output = Self>
154    + ModPowPrecomputedAssign<u64, Self>
155    + ModSquare<Self, Output = Self>
156    + ModSquareAssign<Self>
157    + ModSquarePrecomputed<u64, Self, Output = Self>
158    + ModSquarePrecomputedAssign<u64, Self>
159    + ModSub<Self, Self, Output = Self>
160    + ModSubAssign<Self, Self>
161    + Multifactorial
162    + NegMod<Self, Output = Self>
163    + NegModAssign<Self>
164    + NegModPowerOf2<Output = Self>
165    + NegModPowerOf2Assign
166    + NextPowerOf2<Output = Self>
167    + NextPowerOf2Assign
168    + OrdDouble<Self>
169    + PowerOf2Digits<u8>
170    + PowerOf2Digits<u16>
171    + PowerOf2Digits<u32>
172    + PowerOf2Digits<u64>
173    + PowerOf2Digits<u128>
174    + PowerOf2Digits<usize>
175    + PowerOf2DigitIterable<u8>
176    + PowerOf2DigitIterable<u16>
177    + PowerOf2DigitIterable<u32>
178    + PowerOf2DigitIterable<u64>
179    + PowerOf2DigitIterable<u128>
180    + PowerOf2DigitIterable<usize>
181    + Primes<I = PrimesIterator<Self>, LI = PrimesLessThanIterator<Self>>
182    + PrimitiveInt
183    + Primorial
184    + RootRem<u64, RootOutput = Self, RemOutput = Self>
185    + RootAssignRem<u64, RemOutput = Self>
186    + SciMantissaAndExponent<f32, u64>
187    + SciMantissaAndExponent<f64, u64>
188    + SqrtRem<SqrtOutput = Self, RemOutput = Self>
189    + SqrtAssignRem<RemOutput = Self>
190    + Subfactorial
191    + VecFromOtherType<u8>
192    + VecFromOtherType<u16>
193    + VecFromOtherType<u32>
194    + VecFromOtherType<u64>
195    + VecFromOtherType<u128>
196    + VecFromOtherType<usize>
197    + VecFromOtherTypeSlice<u8>
198    + VecFromOtherTypeSlice<u16>
199    + VecFromOtherTypeSlice<u32>
200    + VecFromOtherTypeSlice<u64>
201    + VecFromOtherTypeSlice<u128>
202    + VecFromOtherTypeSlice<usize>
203    + XXAddYYToZZ
204    + XXDivModYToQR
205    + XXSubYYToZZ
206    + XMulYToZZ
207    + XXXAddYYYToZZZ
208    + XXXSubYYYToZZZ
209    + XXXXAddYYYYToZZZZ
210{
211}
212
213macro_rules! impl_basic_traits {
214    ($u:ident) => {
215        impl PrimitiveUnsigned for $u {}
216    };
217}
218apply_to_unsigneds!(impl_basic_traits);