use core::mem;
pub type LimbRepr = u64;
pub type DoubleLimbRepr = u128;
const REPR_ZERO: LimbRepr = 0x0;
const REPR_ONE: LimbRepr = 0x1;
const REPR_ONES: LimbRepr = !REPR_ZERO;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Limb(LimbRepr);
impl Limb {
pub const BITS: usize = mem::size_of::<LimbRepr>();
pub const ZERO: Limb = Limb(REPR_ZERO);
pub const ONE: Limb = Limb(REPR_ONE);
pub const ONES: Limb = Limb(REPR_ONES);
pub fn repr(self) -> LimbRepr {
self.0
}
}
macro_rules! impl_fmt {
($ty:ty: [$($trait:ident),* $(,)*]) => {
$(
impl core::fmt::$trait for $ty {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.repr().fmt(f)
}
}
)*
};
}
impl_fmt!(Limb: [Binary, Octal, LowerHex, UpperHex]);