reliq 0.3.0

A portable library of primitive-like constructs.
Documentation
use super::*;

const LOOK_UP: [u128; 37] = [
    31,
    314,
    3141,
    31415,
    314159,
    3141592,
    31415926,
    314159265,
    3141592653,
    31415926535,
    314159265358,
    3141592653589,
    31415926535897,
    314159265358979,
    3141592653589793,
    31415926535897932,
    314159265358979323,
    3141592653589793238,
    31415926535897932384,
    314159265358979323846,
    3141592653589793238462,
    31415926535897932384626,
    314159265358979323846264,
    3141592653589793238462643,
    31415926535897932384626433,
    314159265358979323846264338,
    3141592653589793238462643383,
    31415926535897932384626433832,
    314159265358979323846264338327,
    3141592653589793238462643383279,
    31415926535897932384626433832795,
    314159265358979323846264338327950,
    3141592653589793238462643383279502,
    31415926535897932384626433832795028,
    314159265358979323846264338327950288,
    3141592653589793238462643383279502884,
    31415926535897932384626433832795028841
];

#[inline]
pub(super) fn pi<const A: u8, B>() -> B
where
    B: ops::Int,
    (): SupportedPrecision<A>,
    (): SupportedInt<B>,
    (): Supported<A, B> {
    match (B::SIGNED, B::BITS_AS_U128, A) {
        (_, _, 0) => B::AS_3,
        (true, 8, 1..=1)
        | (true, 16, 1..=4)
        | (true, 32, 1..=9)
        | (true, 64, 1..=19)
        | (true, 128, 1..=37)
        | (false, 8, 1..=2)
        | (false, 16, 1..=4)
        | (false, 32, 1..=9)
        | (false, 64, 1..=19)
        | (false, 128, 1..=37) => {
            unsafe {
                look_up::<A>().try_into().unwrap_unchecked()
            }
        },
        _ => {
            unsafe {
                ::core::hint::unreachable_unchecked()
            }
        }
    }
}

#[inline]
const fn look_up<const T: u8>() -> u128 {
    LOOK_UP[(T - 1) as usize]
}