pub struct UInt<U, B> { /* private fields */ }
Expand description
UInt
is defined recursively, where B
is the least significant bit and U
is the rest
of the number. Conceptually, U
should be bound by the trait Unsigned
and B
should
be bound by the trait Bit
, but enforcing these bounds causes linear instead of
logrithmic scaling in some places, so they are left off for now. They may be enforced in
future.
In order to keep numbers unique, leading zeros are not allowed, so UInt<UTerm, B0>
is
forbidden.
§Example
use typenum::{UInt, UTerm, B0, B1};
type U6 = UInt<UInt<UInt<UTerm, B1>, B1>, B0>;
Implementations§
Trait Implementations§
source§impl<Ul, Ur: Unsigned> Add<UInt<Ur, B0>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> Add<UInt<Ur, B0>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
source§impl<Ul, Ur: Unsigned> Add<UInt<Ur, B0>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> Add<UInt<Ur, B0>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>
source§impl<Ul, Ur: Unsigned> Add<UInt<Ur, B1>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> Add<UInt<Ur, B1>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
source§impl<Ul, Ur: Unsigned> Add<UInt<Ur, B1>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> Add<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>
source§impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitAnd<Ur> for UInt<Ul, Bl>
impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitAnd<Ur> for UInt<Ul, Bl>
Anding unsigned integers.
We use our PrivateAnd
operator and then Trim
the output.
source§impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B0>
UInt<Ul, B0> | UInt<Ur, B0> = UInt<Ul | Ur, B0>
source§impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B0>> for UInt<Ul, B1>
UInt<Ul, B1> | UInt<Ur, B0> = UInt<Ul | Ur, B1>
source§impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B0>
UInt<Ul, B0> | UInt<Ur, B1> = UInt<Ul | Ur, B1>
source§impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> BitOr<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1> | UInt<Ur, B1> = UInt<Ul | Ur, B1>
source§impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitXor<Ur> for UInt<Ul, Bl>
impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> BitXor<Ur> for UInt<Ul, Bl>
Xoring unsigned integers.
We use our PrivateXor
operator and then Trim
the output.
source§impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B0>
UInt<Ul, B0>
cmp with UInt<Ur, B0>
: SoFar
is Equal
source§impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B1>
UInt<Ul, B1>
cmp with UInt<Ur, B0>
: SoFar
is Greater
source§impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B0>
impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B0>
UInt<Ul, B0>
cmp with UInt<Ur, B1>
: SoFar
is Less
source§impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B1>
impl<Ul, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1>
cmp with UInt<Ur, B1>
: SoFar
is Equal
source§impl<Xp, Yp> Gcd<UInt<Yp, B0>> for UInt<Xp, B0>
impl<Xp, Yp> Gcd<UInt<Yp, B0>> for UInt<Xp, B0>
gcd(x, y) = 2*gcd(x/2, y/2) if both x and y even
source§impl<Xp, Yp> Gcd<UInt<Yp, B1>> for UInt<Xp, B1>where
UInt<Xp, B1>: Max<UInt<Yp, B1>> + Min<UInt<Yp, B1>>,
UInt<Yp, B1>: Max<UInt<Xp, B1>> + Min<UInt<Xp, B1>>,
Maximum<UInt<Xp, B1>, UInt<Yp, B1>>: Sub<Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>,
Diff<Maximum<UInt<Xp, B1>, UInt<Yp, B1>>, Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>: Gcd<Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>,
impl<Xp, Yp> Gcd<UInt<Yp, B1>> for UInt<Xp, B1>where
UInt<Xp, B1>: Max<UInt<Yp, B1>> + Min<UInt<Yp, B1>>,
UInt<Yp, B1>: Max<UInt<Xp, B1>> + Min<UInt<Xp, B1>>,
Maximum<UInt<Xp, B1>, UInt<Yp, B1>>: Sub<Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>,
Diff<Maximum<UInt<Xp, B1>, UInt<Yp, B1>>, Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>: Gcd<Minimum<UInt<Xp, B1>, UInt<Yp, B1>>>,
gcd(x, y) = gcd([max(x, y) - min(x, y)], min(x, y)) if both x and y odd
This will immediately invoke the case for x even and y odd because the difference of two odd numbers is an even number.
source§impl<Ul, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B0>
impl<Ul, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B0>
UInt<Ul, B0> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0>
source§impl<Ul, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B1>
impl<Ul, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B1>
UInt<Ul, B1> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0> + UInt<Ur, B>
source§impl<U: Ord, B: Ord> Ord for UInt<U, B>
impl<U: Ord, B: Ord> Ord for UInt<U, B>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<U: PartialOrd, B: PartialOrd> PartialOrd for UInt<U, B>
impl<U: PartialOrd, B: PartialOrd> PartialOrd for UInt<U, B>
source§impl<U: Unsigned, B: Bit> Shl<B0> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shl<B0> for UInt<U, B>
Shifting left any unsigned by a zero bit: U << B0 = U
source§impl<U: Unsigned, B: Bit> Shl<B1> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shl<B1> for UInt<U, B>
Shifting left a UInt
by a one bit: UInt<U, B> << B1 = UInt<UInt<U, B>, B0>
source§impl<U: Unsigned, B: Bit, Ur: Unsigned, Br: Bit> Shl<UInt<Ur, Br>> for UInt<U, B>
impl<U: Unsigned, B: Bit, Ur: Unsigned, Br: Bit> Shl<UInt<Ur, Br>> for UInt<U, B>
Shifting left UInt
by UInt
: X << Y
= UInt(X, B0) << (Y - 1)
source§impl<U: Unsigned, B: Bit> Shl<UTerm> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shl<UTerm> for UInt<U, B>
Shifting left UInt
by UTerm
: UInt<U, B> << UTerm = UInt<U, B>
source§impl<U: Unsigned, B: Bit> Shr<B0> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shr<B0> for UInt<U, B>
Shifting right any unsigned by a zero bit: U >> B0 = U
source§impl<U: Unsigned, B: Bit> Shr<B1> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shr<B1> for UInt<U, B>
Shifting right a UInt
by a 1 bit: UInt<U, B> >> B1 = U
source§impl<U, B: Bit, Ur: Unsigned, Br: Bit> Shr<UInt<Ur, Br>> for UInt<U, B>
impl<U, B: Bit, Ur: Unsigned, Br: Bit> Shr<UInt<Ur, Br>> for UInt<U, B>
Shifting right UInt
by UInt
: UInt(U, B) >> Y
= U >> (Y - 1)
source§impl<U: Unsigned, B: Bit> Shr<UTerm> for UInt<U, B>
impl<U: Unsigned, B: Bit> Shr<UTerm> for UInt<U, B>
Shifting right UInt
by UTerm
: UInt<U, B> >> UTerm = UInt<U, B>
source§impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> Sub<Ur> for UInt<Ul, Bl>
impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub
and then Trim
the output.
source§impl<U: Unsigned, B: Bit> Unsigned for UInt<U, B>
impl<U: Unsigned, B: Bit> Unsigned for UInt<U, B>
const U8: u8 = _
const U16: u16 = _
const U32: u32 = _
const U64: u64 = _
const USIZE: usize = _
const I8: i8 = _
const I16: i16 = _
const I32: i32 = _
const I64: i64 = _
const ISIZE: isize = _
fn to_u8() -> u8
fn to_u16() -> u16
fn to_u32() -> u32
fn to_u64() -> u64
fn to_usize() -> usize
fn to_i8() -> i8
fn to_i16() -> i16
fn to_i32() -> i32
fn to_i64() -> i64
fn to_isize() -> isize
impl<U: Copy, B: Copy> Copy for UInt<U, B>
impl<U: Eq, B: Eq> Eq for UInt<U, B>
impl<U: Unsigned, B: Bit> NonZero for UInt<U, B>
impl<U: Unsigned + PowerOfTwo> PowerOfTwo for UInt<U, B0>
impl PowerOfTwo for UInt<UTerm, B1>
impl<U, B> StructuralPartialEq for UInt<U, B>
Auto Trait Implementations§
impl<U, B> Freeze for UInt<U, B>
impl<U, B> RefUnwindSafe for UInt<U, B>where
U: RefUnwindSafe,
B: RefUnwindSafe,
impl<U, B> Send for UInt<U, B>
impl<U, B> Sync for UInt<U, B>
impl<U, B> Unpin for UInt<U, B>
impl<U, B> UnwindSafe for UInt<U, B>where
U: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)