malachite_base/num/basic/
unsigneds.rs

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