fastnum2/decimal/dec/
intrinsics.rs

1use crate::int::{math::ilog10, UInt};
2
3pub(crate) struct Intrinsics<const N: usize>;
4
5/// _E<sub>limit</sub> = 32'768_
6pub(crate) const E_LIMIT: i32 = -(i16::MIN as i32);
7
8/// _E<sub>min</sub> = -32'767_
9pub(crate) const E_MIN: i32 = -(i16::MAX as i32);
10
11impl<const N: usize> Intrinsics<N> {
12    pub(crate) const COEFF_MAX: UInt<N> = UInt::<N>::MAX;
13
14    pub(crate) const COEFF_MEDIUM: UInt<N> = Self::COEFF_MAX.div(UInt::<N>::TEN);
15
16    /// Max length of the _coefficient_ in decimal digits.
17    pub(crate) const MAX_CLENGTH: u32 = clength(UInt::<N>::MAX);
18
19    /// _E<sub>max</sub> = E<sub>limit</sub> + (C<sub>length</sub> – 1)_
20    pub(crate) const E_MAX: i32 = E_LIMIT + (Self::MAX_CLENGTH as i32 - 1);
21
22    pub(crate) const SERIES_MAX_ITERATIONS: u32 = Self::MAX_CLENGTH * 6;
23}
24
25#[inline(always)]
26pub(crate) const fn clength<const N: usize>(coeff: UInt<N>) -> u32 {
27    if coeff.is_zero() {
28        return 1;
29    }
30
31    ilog10(coeff) + 1
32}