core/num/imp/dec2flt/
common.rs1pub(crate) trait ByteSlice {
5 fn read_u64(&self) -> u64;
7
8 fn write_u64(&mut self, value: u64);
10
11 fn offset_from(&self, other: &Self) -> isize;
13
14 fn parse_digits(&self, func: impl FnMut(u8)) -> &Self;
18}
19
20impl ByteSlice for [u8] {
21 #[inline(always)] fn read_u64(&self) -> u64 {
23 let mut tmp = [0; 8];
24 tmp.copy_from_slice(&self[..8]);
25 u64::from_le_bytes(tmp)
26 }
27
28 #[inline(always)] fn write_u64(&mut self, value: u64) {
30 self[..8].copy_from_slice(&value.to_le_bytes())
31 }
32
33 #[inline]
34 fn offset_from(&self, other: &Self) -> isize {
35 other.len() as isize - self.len() as isize
36 }
37
38 #[inline]
39 fn parse_digits(&self, mut func: impl FnMut(u8)) -> &Self {
40 let mut s = self;
41
42 while let Some((c, rest)) = s.split_first() {
43 let c = c.wrapping_sub(b'0');
44 if c < 10 {
45 func(c);
46 s = rest;
47 } else {
48 break;
49 }
50 }
51
52 s
53 }
54}
55
56pub(crate) 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(#[automatically_derived]
impl crate::fmt::Debug for BiasedFp {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "BiasedFp", "m",
&self.m, "p_biased", &&self.p_biased)
}
}Debug, #[automatically_derived]
impl crate::marker::Copy for BiasedFp { }Copy, #[automatically_derived]
impl crate::clone::Clone for BiasedFp {
#[inline]
fn clone(&self) -> BiasedFp {
let _: crate::clone::AssertParamIsClone<u64>;
let _: crate::clone::AssertParamIsClone<i32>;
*self
}
}Clone, #[automatically_derived]
impl crate::cmp::PartialEq for BiasedFp {
#[inline]
fn eq(&self, other: &BiasedFp) -> bool {
self.m == other.m && self.p_biased == other.p_biased
}
}PartialEq, #[automatically_derived]
impl crate::cmp::Eq for BiasedFp {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<u64>;
let _: crate::cmp::AssertParamIsEq<i32>;
}
}Eq, #[automatically_derived]
impl crate::default::Default for BiasedFp {
#[inline]
fn default() -> BiasedFp {
BiasedFp {
m: crate::default::Default::default(),
p_biased: crate::default::Default::default(),
}
}
}Default)]
69pub struct BiasedFp {
70 pub m: u64,
72 pub p_biased: i32,
74}
75
76impl BiasedFp {
77 #[inline]
79 pub const fn zero_pow2(p_biased: i32) -> Self {
80 Self { m: 0, p_biased }
81 }
82}