pub(crate) trait ByteSlice {
fn read_u64le(&self) -> u64;
fn write_u64le(&mut self, value: u64);
fn offset_from(&self, other: &Self) -> isize;
#[allow(clippy::impl_trait_in_params)] fn parse_digits(&self, func: impl FnMut(u8)) -> &Self;
}
impl ByteSlice for [u8] {
#[inline(always)] fn read_u64le(&self) -> u64 {
u64::from_le_bytes(self[..8].try_into().unwrap())
}
#[inline(always)] fn write_u64le(&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) const 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(Copy, Clone, PartialEq, Eq, Default)]
pub(crate) struct BiasedFp {
pub(crate) f: u64,
pub(crate) e: i32,
}
impl BiasedFp {
#[inline]
pub(crate) const fn zero_pow2(e: i32) -> Self {
Self { f: 0, e }
}
}