pub(crate) trait ByteSlice {
fn read_u64(&self) -> u64;
fn write_u64(&mut self, value: u64);
fn offset_from(&self, other: &Self) -> isize;
fn parse_digits(&self, func: impl FnMut(u8)) -> &Self;
}
impl ByteSlice for [u8] {
#[inline(always)] fn read_u64(&self) -> u64 {
let mut tmp = [0; 8];
tmp.copy_from_slice(&self[..8]);
u64::from_le_bytes(tmp)
}
#[inline(always)] fn write_u64(&mut self, value: u64) {
self[..8].copy_from_slice(&value.to_le_bytes())
}
#[inline]
fn offset_from(&self, other: &Self) -> isize {
other.len() as isize - self.len() as isize
}
#[inline]
fn parse_digits(&self, mut func: impl FnMut(u8)) -> &Self {
let mut s = self;
while let [c, s_next @ ..] = s {
let c = c.wrapping_sub(b'0');
if c < 10 {
func(c);
s = s_next;
} else {
break;
}
}
s
}
}
pub(crate) fn is_8digits(v: u64) -> bool {
let a = v.wrapping_add(0x4646_4646_4646_4646);
let b = v.wrapping_sub(0x3030_3030_3030_3030);
(a | b) & 0x8080_8080_8080_8080 == 0
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
pub struct BiasedFp {
pub f: u64,
pub e: i32,
}
impl BiasedFp {
#[inline]
pub const fn zero_pow2(e: i32) -> Self {
Self { f: 0, e }
}
}