ff_uint/num/
mod.rs

1#[macro_use]
2pub(crate) mod macros;
3
4#[cfg(feature = "borsh_support")]
5use crate::borsh::{BorshDeserialize, BorshSerialize};
6#[cfg(feature = "serde_support")]
7use crate::serde::{Deserialize, Deserializer, Serialize, Serializer};
8use crate::{PrimeField, Uint};
9
10use crate::maybestd::vec;
11
12use ref_cast::RefCast;
13
14use crate::seedbox::{SeedBox, SeedBoxGen, SeedboxChaCha20};
15use core::convert::TryInto;
16
17#[repr(transparent)]
18#[derive(Clone, Copy, RefCast)]
19pub struct NumRepr<U: Uint>(pub U);
20
21#[repr(transparent)]
22#[derive(Clone, Copy, RefCast)]
23pub struct Num<Fp: PrimeField>(pub Fp);
24
25// num ops for Uint
26
27impl<U: Uint> NumRepr<U> {
28    pub const ONE: Self = NumRepr(U::ONE);
29    pub const ZERO: Self = NumRepr(U::ZERO);
30    pub const MAX: Self = NumRepr(U::MAX);
31
32    pub fn new(n: U) -> Self {
33        Self(n)
34    }
35
36    pub fn is_zero(self) -> bool {
37        self == Self::ZERO
38    }
39
40    pub fn is_even(&self) -> bool {
41        self.0.is_even()
42    }
43
44    pub fn is_odd(&self) -> bool {
45        self.0.is_odd()
46    }
47
48    pub fn into_inner(self) -> U::Inner {
49        self.0.into_inner()
50    }
51    pub fn as_inner(&self) -> &U::Inner {
52        self.0.as_inner()
53    }
54    pub fn as_inner_mut(&mut self) -> &mut U::Inner {
55        self.0.as_inner_mut()
56    }
57}
58
59#[cfg(feature = "rand_support")]
60impl<U: Uint> crate::rand::distributions::Distribution<NumRepr<U>>
61    for crate::rand::distributions::Standard
62{
63    #[inline]
64    fn sample<R: crate::rand::Rng + ?Sized>(&self, rng: &mut R) -> NumRepr<U> {
65        NumRepr::new(U::random(rng))
66    }
67}
68
69#[cfg(feature = "borsh_support")]
70impl<U: Uint> BorshSerialize for NumRepr<U> {
71    fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> Result<(), borsh::maybestd::io::Error> {
72        self.0.serialize(writer)
73    }
74}
75
76#[cfg(feature = "borsh_support")]
77impl<U: Uint> BorshDeserialize for NumRepr<U> {
78    fn deserialize(buf: &mut &[u8]) -> Result<Self, borsh::maybestd::io::Error> {
79        Ok(Self(U::deserialize(buf)?))
80    }
81}
82
83#[cfg(feature = "serde_support")]
84impl<U: Uint> Serialize for NumRepr<U> {
85    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
86        #[cfg(not(feature = "std"))]
87        use crate::maybestd::string::ToString;
88        Serialize::serialize(&self.to_string(), serializer)
89    }
90}
91
92#[cfg(feature = "serde_support")]
93impl<'de, U: Uint> Deserialize<'de> for NumRepr<U> {
94    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
95        core::str::FromStr::from_str(&<alloc::string::String as Deserialize>::deserialize(deserializer)?)
96            .map_err(|_| crate::serde::de::Error::custom("Wrong number format"))
97    }
98}
99
100impl_num_overflowing_unop!(impl <U:Uint> Not for NumRepr<U>, not, overflowing_not);
101impl_num_overflowing_unop!(impl <U:Uint> Neg for NumRepr<U>, neg, overflowing_neg);
102
103impl_num_overflowing_binop!(impl <U:Uint> Add for NumRepr<U>, add, overflowing_add);
104impl_num_overflowing_binop!(impl <U:Uint> Sub for NumRepr<U>, sub, overflowing_sub);
105impl_num_overflowing_binop!(impl <U:Uint> Mul for NumRepr<U>, mul, overflowing_mul);
106impl_num_overflowing_binop_primitive!(impl <U:Uint> Mul<u64> for NumRepr<U>, mul, overflowing_mul_u64);
107impl_num_overflowing_binop!(impl <U:Uint> Div for NumRepr<U>, div, overflowing_div);
108impl_num_overflowing_binop!(impl <U:Uint> Rem for NumRepr<U>, rem, overflowing_rem);
109impl_num_overflowing_binop_primitive!(impl <U:Uint> Shr<u32> for NumRepr<U>, shr, overflowing_shr);
110impl_num_overflowing_binop_primitive!(impl <U:Uint> Shl<u32> for NumRepr<U>, shl, overflowing_shl);
111
112impl_num_overflowing_binop!(impl <U:Uint> BitAnd for NumRepr<U>, bitand, overflowing_bitand);
113impl_num_overflowing_binop!(impl <U:Uint> BitOr for NumRepr<U>, bitor, overflowing_bitor);
114impl_num_overflowing_binop!(impl <U:Uint> BitXor for NumRepr<U>, bitxor, overflowing_bitxor);
115
116impl_num_overflowing_assignop!(impl <U:Uint> AddAssign for NumRepr<U>, add_assign, overflowing_add);
117impl_num_overflowing_assignop!(impl <U:Uint> SubAssign for NumRepr<U>, sub_assign, overflowing_sub);
118impl_num_overflowing_assignop!(impl <U:Uint> MulAssign for NumRepr<U>, mul_assign, overflowing_mul);
119impl_num_overflowing_assignop_primitive!(impl <U:Uint> MulAssign<u64> for NumRepr<U>, mul_assign, overflowing_mul_u64);
120impl_num_overflowing_assignop!(impl <U:Uint> DivAssign for NumRepr<U>, div_assign, overflowing_div);
121impl_num_overflowing_assignop!(impl <U:Uint> RemAssign for NumRepr<U>, rem_assign, overflowing_rem);
122impl_num_overflowing_assignop_primitive!(impl <U:Uint> ShrAssign<u32> for NumRepr<U>, shr_assign, overflowing_shr);
123impl_num_overflowing_assignop_primitive!(impl <U:Uint> ShlAssign<u32> for NumRepr<U>, shl_assign, overflowing_shl);
124
125impl_num_overflowing_assignop!(impl <U:Uint> BitAndAssign for NumRepr<U>, bitand_assign, overflowing_bitand);
126impl_num_overflowing_assignop!(impl <U:Uint> BitOrAssign for NumRepr<U>, bitor_assign, overflowing_bitor);
127impl_num_overflowing_assignop!(impl <U:Uint> BitXorAssign for NumRepr<U>, bitxor_assign, overflowing_bitxor);
128
129impl_num_map_from!(impl<U:Uint> From<bool> for NumRepr<U>);
130impl_num_map_from!(impl<U:Uint> From<u8> for NumRepr<U>);
131impl_num_map_from!(impl<U:Uint> From<u16> for NumRepr<U>);
132impl_num_map_from!(impl<U:Uint> From<u32> for NumRepr<U>);
133impl_num_map_from!(impl<U:Uint> From<u64> for NumRepr<U>);
134impl_num_map_from!(impl<U:Uint> From<u128> for NumRepr<U>);
135impl_num_map_from!(impl<U:Uint> From<i8> for NumRepr<U>);
136impl_num_map_from!(impl<U:Uint> From<i16> for NumRepr<U>);
137impl_num_map_from!(impl<U:Uint> From<i32> for NumRepr<U>);
138impl_num_map_from!(impl<U:Uint> From<i64> for NumRepr<U>);
139impl_num_map_from!(impl<U:Uint> From<i128> for NumRepr<U>);
140
141impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for bool);
142
143impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for u8);
144impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for u16);
145impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for u32);
146impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for u64);
147impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for u128);
148
149impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for i8);
150impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for i16);
151impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for i32);
152impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for i64);
153impl_num_try_from_for_primitive!(impl<U:Uint> TryFrom<NumRepr<U>> for i128);
154
155impl<U: Uint> core::cmp::Ord for NumRepr<U> {
156    #[inline]
157    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
158        self.0.wrapping_cmp(&other.0)
159    }
160}
161
162impl<U: Uint> core::cmp::PartialOrd for NumRepr<U> {
163    #[inline]
164    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
165        Some(self.cmp(other))
166    }
167}
168
169impl<U: Uint> core::cmp::PartialEq for NumRepr<U> {
170    #[inline]
171    fn eq(&self, other: &Self) -> bool {
172        self.0.eq(&other.0)
173    }
174}
175
176impl<U: Uint> core::cmp::Eq for NumRepr<U> {}
177
178impl<U: Uint> core::hash::Hash for NumRepr<U> {
179    fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
180        self.0.hash(state);
181    }
182}
183
184impl<U: Uint> core::fmt::Debug for NumRepr<U> {
185    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
186        core::fmt::Display::fmt(&self, f)
187    }
188}
189
190impl<U: Uint> core::fmt::Display for NumRepr<U> {
191    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
192        if self.is_zero() {
193            return core::write!(f, "0");
194        }
195
196        // error: constant expression depends on a generic parameter
197        // let mut buf = [0_u8; U::NUM_WORDS * 20];
198
199        let mut buf = vec![0u8; U::NUM_WORDS * 20];
200        let mut i = buf.len() - 1;
201        let mut current = self.0;
202        let ten = U::from_u64(10);
203        loop {
204            let t = current.wrapping_rem(ten);
205            let digit = t.low_u64() as u8;
206            buf[i] = digit + b'0';
207            current = current.wrapping_div(ten);
208            if current.is_zero() {
209                break;
210            }
211            i -= 1;
212        }
213
214        // sequence of `'0'..'9'` chars is guaranteed to be a valid UTF8 string
215        let s = unsafe { core::str::from_utf8_unchecked(&buf[i..]) };
216        f.write_str(s)
217    }
218}
219
220impl<U: Uint> core::fmt::LowerHex for NumRepr<U> {
221    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
222        if f.alternate() {
223            core::write!(f, "0x")?;
224        }
225        // special case.
226        if self.is_zero() {
227            return core::write!(f, "0");
228        }
229
230        let mut latch = false;
231        for ch in self.0.as_inner().as_ref().iter().rev() {
232            for x in 0..16 {
233                let nibble = (ch & (15u64 << ((15 - x) * 4) as u64)) >> (((15 - x) * 4) as u64);
234                if !latch {
235                    latch = nibble != 0;
236                }
237
238                if latch {
239                    core::write!(f, "{:x}", nibble)?;
240                }
241            }
242        }
243        Ok(())
244    }
245}
246
247impl<U: Uint> core::str::FromStr for NumRepr<U> {
248    type Err = <U as core::str::FromStr>::Err;
249
250    fn from_str(value: &str) -> core::result::Result<NumRepr<U>, Self::Err> {
251        Ok(<NumRepr<U>>::new(U::from_str(value)?))
252    }
253}
254
255impl<U: Uint> core::convert::From<&'static str> for NumRepr<U> {
256    fn from(s: &'static str) -> Self {
257        <NumRepr<U>>::new(U::from(s))
258    }
259}
260
261// num ops for PrimeField
262#[cfg(feature = "rand_support")]
263impl<Fp: PrimeField> crate::rand::distributions::Distribution<Num<Fp>>
264    for crate::rand::distributions::Standard
265{
266    #[inline]
267    fn sample<R: crate::rand::Rng + ?Sized>(&self, rng: &mut R) -> Num<Fp> {
268        Num::new(Fp::random(rng))
269    }
270}
271
272#[cfg(feature = "borsh_support")]
273impl<Fp: PrimeField> BorshSerialize for Num<Fp> {
274    fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> Result<(), borsh::maybestd::io::Error> {
275        self.0.serialize(writer)
276    }
277}
278
279#[cfg(feature = "borsh_support")]
280impl<Fp: PrimeField> BorshDeserialize for Num<Fp> {
281    fn deserialize(buf: &mut &[u8]) -> Result<Self, borsh::maybestd::io::Error> {
282        Ok(Self(Fp::deserialize(buf)?))
283    }
284}
285
286impl<Fp: PrimeField> SeedBoxGen<Num<Fp>> for SeedboxChaCha20 {
287    fn gen(&mut self) -> Num<Fp> {
288        let mut n = Fp::Inner::ZERO;
289        let shave = 0xffffffffffffffffu64 >> Fp::REPR_SHAVE_BITS;
290        let len = Fp::Inner::NUM_WORDS;
291        loop {
292            {
293                let p = n.as_inner_mut().as_mut();
294                self.fill_limbs(p);
295                p[len-1] &= shave;
296            }
297            match Num::from_mont_uint(NumRepr(n)) {
298                Some(n) => return n,
299                _ => {}
300            }
301        }
302    }
303}
304
305impl<Fp: PrimeField> Num<Fp> {
306    pub const ZERO: Self = Num(Fp::ZERO);
307    pub const ONE: Self = Num(Fp::ONE);
308    pub const MODULUS: NumRepr<Fp::Inner> = NumRepr(Fp::MODULUS);
309    pub const MODULUS_BITS: u32 = Fp::MODULUS_BITS;
310
311    pub fn is_even(&self) -> bool {
312        self.to_uint().0.is_even()
313    }
314
315    pub fn is_odd(&self) -> bool {
316        self.to_uint().0.is_odd()
317    }
318
319    pub fn double(self) -> Self {
320        Self(self.0.double())
321    }
322
323    pub fn square(self) -> Self {
324        Self(self.0.square())
325    }
326
327    pub fn new(n: Fp) -> Self {
328        Self(n)
329    }
330
331    pub fn checked_inv(self) -> Option<Self> {
332        Some(Self(self.0.checked_inv()?))
333    }
334
335    pub fn is_zero(self) -> bool {
336        self == Self::ZERO
337    }
338
339    pub fn from_uint(v: NumRepr<Fp::Inner>) -> Option<Self> {
340        Some(Self(Fp::from_uint(v.0)?))
341    }
342
343    pub fn from_uint_reduced(v: NumRepr<Fp::Inner>) -> Self {
344        let n = v % Num::<Fp>::MODULUS;
345        Self(Fp::from_uint_unchecked(n.0))
346    }
347
348    pub fn from_mont_uint(v: NumRepr<Fp::Inner>) -> Option<Self> {
349        Some(Self(Fp::from_mont_uint(v.0)?))
350    }
351
352    pub fn from_uint_unchecked(v: NumRepr<Fp::Inner>) -> Self {
353        Self(Fp::from_uint_unchecked(v.0))
354    }
355
356    pub fn from_mont_uint_unchecked(v: NumRepr<Fp::Inner>) -> Self {
357        Self(Fp::from_mont_uint_unchecked(v.0))
358    }
359
360    pub fn sqrt(&self) -> Option<Self> {
361        Some(Self(self.0.sqrt()?))
362    }
363
364    pub fn even_sqrt(&self) -> Option<Self> {
365        let res = self.sqrt()?;
366        if res.to_uint().is_even() {
367            Some(res)
368        } else {
369            Some(-res)
370        }
371    }
372
373    pub fn to_uint(&self) -> NumRepr<Fp::Inner> {
374        NumRepr(self.0.to_uint())
375    }
376
377    pub fn to_mont_uint(&self) -> NumRepr<Fp::Inner> {
378        NumRepr(self.0.to_mont_uint())
379    }
380
381    pub fn as_mont_uint(&self) -> &NumRepr<Fp::Inner> {
382        NumRepr::ref_cast(self.0.as_mont_uint())
383    }
384
385    pub fn as_mont_uint_mut(&mut self) -> &mut NumRepr<Fp::Inner> {
386        NumRepr::ref_cast_mut(self.0.as_mont_uint_mut())
387    }
388
389    pub fn to_other<Fq: PrimeField>(&self) -> Option<Num<Fq>> {
390        Some(Num(self.0.to_other()?))
391    }
392
393    pub fn to_other_reduced<Fq: PrimeField>(&self) -> Num<Fq> {
394        Num(self.0.to_other_reduced())
395    }
396}
397
398impl_num_wrapping_unop!(impl <U:PrimeField> Neg for Num<U>, neg, wrapping_neg);
399impl_num_wrapping_binop!(impl <U:PrimeField> Add for Num<U>, add, wrapping_add);
400impl_num_wrapping_binop!(impl <U:PrimeField> Sub for Num<U>, sub, wrapping_sub);
401impl_num_wrapping_binop!(impl <U:PrimeField> Mul for Num<U>, mul, wrapping_mul);
402impl_num_wrapping_binop!(impl <U:PrimeField> Div for Num<U>, div, wrapping_div);
403
404impl_num_wrapping_assignop!(impl <U:PrimeField> AddAssign for Num<U>, add_assign, wrapping_add);
405impl_num_wrapping_assignop!(impl <U:PrimeField> SubAssign for Num<U>, sub_assign, wrapping_sub);
406impl_num_wrapping_assignop!(impl <U:PrimeField> MulAssign for Num<U>, mul_assign, wrapping_mul);
407impl_num_wrapping_assignop!(impl <U:PrimeField> DivAssign for Num<U>, div_assign, wrapping_div);
408
409impl<Fp: PrimeField> core::cmp::PartialEq for Num<Fp> {
410    #[inline]
411    fn eq(&self, other: &Self) -> bool {
412        self.0.eq(&other.0)
413    }
414}
415
416impl<Fp: PrimeField> core::cmp::Eq for Num<Fp> {}
417
418impl<Fp: PrimeField> core::fmt::Debug for Num<Fp> {
419    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
420        core::fmt::Debug::fmt(&self.0, f)
421    }
422}
423
424impl<Fp: PrimeField> core::fmt::Display for Num<Fp> {
425    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
426        core::fmt::Display::fmt(&self.0, f)
427    }
428}
429
430impl<Fp: PrimeField> core::str::FromStr for Num<Fp> {
431    type Err = <Fp as core::str::FromStr>::Err;
432
433    fn from_str(value: &str) -> core::result::Result<Num<Fp>, Self::Err> {
434        Ok(<Num<Fp>>::new(Fp::from_str(value)?))
435    }
436}
437
438impl<Fp: PrimeField> core::convert::From<&'static str> for Num<Fp> {
439    fn from(s: &'static str) -> Self {
440        <Num<Fp>>::new(Fp::from(s))
441    }
442}
443
444#[cfg(feature = "serde_support")]
445impl<Fp: PrimeField> Serialize for Num<Fp> {
446    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
447        #[cfg(not(feature = "std"))]
448        use crate::maybestd::string::ToString;
449        Serialize::serialize(&self.to_string(), serializer)
450    }
451}
452
453#[cfg(feature = "serde_support")]
454impl<'de, Fp: PrimeField> Deserialize<'de> for Num<Fp> {
455    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
456        let bn = <NumRepr<Fp::Inner> as Deserialize>::deserialize(deserializer)?;
457        Self::from_uint(bn).ok_or(crate::serde::de::Error::custom("Field overflow"))
458    }
459}
460
461impl<Fp: PrimeField> From<bool> for Num<Fp> {
462    fn from(n: bool) -> Self {
463        match n {
464            false => Self::ZERO,
465            true => Self::ONE,
466        }
467    }
468}
469
470impl_fnum_map_from!(impl<Fp:PrimeField> From<u8> for Num<Fp>);
471impl_fnum_map_from!(impl<Fp:PrimeField> From<u16> for Num<Fp>);
472impl_fnum_map_from!(impl<Fp:PrimeField> From<u32> for Num<Fp>);
473impl_fnum_map_from!(impl<Fp:PrimeField> From<u64> for Num<Fp>);
474impl_fnum_map_from!(impl<Fp:PrimeField> From<u128> for Num<Fp>);
475
476impl_fnum_map_from_signed!(impl<Fp:PrimeField> From<i8> for Num<Fp>);
477impl_fnum_map_from_signed!(impl<Fp:PrimeField> From<i16> for Num<Fp>);
478impl_fnum_map_from_signed!(impl<Fp:PrimeField> From<i32> for Num<Fp>);
479impl_fnum_map_from_signed!(impl<Fp:PrimeField> From<i64> for Num<Fp>);
480impl_fnum_map_from_signed!(impl<Fp:PrimeField> From<i128> for Num<Fp>);
481
482impl<Fp: PrimeField> core::convert::TryFrom<Num<Fp>> for bool {
483    type Error = &'static str;
484
485    #[inline]
486    fn try_from(u: Num<Fp>) -> core::result::Result<bool, &'static str> {
487        match u.to_uint().try_into() {
488            Ok(v) => Ok(v),
489            _ => Err(concat!("integer overflow when casting to bool")),
490        }
491    }
492}
493
494impl_fnum_try_from_for_primitive!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for u8);
495impl_fnum_try_from_for_primitive!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for u16);
496impl_fnum_try_from_for_primitive!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for u32);
497impl_fnum_try_from_for_primitive!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for u64);
498impl_fnum_try_from_for_primitive!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for u128);
499
500impl_fnum_try_from_for_primitive_signed!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for i8);
501impl_fnum_try_from_for_primitive_signed!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for i16);
502impl_fnum_try_from_for_primitive_signed!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for i32);
503impl_fnum_try_from_for_primitive_signed!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for i64);
504impl_fnum_try_from_for_primitive_signed!(impl<Fp:PrimeField> TryFrom<Num<Fp>> for i128);
505
506use crate::{BitIterBE, BitIterLE, BitIteratorBE, BitIteratorLE};
507
508impl<I: Uint> BitIterBE for NumRepr<I> {
509    type Iter = BitIteratorBE<I>;
510
511    fn bit_iter_be(&self) -> Self::Iter {
512        self.0.bit_iter_be()
513    }
514}
515
516impl<I: Uint> BitIterLE for NumRepr<I> {
517    type Iter = BitIteratorLE<I>;
518
519    fn bit_iter_le(&self) -> Self::Iter {
520        self.0.bit_iter_le()
521    }
522}
523
524impl<Fp: PrimeField> BitIterBE for Num<Fp> {
525    type Iter = BitIteratorBE<Fp::Inner>;
526
527    fn bit_iter_be(&self) -> Self::Iter {
528        self.to_uint().bit_iter_be()
529    }
530}
531
532impl<Fp: PrimeField> BitIterLE for Num<Fp> {
533    type Iter = BitIteratorLE<Fp::Inner>;
534
535    fn bit_iter_le(&self) -> Self::Iter {
536        self.to_uint().bit_iter_le()
537    }
538}