mesh_loader/utils/float/
common.rs1pub(crate) trait ByteSlice {
5 fn read_u64le(&self) -> u64;
7
8 fn write_u64le(&mut self, value: u64);
10
11 fn offset_from(&self, other: &Self) -> isize;
13
14 #[allow(clippy::impl_trait_in_params)] fn parse_digits(&self, func: impl FnMut(u8)) -> &Self;
19}
20
21impl ByteSlice for [u8] {
22 #[inline(always)] fn read_u64le(&self) -> u64 {
24 u64::from_le_bytes(self[..8].try_into().unwrap())
25 }
26
27 #[inline(always)] fn write_u64le(&mut self, value: u64) {
29 self[..8].copy_from_slice(&value.to_le_bytes());
30 }
31
32 #[inline]
33 fn offset_from(&self, other: &Self) -> isize {
34 other.len() as isize - self.len() as isize
35 }
36
37 #[inline]
38 fn parse_digits(&self, mut func: impl FnMut(u8)) -> &Self {
39 let mut s = self;
40
41 while let [c, s_next @ ..] = s {
45 let c = c.wrapping_sub(b'0');
46 if c < 10 {
47 func(c);
48 s = s_next;
49 } else {
50 break;
51 }
52 }
53
54 s
55 }
56}
57
58pub(crate) const fn is_8digits(v: u64) -> bool {
61 let a = v.wrapping_add(0x4646_4646_4646_4646);
62 let b = v.wrapping_sub(0x3030_3030_3030_3030);
63 (a | b) & 0x8080_8080_8080_8080 == 0
64}
65
66#[derive(Copy, Clone, PartialEq, Eq, Default)]
69pub(crate) struct BiasedFp {
70 pub(crate) f: u64,
72 pub(crate) e: i32,
74}
75
76impl BiasedFp {
77 #[inline]
78 pub(crate) const fn zero_pow2(e: i32) -> Self {
79 Self { f: 0, e }
80 }
81}