// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Per-scale, oracle-sourced, width-deduplicated wide
//! transcendental constant table.
//!
//! GENERATED by `scripts/gen_const_table.py` (mpmath oracle). Do
//! NOT edit by hand; re-run the script and commit its output. This
//! file is NOT produced at build time — `build.rs` is untouched.
//!
//! Each constant ships ONE golden mantissa per band —
//! `floor(const * 10^(band_hi+1))` — and a `const fn` ([`cb_build`])
//! REBUILDS the per-scale table at compile time by dividing it down by
//! 10 one scale at a time. So the source carries ~hundreds of bytes per
//! constant, not the per-scale limbs, yet the compiled table (and the
//! runtime static lookup) is byte-identical to a literal one. Each
//! rebuilt entry is `floor(const * 10^scale)` as the narrowest-fit
//! little-endian `u64` slice plus a `round_up` bit = 1 iff the dropped
//! fractional tail is >= 1/2 (the most-significant dropped digit >= 5).
//! Every constant is irrational and positive, so the tail is never an
//! exact tie and never zero, and the six rounding modes derive exactly
//! from `(floor, round_up)`:
//!
//! | mode | result |
//! |------|--------|
//! | Trunc / Floor | `floor` |
//! | Ceiling | `floor + 1` |
//! | HalfToEven / HalfAwayFromZero / HalfTowardZero | `floor + round_up` |
//!
//! The value is width-independent: an accessor zero-extends the
//! stored limbs into the caller's work integer (the high limbs stay
//! zero). The narrow band (`*_NARROW`, scales 0..=38) is ALWAYS
//! present — the public `DecimalConstants` trait on D18/D38 reads it
//! in every build (default / no_std included). The three wider bands
//! are feature-gated to match the tiers that can request them
//! (mirrors `src/types/consts/wide.rs`).

/// Scratch limb cap for the const-fn builders: the widest golden is
/// ln2 @ scale 5121 (~266 limbs); 280 leaves margin. A const-eval local
/// only — never in the binary.
const MAXK: usize = 280;

/// A compile-time-built per-scale constant band. `flat` holds every scale's
/// `floor(const * 10^scale)` as narrowest-fit little-endian limbs, packed
/// back-to-back; entry `i` (scale `lo + i`) is `flat[off[i] .. off[i]+len[i]]`
/// with round-up bit `bit[i]`. Built by [`cb_build`] from one golden mantissa.
pub(crate) struct ConstBand<const F: usize, const N: usize> {
    flat: [u64; F],
    off: [u32; N],
    len: [u16; N],
    bit: [u8; N],
}

/// Total narrowest-fit limb count over scales `lo..=hi`, divided down from
/// `golden = floor(const * 10^(hi+1))`. Sizes [`ConstBand`]'s `flat` exactly.
const fn cb_flat_len(golden: &[u64], lo: u32, hi: u32) -> usize {
    let mut buf = [0u64; MAXK];
    let mut blen = golden.len();
    let mut i = 0;
    while i < blen {
        buf[i] = golden[i];
        i += 1;
    }
    let mut total = 0usize;
    let mut s = hi + 1;
    while s > lo {
        let mut rem: u64 = 0;
        let mut j = blen;
        while j > 0 {
            j -= 1;
            let c = ((rem as u128) << 64) | (buf[j] as u128);
            buf[j] = (c / 10) as u64;
            rem = (c % 10) as u64;
        }
        while blen > 1 && buf[blen - 1] == 0 {
            blen -= 1;
        }
        total += blen;
        s -= 1;
    }
    total
}

/// Build the band for scales `lo..=hi` by dividing `golden = floor(const *
/// 10^(hi+1))` down by 10 once per scale. Each division's remainder is the
/// most-significant dropped digit, so the round bit is `rem >= 5` — exact for
/// irrational constants (no tie); `floor(const*10^s) = floor(golden/10^(hi+1-s))`
/// is exact. Reproduces the former literal table bit-for-bit.
const fn cb_build<const F: usize, const N: usize>(
    golden: &[u64],
    lo: u32,
    hi: u32,
) -> ConstBand<F, N> {
    let mut b = ConstBand { flat: [0u64; F], off: [0u32; N], len: [0u16; N], bit: [0u8; N] };
    let mut buf = [0u64; MAXK];
    let mut blen = golden.len();
    let mut i = 0;
    while i < blen {
        buf[i] = golden[i];
        i += 1;
    }
    let mut s = hi + 1;
    let mut cursor = 0usize;
    while s > lo {
        let mut rem: u64 = 0;
        let mut j = blen;
        while j > 0 {
            j -= 1;
            let c = ((rem as u128) << 64) | (buf[j] as u128);
            buf[j] = (c / 10) as u64;
            rem = (c % 10) as u64;
        }
        while blen > 1 && buf[blen - 1] == 0 {
            blen -= 1;
        }
        let idx = (s - 1 - lo) as usize;
        b.off[idx] = cursor as u32;
        b.len[idx] = blen as u16;
        b.bit[idx] = if rem >= 5 { 1 } else { 0 };
        let mut k = 0;
        while k < blen {
            b.flat[cursor + k] = buf[k];
            k += 1;
        }
        cursor += blen;
        s -= 1;
    }
    b
}

/// The stored `(floor-limbs, round-up)` for entry `i` of a band — a `const fn`
/// so a const-scale caller folds to the one entry (and bakes through `const_n`).
/// `split_at` keeps it const-stable (range indexing is not yet const).
const fn cb_get<const F: usize, const N: usize>(
    b: &'static ConstBand<F, N>,
    i: usize,
) -> (&'static [u64], u8) {
    let o = b.off[i] as usize;
    let l = b.len[i] as usize;
    (b.flat.split_at(o).1.split_at(l).0, b.bit[i])
}

const PI_NARROW_GOLDEN: &[u64] = &[
    0x8b0d6d7ecd7f8c08, 0x04ab8d99ec90193f, 0xa1f2d3bb978c0289, 0x7a16f42cefb66a1b, 0x5ecb9ff2b4452d85, 0xb6ebb144d56e158d,
    0x7bba6cde3d8b76db, 0x349971fd921413fc, 0x0c6e39e6e877ca95, 0x4e657adef891ec16, 0x3fc150032e90b2f1, 0x792d58529576ff96,
    0xe18e7359c66fc144, 0x5b78e5ccc1758092, 0x3781ff667c931854, 0x8031cb8010e7aefa, 0xabd16352d5a9fb5e, 0x145c1df7ed11e689,
    0x55716b8a7303c0af, 0xe3c6de2207196d00, 0x0b043384b0cdba26, 0xc0d8cba4b5c606da, 0x10083c743e052e27, 0x18bb978953799424,
    0x6d338818f060f60f, 0x800e39b5e52fe7e3, 0x0000037bd1ee11f6,
];
const PI_NARROW_F: usize = cb_flat_len(PI_NARROW_GOLDEN, 0, 512);
static PI_NARROW: ConstBand<PI_NARROW_F, 513> = cb_build(PI_NARROW_GOLDEN, 0, 512);

#[cfg(feature = "_wide-support")]
const PI_BASE_GOLDEN: &[u64] = &[
    0x8b0d6d7ecd7f8c08, 0x04ab8d99ec90193f, 0xa1f2d3bb978c0289, 0x7a16f42cefb66a1b, 0x5ecb9ff2b4452d85, 0xb6ebb144d56e158d,
    0x7bba6cde3d8b76db, 0x349971fd921413fc, 0x0c6e39e6e877ca95, 0x4e657adef891ec16, 0x3fc150032e90b2f1, 0x792d58529576ff96,
    0xe18e7359c66fc144, 0x5b78e5ccc1758092, 0x3781ff667c931854, 0x8031cb8010e7aefa, 0xabd16352d5a9fb5e, 0x145c1df7ed11e689,
    0x55716b8a7303c0af, 0xe3c6de2207196d00, 0x0b043384b0cdba26, 0xc0d8cba4b5c606da, 0x10083c743e052e27, 0x18bb978953799424,
    0x6d338818f060f60f, 0x800e39b5e52fe7e3, 0x0000037bd1ee11f6,
];
#[cfg(feature = "_wide-support")]
const PI_BASE_F: usize = cb_flat_len(PI_BASE_GOLDEN, 0, 512);
#[cfg(feature = "_wide-support")]
static PI_BASE: ConstBand<PI_BASE_F, 513> = cb_build(PI_BASE_GOLDEN, 0, 512);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const PI_XW_GOLDEN: &[u64] = &[
    0x81321410599faf4e, 0xd8cd998eb681d11c, 0x5f1850d2f7de539e, 0x1bbc9c3cea16a6de, 0x28f2bd8340587edb, 0x79a760c7f2fce1c1,
    0x711f2936fb51c5cf, 0x9f3143e657c845e6, 0xb2e7b2eb217c102b, 0xee85c772241d88f6, 0x791344a6b06597e3, 0x2ae547a3adb6dfe7,
    0x574a1691caa99cb5, 0xc8c4a82343d57b81, 0x041e3ba31a4ec209, 0x83eb114a7f972e17, 0xea03dc0878996252, 0x22cc4326f61d4c92,
    0x66c27b88dfc75404, 0xdeeecf49b6aebc4e, 0xb27613f6ed3d5f71, 0xa3aafee5222d4c98, 0x0198f0acec2d8ff1, 0xc9f693d9ffec34f8,
    0xf9c684306cc5fc18, 0x8462a1395d46db49, 0xd20c221c6a3cf563, 0xc45f49ab06ebc09e, 0xb2742dac834a9d9e, 0x3c9f7a7cfc08b385,
    0xae9faf07b283558e, 0xd199b262ca34bb35, 0x6ed9b8bbeec6d706, 0x2d202007ba5ba93f, 0x79d1074a72585a9f, 0x6ab8824e6cb75e58,
    0x853aec15ee8525a1, 0x2d0d722f13cebcb1, 0x247e1545f3982e6b, 0xcd1d327661b2a16a, 0x7a4f0602539161ab, 0x70c0abfe2554a85c,
    0x387b1a54f95b021c, 0x00ca6c9012df4c02, 0x224d56ae5287d0fa, 0x187b527ee6b20a32, 0xaf13c0d5fe53d3ca, 0x2ba0312416702e42,
    0x6738eca1138b771c, 0xb460485ff83b6f06, 0x11fda80d361c4590, 0xfe364dc6b722eb7d, 0x8dabb9a99162a85d, 0x00000000000062e4,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const PI_XW_F: usize = cb_flat_len(PI_XW_GOLDEN, 513, 1024);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static PI_XW: ConstBand<PI_XW_F, 512> = cb_build(PI_XW_GOLDEN, 513, 1024);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const PI_XXW_GOLDEN: &[u64] = &[
    0x2487da5c5d8da63f, 0xa4b4727311318463, 0xb9f1b0ec753a241f, 0x5d064dd9c7591fb3, 0x3ecc7f34521e1d86, 0x075d6cea412a7473,
    0x0c498c453791619b, 0xab35b2f6d946754f, 0x10febf68242ee530, 0x48e200e85e14c3d7, 0xf0dd4cfe4012cbdd, 0x4d763784a145b548,
    0x85dd183050f82fc4, 0x2c2fff79e7e52e18, 0x3cb33dccb5259223, 0xe265ad0995e4da2e, 0x3f966179efb31470, 0x7293f9095c3b47cf,
    0x3a64209b9d4bbc9b, 0x676c8a4a9354c728, 0xbd0b7bcd8ca60ca3, 0x818e75b9c62d2a59, 0x8ca4d93ded155aff, 0xa0ad2c5e065b29d6,
    0xeb3d1fa1219691da, 0xa19c93d7334a00b0, 0x59b2681111354eb0, 0x22cec30e47c910f6, 0xd5aa44dfd4db0fce, 0xa7004561e23601de,
    0x2760d40691b077b0, 0x8d9ff8c89fdf08d4, 0x65c18bca97f64142, 0xe39f68cdcc335fb4, 0x63da769f762d6d99, 0xbfa60883b7391934,
    0xfe4955d0ad32564c, 0x8a5f362c526578e5, 0xfa1cdf4d8dedcb86, 0xc8baa5c7bd8e82bb, 0xbf16fc4a37828a77, 0xc51ea1ce8f7842d0,
    0x3f4ec9bc615ba8b8, 0x60e50292233c8546, 0x45e722082c3484c2, 0xe262863330b3bf32, 0xb2a59c2a75eef4f3, 0x06d49e764ae66580,
    0x20f5c857fcabb780, 0x0249e89a1728606d, 0xa6b0104015ff8931, 0xad4590836b6ba940, 0x72b693f1745ccf22, 0x094b36812455af1b,
    0xd531a742ae52da12, 0x4b95d88ebdeb43f3, 0xdde946e227fbce8e, 0xaab0c3d25de86d2b, 0xebf36d0d7da34cb2, 0x17815a5a2b7d4f3d,
    0xcc1d698d1ba34e14, 0xa7c2e300f1ff229a, 0x088abcfeeb0da219, 0x662f91124dae75b4, 0xfd768e2877931dd5, 0x27b1d31834c9e7bf,
    0x2aea50e710e19adc, 0xc50e10a75d1e1598, 0xbb2c69e3cc822e40, 0x7bf117e58ec4ede7, 0xc30003051035a98c, 0xeb6921c7edbf0dff,
    0x27212eaffa20afd5, 0xc76a26dfdf0cc321, 0x7b66bea25348e607, 0x2fde55951d77d060, 0xbe75c3d6f0a12178, 0x2707473e045ef181,
    0x71c41111dba7926c, 0xc0879d540016d746, 0xfdf20b3a495f0805, 0x3959f65df11fc36b, 0x31299a2c9903bc2e, 0x70c20b4186a373d0,
    0x564114bd83f3b152, 0xe9482fe0426e8d07, 0x44874318a7bedaf5, 0x96c7338e1f0ab656, 0xa42460c81f3fb57a, 0xb0528bfd2bb74950,
    0x6d4c83c6e43dc9b7, 0x991c608452a2fd58, 0xa5c181c6aaeab1fc, 0xaa913297b9bbbbdd, 0xbd7c72cf315b641a, 0x22862b435aae9144,
    0xafe4e5b04f98e935, 0xc4cedb783a1ae479, 0x5640f80bc75300e5, 0xb0837288dd17b120, 0x7834ea82f2f046c1, 0x84694e86cb201770,
    0x97e77099e6204bfc, 0x7c27cc47c81bc54a, 0x1ba4d477937ecd77, 0xee3146f644c07fd6, 0x0000000001374cd7,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const PI_XXW_F: usize = cb_flat_len(PI_XXW_GOLDEN, 1025, 2048);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static PI_XXW: ConstBand<PI_XXW_F, 1024> = cb_build(PI_XXW_GOLDEN, 1025, 2048);

const TAU_NARROW_GOLDEN: &[u64] = &[
    0x8505ca15cad3faca, 0x76f179117d21b275, 0x0000000000000012,
];
const TAU_NARROW_F: usize = cb_flat_len(TAU_NARROW_GOLDEN, 0, 38);
static TAU_NARROW: ConstBand<TAU_NARROW_F, 39> = cb_build(TAU_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const TAU_BASE_GOLDEN: &[u64] = &[
    0x4fed27f4dd1a855c, 0x9baad6c9c8130e89, 0xb6e95c4a7049b6c7, 0x8573c529d60504aa, 0x65b6bbf172cc53bc, 0xb2802a34b6f963e4,
    0xd93a6b7663f91b29, 0xed22067e3b6caa01, 0xf9660bd3b010fbe2, 0xf0c6c8b91444309d, 0xa9a207b6aad23d92, 0xedc5ad7276802810,
    0x10826a4c014f81d9, 0x48284bed4a651d22, 0x15d759a96dc7d541, 0x5979bc4168c1335d,
];
#[cfg(feature = "_wide-support")]
const TAU_BASE_F: usize = cb_flat_len(TAU_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static TAU_BASE: ConstBand<TAU_BASE_F, 307> = cb_build(TAU_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const TAU_XW_GOLDEN: &[u64] = &[
    0xc00a7b3f01ed67b7, 0x423b97475d11b54e, 0x3d8d6e0d405489bd, 0xcf03257bcb6e2343, 0xc5fe76ac102214c4, 0x0d186f5b58db7874,
    0xbea697fd243b2253, 0xb81cf0a420cdfc48, 0xfc66884bb2e579a7, 0xb8b63ff6669997f3, 0xa9334e800be73265, 0xa1365ca4bc47a7d2,
    0x3d56363d8406afe2, 0xbbbbf5bf7b44469d, 0xada4eb273c124d78, 0xee741c6d0dd3b2e5, 0x4413096596d4a380, 0xd8a810bae161157f,
    0x29f4b6dc668ed8f5, 0x17752645ddddad89, 0x1cca1e2091a44023, 0x842386a5ec4a65a0, 0x0860439d842dd9b4, 0x0a5b8cd5dfbe8183,
    0x60318e88dd878191, 0x69bf69b4568b4293, 0x2b9308fa7624cc9c, 0xcf6235a04908cddd, 0xc94583f366429e0c, 0x2311fe35ac7dc458,
    0x7340fe2a54cd706c, 0xf1b961e9a2658080, 0x0000000000000001,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const TAU_XW_F: usize = cb_flat_len(TAU_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static TAU_XW: ConstBand<TAU_XW_F, 309> = cb_build(TAU_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const TAU_XXW_GOLDEN: &[u64] = &[
    0x0b444c8c1099caef, 0x149d0b50e459f39c, 0x480562699d682ec3, 0xb00aa125719a0e39, 0x9f8c69ca55dbd1e7, 0x9383f1e65984d050,
    0x6d79e9529ece324b, 0x1064a0f6baeea3d6, 0x53436dc4d55ec8ab, 0x81481255f2ab3c99, 0x187b74b0729db034, 0x39665e3cf1d80fdc,
    0x004b244559746dd5, 0x9a1527d48f66674d, 0x0405ae9572aed818, 0x2fe655eced6e51cc, 0x753c6a0f17110030, 0x5696326dabdc05d1,
    0x377f211cedac8d40, 0xb1b8fe7e25931d12, 0xcea844e1da7d78c0, 0x3f77e89cc733c11b, 0x717461f528c913b3, 0x625e770950f2c799,
    0x66316bf8c6cf7d54, 0x4ed05fdf51909887, 0x368dbd897c77813a, 0xc66b9aa47215edcb, 0x50f5504ff2fa9fd8, 0x011fdbbc0695a933,
    0xc4518c62bbbecb73, 0x92382d28cdd628df, 0x0fd89bee16cfb601, 0x4a0f4ce97f0ea1a3, 0x29940eba00c0b1d3, 0x63c5cc9085837e64,
    0xb70f25412782c4a0, 0xd37309b29dedc7dd, 0x3e4153c662b33fa6, 0xceb05a4f7354591a, 0xfe03ce860baebbf3, 0xe9d7f66599014915,
    0x47cfd5754d6eb3e6, 0x992e604bfdd2de03, 0xf1642b31fa6d8420, 0xc68d6537db0002f8, 0x6ff17681c5ac3176, 0x2bc22b85bc0760f0,
    0x58967fc3a87d4789, 0x56a2900b40902356, 0xb3dd5ea450e57e91, 0x1e798d9198279cef, 0x1b0df2aa0fe4edf9, 0x2a9a9482dbbe6fe1,
    0x9e1f64eb81f28b4a, 0xd5a38e62b4010715, 0x96fe460ff05ae2ba, 0x081cf0bfb07d51c4, 0xddc6cdfd630567ed, 0x7fb1d55bd71fec86,
    0x02efb5975ab6740c, 0x6bb182c2f20a0918, 0xe726559029fb1090, 0x9a0358ee02f36d22,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const TAU_XXW_F: usize = cb_flat_len(TAU_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static TAU_XXW: ConstBand<TAU_XXW_F, 616> = cb_build(TAU_XXW_GOLDEN, 616, 1231);

const HALF_PI_NARROW_GOLDEN: &[u64] = &[
    0x6141728572b4feb2, 0x9dbc5e445f486c9d, 0x0000000000000004,
];
const HALF_PI_NARROW_F: usize = cb_flat_len(HALF_PI_NARROW_GOLDEN, 0, 38);
static HALF_PI_NARROW: ConstBand<HALF_PI_NARROW_F, 39> = cb_build(HALF_PI_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const HALF_PI_BASE_GOLDEN: &[u64] = &[
    0x53fb49fd3746a157, 0xe6eab5b27204c3a2, 0xadba57129c126db1, 0x215cf14a7581412a, 0x196daefc5cb314ef, 0x6ca00a8d2dbe58f9,
    0x764e9add98fe46ca, 0xbb48819f8edb2a80, 0x7e5982f4ec043ef8, 0xbc31b22e45110c27, 0x2a6881edaab48f64, 0x7b716b5c9da00a04,
    0x84209a930053e076, 0x520a12fb52994748, 0x4575d66a5b71f550, 0x165e6f105a304cd7,
];
#[cfg(feature = "_wide-support")]
const HALF_PI_BASE_F: usize = cb_flat_len(HALF_PI_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static HALF_PI_BASE: ConstBand<HALF_PI_BASE_F, 307> = cb_build(HALF_PI_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const HALF_PI_XW_GOLDEN: &[u64] = &[
    0xb0029ecfc07b59ed, 0x508ee5d1d7446d53, 0xcf635b835015226f, 0x33c0c95ef2db88d0, 0x317f9dab04088531, 0xc3461bd6d636de1d,
    0x2fa9a5ff490ec894, 0xee073c2908337f12, 0xff19a212ecb95e69, 0x6e2d8ffd99a665fc, 0xaa4cd3a002f9cc99, 0xa84d97292f11e9f4,
    0x4f558d8f6101abf8, 0x2eeefd6fded111a7, 0x6b693ac9cf04935e, 0x3b9d071b4374ecb9, 0xd104c25965b528e0, 0x762a042eb858455f,
    0x4a7d2db719a3b63d, 0xc5dd499177776b62, 0x0732878824691008, 0x2108e1a97b129968, 0xc21810e7610b766d, 0x4296e33577efa060,
    0xd80c63a23761e064, 0x1a6fda6d15a2d0a4, 0x4ae4c23e9d893327, 0x33d88d6812423377, 0x325160fcd990a783, 0x08c47f8d6b1f7116,
    0x1cd03f8a95335c1b, 0x7c6e587a68996020,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const HALF_PI_XW_F: usize = cb_flat_len(HALF_PI_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static HALF_PI_XW: ConstBand<HALF_PI_XW_F, 309> = cb_build(HALF_PI_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const HALF_PI_XXW_GOLDEN: &[u64] = &[
    0x02d11323042672bb, 0xc52742d439167ce7, 0x5201589a675a0bb0, 0xec02a8495c66838e, 0x27e31a729576f479, 0xe4e0fc7996613414,
    0x9b5e7a54a7b38c92, 0xc419283daebba8f5, 0x54d0db713557b22a, 0x205204957caacf26, 0x061edd2c1ca76c0d, 0x4e59978f3c7603f7,
    0x4012c911565d1b75, 0x268549f523d999d3, 0x01016ba55cabb606, 0x0bf9957b3b5b9473, 0x5d4f1a83c5c4400c, 0x15a58c9b6af70174,
    0x8ddfc8473b6b2350, 0x2c6e3f9f8964c744, 0xf3aa1138769f5e30, 0xcfddfa2731ccf046, 0x5c5d187d4a3244ec, 0x18979dc2543cb1e6,
    0xd98c5afe31b3df55, 0x93b417f7d4642621, 0xcda36f625f1de04e, 0x319ae6a91c857b72, 0xd43d5413fcbea7f6, 0xc047f6ef01a56a4c,
    0xf1146318aeefb2dc, 0x648e0b4a33758a37, 0xc3f626fb85b3ed80, 0xd283d33a5fc3a868, 0x0a6503ae80302c74, 0x18f173242160df99,
    0x6dc3c95049e0b128, 0xb4dcc26ca77b71f7, 0x8f9054f198accfe9, 0xf3ac1693dcd51646, 0x7f80f3a182ebaefc, 0xba75fd9966405245,
    0xd1f3f55d535bacf9, 0x264b9812ff74b780, 0x3c590acc7e9b6108, 0xb1a3594df6c000be, 0x1bfc5da0716b0c5d, 0x4af08ae16f01d83c,
    0x96259ff0ea1f51e2, 0x55a8a402d02408d5, 0xecf757a914395fa4, 0x479e63646609e73b, 0x46c37caa83f93b7e, 0x8aa6a520b6ef9bf8,
    0x6787d93ae07ca2d2, 0xb568e398ad0041c5, 0x25bf9183fc16b8ae, 0x42073c2fec1f5471, 0xb771b37f58c159fb, 0x1fec7556f5c7fb21,
    0x00bbed65d6ad9d03, 0x1aec60b0bc828246, 0xb9c995640a7ec424, 0x2680d63b80bcdb48,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const HALF_PI_XXW_F: usize = cb_flat_len(HALF_PI_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static HALF_PI_XXW: ConstBand<HALF_PI_XXW_F, 616> = cb_build(HALF_PI_XXW_GOLDEN, 616, 1231);

const QUARTER_PI_NARROW_GOLDEN: &[u64] = &[
    0xb0a0b942b95a7f59, 0x4ede2f222fa4364e, 0x0000000000000002,
];
const QUARTER_PI_NARROW_F: usize = cb_flat_len(QUARTER_PI_NARROW_GOLDEN, 0, 38);
static QUARTER_PI_NARROW: ConstBand<QUARTER_PI_NARROW_F, 39> = cb_build(QUARTER_PI_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const QUARTER_PI_BASE_GOLDEN: &[u64] = &[
    0x29fda4fe9ba350ab, 0xf3755ad9390261d1, 0x56dd2b894e0936d8, 0x90ae78a53ac0a095, 0x8cb6d77e2e598a77, 0x3650054696df2c7c,
    0x3b274d6ecc7f2365, 0x5da440cfc76d9540, 0xbf2cc17a76021f7c, 0x5e18d91722888613, 0x153440f6d55a47b2, 0x3db8b5ae4ed00502,
    0x42104d498029f03b, 0x2905097da94ca3a4, 0xa2baeb352db8faa8, 0x0b2f37882d18266b,
];
#[cfg(feature = "_wide-support")]
const QUARTER_PI_BASE_F: usize = cb_flat_len(QUARTER_PI_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static QUARTER_PI_BASE: ConstBand<QUARTER_PI_BASE_F, 307> = cb_build(QUARTER_PI_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const QUARTER_PI_XW_GOLDEN: &[u64] = &[
    0xd8014f67e03dacf6, 0xa84772e8eba236a9, 0x67b1adc1a80a9137, 0x99e064af796dc468, 0x98bfced582044298, 0x61a30deb6b1b6f0e,
    0x17d4d2ffa487644a, 0xf7039e148419bf89, 0x7f8cd109765caf34, 0xb716c7feccd332fe, 0x552669d0017ce64c, 0x5426cb949788f4fa,
    0xa7aac6c7b080d5fc, 0x17777eb7ef6888d3, 0xb5b49d64e78249af, 0x1dce838da1ba765c, 0xe882612cb2da9470, 0xbb1502175c2c22af,
    0x253e96db8cd1db1e, 0x62eea4c8bbbbb5b1, 0x039943c412348804, 0x908470d4bd894cb4, 0x610c0873b085bb36, 0x214b719abbf7d030,
    0x6c0631d11bb0f032, 0x8d37ed368ad16852, 0xa572611f4ec49993, 0x99ec46b4092119bb, 0x1928b07e6cc853c1, 0x84623fc6b58fb88b,
    0x0e681fc54a99ae0d, 0x3e372c3d344cb010,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const QUARTER_PI_XW_F: usize = cb_flat_len(QUARTER_PI_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static QUARTER_PI_XW: ConstBand<QUARTER_PI_XW_F, 309> = cb_build(QUARTER_PI_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const QUARTER_PI_XXW_GOLDEN: &[u64] = &[
    0x816889918213395d, 0x6293a16a1c8b3e73, 0x2900ac4d33ad05d8, 0xf6015424ae3341c7, 0x13f18d394abb7a3c, 0x72707e3ccb309a0a,
    0xcdaf3d2a53d9c649, 0x620c941ed75dd47a, 0x2a686db89aabd915, 0x9029024abe556793, 0x830f6e960e53b606, 0xa72ccbc79e3b01fb,
    0xa0096488ab2e8dba, 0x1342a4fa91eccce9, 0x8080b5d2ae55db03, 0x05fccabd9dadca39, 0x2ea78d41e2e22006, 0x0ad2c64db57b80ba,
    0x46efe4239db591a8, 0x16371fcfc4b263a2, 0x79d5089c3b4faf18, 0x67eefd1398e67823, 0x2e2e8c3ea5192276, 0x8c4bcee12a1e58f3,
    0xecc62d7f18d9efaa, 0x49da0bfbea321310, 0x66d1b7b12f8ef027, 0x18cd73548e42bdb9, 0x6a1eaa09fe5f53fb, 0x6023fb7780d2b526,
    0xf88a318c5777d96e, 0x324705a519bac51b, 0x61fb137dc2d9f6c0, 0x6941e99d2fe1d434, 0x853281d74018163a, 0x0c78b99210b06fcc,
    0xb6e1e4a824f05894, 0xda6e613653bdb8fb, 0x47c82a78cc5667f4, 0x79d60b49ee6a8b23, 0xbfc079d0c175d77e, 0xdd3afeccb3202922,
    0x68f9faaea9add67c, 0x1325cc097fba5bc0, 0x1e2c85663f4db084, 0xd8d1aca6fb60005f, 0x0dfe2ed038b5862e, 0x25784570b780ec1e,
    0xcb12cff8750fa8f1, 0x2ad452016812046a, 0xf67babd48a1cafd2, 0x23cf31b23304f39d, 0x2361be5541fc9dbf, 0x455352905b77cdfc,
    0xb3c3ec9d703e5169, 0x5ab471cc568020e2, 0x92dfc8c1fe0b5c57, 0xa1039e17f60faa38, 0xdbb8d9bfac60acfd, 0x8ff63aab7ae3fd90,
    0x005df6b2eb56ce81, 0x0d7630585e414123, 0x5ce4cab2053f6212, 0x13406b1dc05e6da4,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const QUARTER_PI_XXW_F: usize = cb_flat_len(QUARTER_PI_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static QUARTER_PI_XXW: ConstBand<QUARTER_PI_XXW_F, 616> = cb_build(QUARTER_PI_XXW_GOLDEN, 616, 1231);

const E_NARROW_GOLDEN: &[u64] = &[
    0x21a1ed6d190c99dd, 0xfd02097d8125224b, 0x0000000000000007,
];
const E_NARROW_F: usize = cb_flat_len(E_NARROW_GOLDEN, 0, 38);
static E_NARROW: ConstBand<E_NARROW_F, 39> = cb_build(E_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const E_BASE_GOLDEN: &[u64] = &[
    0xddbb6902bfee3f63, 0x94f0e8f4b547603d, 0xad41a9ce49015512, 0xb53c769b1b928425, 0x1b4c7e575c300b65, 0xac574c8069d6dfa2,
    0x4695d05696a3a988, 0x62641b5fa0002c8a, 0xb9958111fb8c5fc7, 0x9738ed0687d09593, 0x4093bcdb9aea5f7b, 0x6bc968c4697ff3a5,
    0x8d9a859f0ae10929, 0x299a00974d61b7cf, 0x9e546113c0514e2e, 0x26b5a9890bfdf91c,
];
#[cfg(feature = "_wide-support")]
const E_BASE_F: usize = cb_flat_len(E_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static E_BASE: ConstBand<E_BASE_F, 307> = cb_build(E_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const E_XW_GOLDEN: &[u64] = &[
    0x641a7f2a1a375901, 0x5e5bbe2fed11a4bf, 0xf664aa29e01b8480, 0xaa7e3853f3e3d2f5, 0xfc716a87ee4283f8, 0x150b49a4997e9654,
    0xc1106f30264ba2c9, 0xfd95b0d5ae145a3d, 0x7f9f7cdd16f7fa95, 0x8f10aa27b52a1f00, 0x5c25cf06b37e97af, 0x8a7d656b56399892,
    0x36c05ba0f7018e96, 0xada5128d228c77ca, 0xab757fae39919ddf, 0x0c2cb6ed271ca8dd, 0x939249e5c9c5fea8, 0x84a449d707691b81,
    0x750de303ccbe9fd9, 0xf3b07a880ee83f71, 0x879a75233f7a7edb, 0x9c5ac70e3fa9e350, 0x0829b87a372707ff, 0xe279423f2f272429,
    0xdeacfcefaf1d64db, 0xb74a8abb1ade0560, 0xba93488ba7801a5a, 0xa57ddc17e4f1326b, 0x644a0210396a4df3, 0xff77e967d5cab995,
    0x82df773c5d39e82a, 0xd7545376ed16c3ce,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const E_XW_F: usize = cb_flat_len(E_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static E_XW: ConstBand<E_XW_F, 309> = cb_build(E_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const E_XXW_GOLDEN: &[u64] = &[
    0xdee1e08f5369aaa6, 0x1cd66a42d3831c4b, 0x121f2c9554270217, 0x1925412d2b6e2a92, 0x27e5ab53b5f9328e, 0x26c932b54868ca42,
    0x3414762897a6856f, 0x527c992612aaa7f0, 0x28cd1b3c54b9ddb1, 0x7ba41dd5578418fc, 0x74bb05056fe03998, 0x1f81146d9f7d33da,
    0xe3b78b8941cd8ec2, 0x8a732ce69581cd9a, 0x58814582f5b57e93, 0xd8ee418a3e8ae415, 0x2c077d906b899a2c, 0x88967e13c8157f9b,
    0xab7ef13fa3251b20, 0x69c154efe82ae0b0, 0x3de864c0a87381b9, 0xa80813f9834d2bde, 0x4cca35329b8dcc25, 0x97b286a751b08be0,
    0x128bd551b5f34694, 0x53a3c8e43390b94a, 0x9cffc26633dabe95, 0x54f6c4d7c1a47ff4, 0x8ffbe671adb2b3a4, 0x6a639dd0d8ca12d6,
    0x852830ad22ec0592, 0x95f2a516eedd3a14, 0x3e2afd6e250b4ee1, 0x5e0580c8ed5d64c0, 0xb7913ade55b61815, 0x4636cd7df5f5f5f0,
    0x2ade277fdcf887a9, 0xa5c887f1cc49040b, 0x9a4d6644db934f05, 0xba8cc397d27315c9, 0x9c77d5a320e2880b, 0x723c8c2fe2cdfcce,
    0x9b551ff21c4f7edb, 0x56c110621f22867e, 0xc6340a784eca6cc8, 0x97ce05042bb08553, 0xd33a8a7b2c647fed, 0x4f338c21846774aa,
    0xf71128e6c930c05e, 0x14fba92482efb44d, 0x1f960134383c6825, 0x0b451eaded06371d, 0x4fdcb5502f0d9415, 0xe809cdb015f5c943,
    0x49f9473db8dd29c9, 0x37c2de43463f79ae, 0xf558f95a4f04cc8d, 0x41519ba6c26b68da, 0x113f700eedda68fe, 0xf24d99817bf91e31,
    0x70d90ac410f1d205, 0xb55ac2258b01296e, 0xf73f7640a0a624fb, 0x42a15fc0edd6a2cf,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const E_XXW_F: usize = cb_flat_len(E_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static E_XXW: ConstBand<E_XXW_F, 616> = cb_build(E_XXW_GOLDEN, 616, 1231);

const GOLDEN_NARROW_GOLDEN: &[u64] = &[
    0x64a32cdded8a0958, 0xc14602d0b29cb5cb, 0x0000000000000004,
];
const GOLDEN_NARROW_F: usize = cb_flat_len(GOLDEN_NARROW_GOLDEN, 0, 38);
static GOLDEN_NARROW: ConstBand<GOLDEN_NARROW_F, 39> = cb_build(GOLDEN_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const GOLDEN_BASE_GOLDEN: &[u64] = &[
    0xfe03ac4d6755818c, 0xbe3ec3b8b0e0d8bf, 0x7355f3d43c199801, 0x0426d7b3c7a71208, 0xb5f595456e3be613, 0xa511a11dac2a4355,
    0x4291cb7d2374b66d, 0x69935983f0d9c25a, 0x2c89300244eb18c6, 0xfaf7ed980fd0c16d, 0xb80a08a58207c742, 0x239a233af8cb30ea,
    0x4c4d2b5f1d52b417, 0x2b82e1517fdfb790, 0x8ca2ec77d276636e, 0x170aa44154e9caef,
];
#[cfg(feature = "_wide-support")]
const GOLDEN_BASE_F: usize = cb_flat_len(GOLDEN_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static GOLDEN_BASE: ConstBand<GOLDEN_BASE_F, 307> = cb_build(GOLDEN_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const GOLDEN_XW_GOLDEN: &[u64] = &[
    0x006ba23733b193ea, 0x83d51c7b057d0b48, 0x54d03e54fda8d860, 0x8f0a7ed2cf71c121, 0xb2ccdf6de6c7697c, 0x2c9d5e192ebd8c69,
    0xa30b514adce5bcb6, 0x319c6d5ba2010653, 0x718448ce36cded35, 0x68fe43036e5ed585, 0x811e6ed2e3f52711, 0x606e82c90bf7672f,
    0xfe8f210104fe511c, 0xcb100f0555653015, 0x5dcf674078a3085b, 0x094c18e0a4b77c91, 0xe592f11f9ce1050a, 0xd39a7cadd5b16c45,
    0x02a59375c38b5063, 0x7d33a959ef9d9018, 0x61a9f93563c541ed, 0x77139696a719c071, 0x33a4be6eadca7ac9, 0xc573848604d8b387,
    0xbe02dd87ff45935b, 0xf9cd434a35c65dcb, 0x6fc0f965791f9d5f, 0x57287d64b19f08f5, 0xea8856e7c3b099fc, 0xa1b7dc037a99e304,
    0x0709e2440ab0654a, 0x802c487ebd2d511b,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const GOLDEN_XW_F: usize = cb_flat_len(GOLDEN_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static GOLDEN_XW: ConstBand<GOLDEN_XW_F, 309> = cb_build(GOLDEN_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const GOLDEN_XXW_GOLDEN: &[u64] = &[
    0x95540bcac9724d99, 0xc4a624c638d44267, 0xa0c46c7ebc7ce3be, 0xdfd4a658555cfa53, 0x8cafad1144710da3, 0x9131f73cf2dce00d,
    0x3ecc4369b8d0a328, 0xbc225f940863e0ce, 0x1f53aea81c42d3ce, 0xe8b71197e76e0c58, 0x824c3a3f8ca2b02f, 0xb6dd5e6bec461bfe,
    0xf02ad4ee3fbde814, 0xb260322ee32546c3, 0x73499fa1666ce014, 0xdadca1f7e940098d, 0x95452ac4d923405f, 0x08215d61acffc6ba,
    0x3c8d28a22c2b97fd, 0x14570b3467144ba7, 0xa68c1866cc8fd5fd, 0xbfb3a1ea13265647, 0xf05c84a330f739d3, 0x2b751ad6f4d7f810,
    0xa840088238321640, 0x954cf9956a7dc7fb, 0xcdfbb12c1ca3c7c6, 0x2b803779908fca79, 0x6fe8f75390791808, 0xb4c1fb0244f89d97,
    0x2a4d13b6e82678bf, 0x67b0f48861419fce, 0x55160cae082956ae, 0x34fce11145ae658d, 0xa12d1753ce75de8b, 0x5be45aae19e3415b,
    0x63033634d85c54f9, 0x3ba4322e7bb4dbf6, 0x34f38208583cdc39, 0xf0eadfe79e8491a3, 0x6afab8fef5766bbb, 0x1e5416eb2b5a82b5,
    0x10d2de59e72d0c1e, 0xf54405cc7f060fca, 0x8ba7c167e5d1b52e, 0xfaeac4e2159af14f, 0x0732cf8ef140b0f8, 0xc5f85dc5bddddf74,
    0xc912eac340309cb1, 0x69e97ad8569bc7c5, 0x3a0b367510eaa5fc, 0xee29a160be9f9134, 0x1b9339642e880b8f, 0x834564f3fae2d896,
    0xc460be7771796b5a, 0xd967bce2a7ec305f, 0x00f1133fb0a36385, 0xe34340b582fc7fa3, 0x22ba16b0e556aefa, 0x81f753edd572b534,
    0x7f203f909b1aae6c, 0x855229081fb27f47, 0xfa86e84a24d7b28f, 0x27a94181312c2841,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const GOLDEN_XXW_F: usize = cb_flat_len(GOLDEN_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static GOLDEN_XXW: ConstBand<GOLDEN_XXW_F, 616> = cb_build(GOLDEN_XXW_GOLDEN, 616, 1231);

const LN2_NARROW_GOLDEN: &[u64] = &[
    0x5e58f63f8aee8fb1, 0xfb6d5711c54c885b, 0xb7faeb93b974c4ac, 0xd89b64461b4d897d, 0x480481459a0b137c, 0x49072aef82899c15,
    0x8e08edf8c93c43c0, 0xde5788f9b759fe17, 0x2f7aa6cbf9ed33b6, 0x0b80edf071cf0c3b, 0x0f95adb0252316e7, 0x0b8d803719662628,
    0x81fcae4d7c0ae88b, 0xb2e6efe9c3e5f404, 0x2356441229653c49, 0xe57c67392c6a188d, 0xb876f120783940a0, 0x944e96c1faf26fc2,
    0x6bad48945a70f6b1, 0x4b27abb969c75fc1, 0xddac01771154dc0d, 0xeeef15007a924eb5, 0xa3b6fe724091ddfe, 0xefecd3bd4211bbe0,
    0xfea4cc969d02b2ef, 0xd7a6aee471f91e39, 0x000000c4c46a76d0,
];
const LN2_NARROW_F: usize = cb_flat_len(LN2_NARROW_GOLDEN, 0, 512);
static LN2_NARROW: ConstBand<LN2_NARROW_F, 513> = cb_build(LN2_NARROW_GOLDEN, 0, 512);

#[cfg(feature = "_wide-support")]
const LN2_BASE_GOLDEN: &[u64] = &[
    0xee40ad9ece52e59c, 0xa1ebd3060b7045ea, 0xcc4870b31b94084d, 0xdbd1f78eadcfdd2e, 0x8c76b9056b7dfe5a, 0x4e75fe391d0f0e11,
    0xd6dc89f1a56f2cba, 0xdfab281b74c5ff03, 0x62b1b65767eab07c, 0xb281ba02a2c365b6, 0x8c662573a1504e2c, 0xa56a13877bccf3a6,
    0x7c09c9fdfd5c6264, 0x7993671e17993f6f, 0xf22f1c0e83466414, 0xe3769bb87fde975d, 0xca4391e9cd40fb62, 0x703987c381120853,
    0x0dad902cbea7fa40, 0x4859fe104225025a, 0xc1457adb22580874, 0x8e5ced9462625f53, 0x2643824a7c84d216, 0x35cf7f2d4a8771ff,
    0x372ad53489d00e0a, 0xba95510706cb83b5, 0x17a2f92dfa1195fe, 0xc62a70fee48bc70e, 0x7499ce879ad1b808, 0x6efa2d272afc2ce3,
    0xe7cfc30ddb46cca9, 0xb777ab1b6ed45231, 0xaf3b39765a37474e, 0x54bde7f9e093ced1, 0xc1dec38eec5f4e9c, 0x70be369f6b8e4fab,
    0x76201f75a7f14192, 0xe9ec84db711aea9e, 0xb87b39ae33be29a5, 0x71a40266822258ca, 0xea881a1b22666b14, 0x36aa663c91d0131b,
    0x2e0100ddcb00f194, 0x48992ea352e9728b, 0x773b9d6ee986e196, 0xc320cf2398940b01, 0x7916cf9d2e32cf26, 0xb302b36928ccd668,
    0x73cf02c39ecb6989, 0xccc05a043caf90a0, 0x9c92eaf3af2badb7, 0xf69b996d8a09798e, 0x80e61dbfcb2e77b6, 0x2f35b01ff4698bae,
    0x09bdfb548845bbec, 0xb0338f4e4d131ca7, 0x3520a91ee9bb65d2, 0x7a0c5b2f591fe0c6, 0x10f1c4cdb6090d2f, 0xdfbbf4437294f504,
    0x6d2858f54cea70fb, 0xf4b8a8f694780b9b, 0x66c8043a99d86753, 0xd9b6b8ace45d6e84, 0xf91394d8d50547ea, 0xb7c4a6e41600caf8,
    0x000000007440bf8b,
];
#[cfg(feature = "_wide-support")]
const LN2_BASE_F: usize = cb_flat_len(LN2_BASE_GOLDEN, 0, 1280);
#[cfg(feature = "_wide-support")]
static LN2_BASE: ConstBand<LN2_BASE_F, 1281> = cb_build(LN2_BASE_GOLDEN, 0, 1280);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LN2_XW_GOLDEN: &[u64] = &[
    0xe6c76ed247296eed, 0xc07ae017ffabbee3, 0x5e7ee2c5ce700b8b, 0x8c199d109adf8e4c, 0x68a0ddf6e6e54d45, 0xecc3c27f8d78d16f,
    0x39be3da794a25e93, 0x76f264dd7d175446, 0xc1b8ae24bd46a9b8, 0x668ac8b9d0c323b5, 0x8b6178900f9fdca4, 0xf50d247498686e96,
    0xdee7575e1e297e6b, 0x43d43922458cdb83, 0x229828ed18c993f5, 0xa2c05b98424a2094, 0x3cf6eb260cba2fbf, 0x49e51aa3ab6dd2c3,
    0x194610df48d7b584, 0x5aaf43f554b71ee7, 0x1bff7169ad254c18, 0x07d7d68e8f223a0b, 0x41df316e93257ebb, 0x461e9f37264297dd,
    0x5c64b23756d8b54e, 0x84163ed14ec3de70, 0x69a7fdfd02a751d9, 0x06c666cbe04276f1, 0xe3b28415310a80fe, 0xd5a8ab94dbc4da6b,
    0x555e2c93222e78ac, 0x247040b5fe33414d, 0xadbec26c1474ec87, 0x876ba8c519605352, 0x4b19b27f95f99364, 0xef0d110590943598,
    0xcfcb7e724b18abbd, 0xe2430935eda994ab, 0x68ceb6b60a8098ea, 0x8a8d2107f5800406, 0xf3a99b2e93079a27, 0x9928541bee4e6e6b,
    0xb21b80e71595eb2a, 0x7373403ff70587c0, 0x8dad97ac9300d450, 0x8d5ea2144f7bfb5f, 0x3180324b1fafaa0b, 0xbbad6853732dd2c1,
    0xebcc83b1f69eb0b7, 0xf81c90c640d80df3, 0x0b239ddd60191ca5, 0xf2daf217a378c651, 0x63e55320082c068c, 0x8a97172c6e5161b2,
    0xbbd89aa9460bd605, 0xd491c1baa1dc95ba, 0x9538d1b751f2b2bc, 0x85dc6cb1dc1b02f7, 0x9b3f078961d79e9c, 0x8c5344d4ee8fa892,
    0x2d9632536a2ad398, 0x62954e06f2a68f39, 0x52095d6d39022149, 0x27d4dfb648549199, 0x574e17c3a00ab3a3, 0x1be68ff0fdad1cc1,
    0x867b196e458a4368, 0x7b712b3ed5e036d7, 0xaa711f2725590e85, 0x57c6bb01c9422d5c, 0x031bcfb36f6f87bc, 0x64d7f3dd4e80fda4,
    0x5dc1c8097a5afc1c, 0xbdf60e20c8770b3d, 0x45c6e42f6626cbd0, 0x66d40f7e3d40e349, 0x955ff36007888092, 0x2ec90e40115fa4f6,
    0x0aeb747dc1be1123, 0x03f0946538c5aef6, 0x0598335079a2dc7a, 0xb0b4e267bc0c3dd9, 0x511ab6187b3cfee2, 0xa373ccc718554856,
    0xf9c0c8cbe1621ba6, 0x289d9527b2a26919, 0x61358c60cd89d58f, 0xd96eb46bde8bde96, 0xbda74dd94c768c43, 0xaca7d1f1e93964e6,
    0x688596413f9bd949, 0x50bc7abf1bb451d6, 0x7890e9ed1d61824c, 0xb102f12b17d2b25d, 0x9d3b8672395b8c3a, 0xf7f035d70f32cf04,
    0x3ddf51130f09c7bd, 0x5868db9e0ec8afd2, 0xdedb585daf45dff7, 0x99101eaf9280a4bb, 0x4dd20cab88d016be, 0xb9bd74bd40488901,
    0x4f5d37b0f425b418, 0xf5aa90a37834abb8, 0x3003f55a32cc4139, 0xfcfb85f614a1b057, 0xcacf22f47a5ad86f, 0xadd407a27a645884,
    0xc421eedfaa05a0f9, 0x004549b6d43bb19b, 0x9b117c71382ec222, 0x01e4dc7d05aabe16, 0x4011bef4e6f70226, 0x27e7d4abdd48e1e5,
    0xec5dcc0521bcfff1, 0x78af8d1a512e9e4a, 0x6db9eff33a8bc59d, 0xe0aea7e82456b767, 0xe4c332fc24d888b4, 0xead17389bc643947,
    0x681222d996276cf1, 0xbcf20cf2be27d473, 0x45d4e62068a509f2, 0xe6bd3f91c6f51a30, 0xf14fc001155891e8, 0x2b2eaa4f7c070073,
    0x2c26bf69929b2de9, 0xa6a70496e3f00afc, 0xee974485bf873d6a, 0xa50e787aecf80fa8, 0xf9d0bc15aad9ad96, 0x8eaef600e87ab534,
    0x079dc3dfc7ae6de2,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LN2_XW_F: usize = cb_flat_len(LN2_XW_GOLDEN, 1281, 2560);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static LN2_XW: ConstBand<LN2_XW_F, 1280> = cb_build(LN2_XW_GOLDEN, 1281, 2560);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LN2_XXW_GOLDEN: &[u64] = &[
    0x25ea1fa14e1f3ac1, 0x34856c8c5745e6f4, 0x0d158fa234d74edb, 0xb5a129dc677536f7, 0x66a21465e32e64c9, 0x857504f65098232a,
    0xf2910b51c669295c, 0x0e9af51938201490, 0x852181b1f72ca737, 0xa5f81a528460b1f9, 0x505fc77fa7c06e75, 0x8a062ae9c52d32a9,
    0x4f0847e7d0e58946, 0x0c2407c755395065, 0x7a1f585340e533f6, 0x1e9ce570fd061530, 0xbcdafc1720084558, 0x31b27d07e0e88579,
    0x07402ef7d870ea4e, 0x2c9d5f20d576d2c5, 0x80285d3932a0ab7e, 0xc9043d46bc7f08ff, 0x72ac669993abd9d1, 0xb1c008ac126175c5,
    0xee5efbef75907902, 0x05965c79ce712b0a, 0xa874ab592ec3e4ff, 0xf29e68177103028d, 0x85c430fe7a79b745, 0x7080afa85e85ac48,
    0x9ff2a19ed0ce8982, 0x8da83b6d0803271b, 0xef7eaf36050f7eb0, 0xe508bd56fc090fdf, 0xd79d44b269e41639, 0x291fb01472901e9b,
    0xb2c8ff2c89a7e38c, 0xe435b29070304ef5, 0x4aa310f048f74eeb, 0x23f7cc4e1bab0247, 0x0771b9b9693f426d, 0xd73fc29beb54ef39,
    0xa9736ded92425cec, 0xcc1ba7c12697f7b1, 0x35da436bdd8bc16f, 0x26e93d59b29e1e8a, 0xeb641ce8cb221724, 0xe7bef1ce6a785850,
    0xb474e3e7564c960b, 0x9fa773fc2aba7e76, 0x774b693afbb00ce0, 0x592d919a8c9fbee6, 0xb7cf75619be0d57a, 0xe6fc8653eda2e67e,
    0xc6fc4c68abe5668b, 0x8f100ad811d8125f, 0xb9b5324dd333e4b2, 0xa850b71295a2cdf1, 0xe9b128a12a5c06d1, 0xe92f00f01dd7bb46,
    0x46dfefc3757e54d9, 0xadebb8ab33cf53fd, 0xde26f43cebb9fb13, 0x53cb33b05c71f903, 0x5463d9be73d7a57c, 0xa724c4348a8a7785,
    0x6c094298950b2e13, 0x6eb587f85d1b955b, 0x75ae670cfebe87ee, 0x0209205196ee44fd, 0xbc313befa47002d2, 0x52919bf7c554b2a5,
    0x20342502e45f9944, 0x31503a94a5fa8486, 0x5037f1eae70aa57c, 0x97f7312746ad552f, 0xc2110242f1f473eb, 0x7c4bf7d7bc186380,
    0x147448f455164cf3, 0x9e41f67abed092f8, 0xb9ed07aeb11e6f14, 0x13366ea8450c980c, 0xdc95825d94d7e8e5, 0xb94ca0a68bb49a3f,
    0x72fb2a51275a7f86, 0x6f41e2186c1eac0c, 0x04fe9964974b2a30, 0x0419fdd5ac25eb65, 0x4b45fcefb3f00d28, 0xbbc79110750b0d4c,
    0x1fa62038bb705ce2, 0x0669e112a77e2cf6, 0x1bfd51f32d642080, 0x503cbbdc2ed0995b, 0x03db4ab6a2c85df1, 0x35b7286ae0070716,
    0xd531ad2f144688ea, 0xf7f0be49edceb18b, 0xbc2ce2dbd1420805, 0x36a9c7dd863d201d, 0x0682d27f5d705674, 0x7d8793c29f6e9849,
    0xc89f3bc6ca73ecd0, 0x644bbb931490b0a2, 0xcca11a497dfc9651, 0x688b0db6646d5130, 0xe6e9b2cc97f9222c, 0xc9f41352b7e64d12,
    0x23c6bfb2cfabf83b, 0xa5ae6f39e9d21975, 0x861b1a01a82d4ee6, 0xbb22b47d7e4bdbae, 0x19c77eb08c58e23b, 0x10defe55ecdcb7d3,
    0x1b8e705690e36229, 0xe7aab62cd8de88aa, 0x34e634f64e0524aa, 0x0e4445cdc97b14c3, 0x941350c725871672, 0x3001fbc6d6ee50a1,
    0x5a0da347e933c511, 0xf8af4b32e28594a1, 0x67a54dae1d6facd5, 0x3eeb38cd3d1f8276, 0x44bb26c79771b8fb, 0x84194650605a8499,
    0xd7922f535ed5325a, 0xfc19139a6e417675, 0x19a7d2f4d4f0f5e6, 0xe23b86798456a588, 0x0baf63504273fa9e, 0x80520a8bccbcfe93,
    0x2c295f8afb5033b0, 0x7cdb6a60511d710f, 0x91472fe29b53b3d9, 0x0fda2ea95fb19df8, 0xe11888f18ddf9c9b, 0x31f40bdaaeaf81d8,
    0x1108707a0382ef8c, 0x35f6d9670e6032f0, 0x98497f160509eb25, 0x69332e963e216500, 0x754f9bbf78b133ba, 0x6ac18ef6f62c7fe9,
    0x8c95902d20403dc1, 0xa95ee809f34fe4ec, 0xb95c45aeb7394fe9, 0x18513721d6513369, 0x8ef3bf8cb1077309, 0xa90741944fe4008c,
    0x1ee33cffc5a5feb8, 0xf915d3f0de7e4d56, 0x31a9d047ffa8142b, 0x1dc48ce64fcbe511, 0xfe188280ce520d6b, 0x69bcbe3cd624716d,
    0x6d9c223f3e92fe23, 0x0ba0d4d150b6c22b, 0xb6aed5549d84b41d, 0x5829fb8f63c1d17e, 0x26a3a1a2efb992af, 0x52e40916ae8ef8bf,
    0x330cedfb6663ebd2, 0xaff6ed304bced7ce, 0x443d37d5d9d88097, 0xd454110673312324, 0x699dfb43710a562b, 0xc9c8985e3beb460b,
    0x0456ce2fd0651c3f, 0xe6c910eb7b855787, 0x5179375bb23b5fd5, 0x6bc8b63f019c3057, 0x70eaa24e83556970, 0xf4d87440340c46ff,
    0xd382fe067955463a, 0x73696ca405babae9, 0xc654c0bcc40f5206, 0x151c0bd627d733df, 0x5c0651ee893837e6, 0xd09a0fead49ec642,
    0xd64bf811cbb9d068, 0xeee625a8fee75633, 0x2588b1bc550e1cc5, 0x433c7ba4de24bb0b, 0xd74901a5f6f9516e, 0x2a88ac9947926c50,
    0x5e84e922b8e50548, 0xfe0c0abb6b15094e, 0x6111932e8dd9ee80, 0xb9fdf06b928137e3, 0xbe3f8b5c7007b827, 0xf8c121ca9add0d7c,
    0xa5e1ba3b3587d939, 0xd4eab4782dc452cb, 0x0a8c40b634289f5e, 0x88c19fe08bccf071, 0x2e49104d0d032f90, 0x35f7fc15c246ecee,
    0x408355dc21cffe04, 0x3fbbeb67777c8ae2, 0xd543a98c60629e87, 0xa37d3ab03daadf4b, 0x55f301477647f809, 0x2419efaa28c9c542,
    0x303c3125d9c6673e, 0x22db271aad55c173, 0xca70df67e7a93f70, 0x7821a9b6d4362e18, 0x979c6a5dd0a503f0, 0x30961db433878a13,
    0xe14632d3c3e81793, 0x3e4844e2cf92b909, 0x2982722dd6a201f8, 0x9957cbe7f545240d, 0x4e4fc51a7032bccb, 0x30d949b0d26f6be9,
    0x00f2751d1e7c90e4, 0xa26519cce848a596, 0xbfcbcf1ecc76b151, 0x9d5fdfe427e7414c, 0xce9be211c297b08c, 0xe834377354d88706,
    0x9011f1c2a5faf8cf, 0x5fdedb16f6e12c45, 0x401c333a3b86509d, 0x56b95e19baeecbac, 0xf02c9189b7f87e07, 0x97f190f8e361a402,
    0xe0c38713b12acaac, 0x2da5a5799ae751f4, 0xd5023ae548a4634e, 0x31201404ff023940, 0x0b87a1322aa2a9e1, 0x289801b82e603610,
    0x7dca21fe0b41ad42, 0x472fdb68a03ed08f, 0xdf56bf0c23fa4a25, 0x8b78de8e59cac797, 0xbeda825f5e023d31, 0x737a536527632f0e,
    0xaf36bc33678b0063, 0xd9ddd4a6afdbdd7f, 0x6038f4d9215e2937, 0xec3aed6f21a93c79, 0x3f883ebfadbe59f4, 0xa0574d7eaaefade0,
    0x3afdab724a955c8c, 0x6f89e9c67c337cf0, 0x362020603a785b21, 0x76ab419a5454abf4, 0x97fe1348edb4758e, 0x7e3fddf7142780a8,
    0x3f028b6623017d72, 0xbca0854307408b5e, 0xe2866b187838e217, 0xc9c9fd320859176c, 0x775ff51cd0d118f1, 0x07cf086fb4abf6bc,
    0x13b9b35de0657abb, 0xe074d24537bb71bc, 0x09fa052730e9b616, 0x089029d5e4dd5ee9, 0x5edab00eb42c9489, 0xf7a032f7e0baf5e9,
    0x7976b6f75a9446d9, 0x00085e64a637ffed,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LN2_XXW_F: usize = cb_flat_len(LN2_XXW_GOLDEN, 2561, 5120);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static LN2_XXW: ConstBand<LN2_XXW_F, 2560> = cb_build(LN2_XXW_GOLDEN, 2561, 5120);

const LN10_NARROW_GOLDEN: &[u64] = &[
    0x6cc8fed9dd141fcb, 0xac522cbbec727362, 0x25025ef2653443c9, 0x0516f72a492de737, 0x53dc263da50d1660, 0x10f1d89d2dad675e,
    0x1d51c5e7d935d663, 0xe1f3e3ffb00c61ab, 0x75f259ee3ae1da60, 0xdb1a2fd82d7200fc, 0x6e657ace4128a1d9, 0x3ed446517afcbe0d,
    0xc07434c96cd030a8, 0x84e68598242619fb, 0x442d5e7650368a2f, 0xc3ea15c387eadf70, 0xcbd09801048eda72, 0x4b9801e3fc19cdc1,
    0xecdcc8bfedda05d7, 0x576d6d4236f66b17, 0xcd568f02b8576207, 0x11cd0a44e65f1d3e, 0x3e26cb510e2f5ced, 0x8defd38e074ff2b0,
    0xffea14eac7a39d73, 0x163d144fef48484a, 0x0000028da58b2316,
];
const LN10_NARROW_F: usize = cb_flat_len(LN10_NARROW_GOLDEN, 0, 512);
static LN10_NARROW: ConstBand<LN10_NARROW_F, 513> = cb_build(LN10_NARROW_GOLDEN, 0, 512);

#[cfg(feature = "_wide-support")]
const LN10_BASE_GOLDEN: &[u64] = &[
    0x6cc8fed9dd141fcb, 0xac522cbbec727362, 0x25025ef2653443c9, 0x0516f72a492de737, 0x53dc263da50d1660, 0x10f1d89d2dad675e,
    0x1d51c5e7d935d663, 0xe1f3e3ffb00c61ab, 0x75f259ee3ae1da60, 0xdb1a2fd82d7200fc, 0x6e657ace4128a1d9, 0x3ed446517afcbe0d,
    0xc07434c96cd030a8, 0x84e68598242619fb, 0x442d5e7650368a2f, 0xc3ea15c387eadf70, 0xcbd09801048eda72, 0x4b9801e3fc19cdc1,
    0xecdcc8bfedda05d7, 0x576d6d4236f66b17, 0xcd568f02b8576207, 0x11cd0a44e65f1d3e, 0x3e26cb510e2f5ced, 0x8defd38e074ff2b0,
    0xffea14eac7a39d73, 0x163d144fef48484a, 0x0000028da58b2316,
];
#[cfg(feature = "_wide-support")]
const LN10_BASE_F: usize = cb_flat_len(LN10_BASE_GOLDEN, 0, 512);
#[cfg(feature = "_wide-support")]
static LN10_BASE: ConstBand<LN10_BASE_F, 513> = cb_build(LN10_BASE_GOLDEN, 0, 512);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LN10_XW_GOLDEN: &[u64] = &[
    0x62888308de6df438, 0x8f43df1051fbf909, 0x5869b8e14850dd93, 0x4224d7b452067216, 0xc14c5db9e2cea323, 0xcb26d06304a952a5,
    0xbe34a28c5ac9cb76, 0xac407947adb2c030, 0x04475dbdc95b27fb, 0xef5080d22025ce13, 0x5b5af879e667b2ec, 0xf8b53717de5dde95,
    0x15af5dc4791b2ba9, 0x84705abd7921a30d, 0xad5d6cfd0ed5e78e, 0xa21ae76d44622b48, 0x64cd92aa52fd6f1e, 0xe134bc9957f14e54,
    0x544f221a53a824ec, 0xfd25ddd9ba5e49f3, 0x2a14a0a9fad2acb9, 0x249913486a832a0a, 0x90c4bcc376bed8e9, 0x68b021d352b2b6ad,
    0xd562de3f877b8d0f, 0xe979fa984d72d8b4, 0xf3115734c1f9d71c, 0x3905b9df6ae03096, 0x6e306f9a28849a63, 0xa3fd9e67b4636c17,
    0x7c1026dce3026a52, 0x59747ef9de53b482, 0x26e16ed15a671e80, 0xbda221cd196c5233, 0x2509900ee844a7ea, 0x6d61cce0cdcd1a90,
    0x2e4e9c22836c7405, 0x7f8d6778f2dc6674, 0xc00bbeac259668fb, 0xaf65ec5fca064670, 0x3addb9d7caf760ab, 0xcd6235af7af47c32,
    0x6a52c3acac0c03a1, 0x8dd4c3a200fdc7c7, 0x2b0796bb40c0039a, 0x677a33974fcc3d54, 0xe68b9518337f505b, 0x11b448930110e59c,
    0xfbe2bf3a63889fc0, 0xf8e2398e598f1081, 0x97b2e142fc467dc5, 0x00f43df6884f9f17, 0x673a030f7d6f1364, 0x000000000000487b,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LN10_XW_F: usize = cb_flat_len(LN10_XW_GOLDEN, 513, 1024);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static LN10_XW: ConstBand<LN10_XW_F, 512> = cb_build(LN10_XW_GOLDEN, 513, 1024);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LN10_XXW_GOLDEN: &[u64] = &[
    0xc36f6f24fcf7f4cc, 0x04b91095c74639b2, 0x3a05573f0cdc4146, 0xd09cdfa18b94bfb1, 0x0d844933c4ac25f8, 0xe71dd97a2b0af9b4,
    0xd15600aeee2b285f, 0x46b172cdcd2b4271, 0x9fee55481ab26a6f, 0x545d777296afd24d, 0xe6aee4939901e71e, 0xf6cdda5d646c3009,
    0x5f2e0f2f1ff7dd27, 0xb6de1a46a16c5fe1, 0xe370a222f1c0de32, 0xc984493626759410, 0x5ab3d885a4ec069c, 0x118071a0b78f083d,
    0x5cfc4974002f6059, 0x1d51b8b0ae11d116, 0x72005232af0d3235, 0x25fce9b1e871e6f1, 0x8db2a9081c23dc30, 0x94eed9e46f62e7ba,
    0xa7cedd9c93e47516, 0x15b42e8f33e06288, 0xc7ddb639897a1bfc, 0xd43dd967a4491db2, 0xdefd12e8df7e8104, 0x44adfa9fd577cf96,
    0x85ff5d6c655f68fa, 0x1ed4cc81f3ae119b, 0x8c99aef45b72050a, 0xcb0bb698fc845fa0, 0xad195c25617df956, 0xe5198b89da09b9ce,
    0x1623496ffd3d9e48, 0xd02f20e675b44ee8, 0x5645988df82717e1, 0xe403abc1ffd401be, 0x07cb876cc754695f, 0x04361ddcd489ab7a,
    0x3fa7df30b35783dc, 0xe08ef41f945990af, 0x466245d48b7be767, 0x12a2c109e8c4075e, 0x5056142d1115c804, 0x92612c2676255f81,
    0xbe6774d9cc246b44, 0xaba32880b81684c8, 0x06dab1936a9137e7, 0x3eda640c6151dab4, 0xdbfd807e91a549a3, 0x1d7c666cfe227668,
    0xebc23ef3b640473a, 0xb15c59f284355458, 0x23568ff7eeb135c1, 0x0b095a620edfaba1, 0xf27a7494b67c215a, 0x7670f0304e9b2971,
    0x104771777bfcbe28, 0x3fb90f933916038e, 0xbfc9528834540473, 0xc3c7fd6bda0bb64c, 0x767a50b96dfd9571, 0x11e1e1c169d9f68a,
    0xcaf18f29bfced5e4, 0x1e85cfe4ee7b5fcc, 0xf71dc694694b68a5, 0x5b95ff340eebe71f, 0xfdda261a50132de2, 0x6b497ddb3227ae68,
    0xe76883ce497d7f30, 0xf0e1d20683cf0e5c, 0xb02609cba5dd4636, 0x1551c824c399fb05, 0x3c414979c770fd15, 0x6b6d603ea9a4b8a4,
    0x65ec1966f14ea89f, 0xc5f08d6a37299674, 0xaddf41f225783eec, 0x233ad194a3604636, 0xa5b48974319f6243, 0x36955185f9e24f10,
    0xa3dce3868b3c1c7e, 0x2e276afcc2bce949, 0x7b1b5d5b379a799e, 0x6506a536c513394d, 0x7f91d2bb6a498326, 0xa72d6672bbcdbdad,
    0x97bd9dd8838a1413, 0x6f397968aefd9d0a, 0x0d54a099c5f7a262, 0x9ab19867dfd1fed1, 0x614ec624c75e17f3, 0x449c1e6da2ffec10,
    0xce837a9c05f76bc3, 0x18ab88007a5ad2c7, 0xd362fa8a1b780fb1, 0xb0cfb4d02344c87f, 0x8af004515cf04074, 0x06deb88bb936e688,
    0x6608c59f5142b9be, 0xdc9d806e644f072d, 0x31f4f7481d96d673, 0xd27245c4ea1dce0b, 0x0000000000e429b8,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LN10_XXW_F: usize = cb_flat_len(LN10_XXW_GOLDEN, 1025, 2048);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static LN10_XXW: ConstBand<LN10_XXW_F, 1024> = cb_build(LN10_XXW_GOLDEN, 1025, 2048);

const LOG10_2_NARROW_GOLDEN: &[u64] = &[
    0x1995e9c8b2e525d0, 0xe27844ae0cf73ae0,
];
const LOG10_2_NARROW_F: usize = cb_flat_len(LOG10_2_NARROW_GOLDEN, 0, 38);
static LOG10_2_NARROW: ConstBand<LOG10_2_NARROW_F, 39> = cb_build(LOG10_2_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const LOG10_2_BASE_GOLDEN: &[u64] = &[
    0x4ecc94b13eaa610d, 0x0550fd70e43f2568, 0x05b8168cf62e3004, 0x5b19b91a36e40db9, 0xcc232897c6948ec1, 0xbb664830a9ceb98f,
    0x49df735fe2b051fc, 0x2d70cf3e4ec5a15c, 0x4fdadf9cc8ff454a, 0xb7f3fd7564ef8019, 0x8cefb605dc67272f, 0x29901c6bb2cb9dd3,
    0x385b22980a4f4387, 0x7aca8561a0399df6, 0xbe1e9381caa8ae6d, 0x04496c57d0e77ac1,
];
#[cfg(feature = "_wide-support")]
const LOG10_2_BASE_F: usize = cb_flat_len(LOG10_2_BASE_GOLDEN, 0, 306);
#[cfg(feature = "_wide-support")]
static LOG10_2_BASE: ConstBand<LOG10_2_BASE_F, 307> = cb_build(LOG10_2_BASE_GOLDEN, 0, 306);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LOG10_2_XW_GOLDEN: &[u64] = &[
    0x677501f5a994ed16, 0x94122e5919d8ba86, 0xc759e396f0d5c719, 0x97975f6e49722906, 0x2092a959d93f9d88, 0xe7f38c16ca93daf1,
    0x1a44f60e59a9da6f, 0x5a707aa11c944323, 0x06c59674ffca60ca, 0x1b4663cdde52302f, 0x40f7527f2964da11, 0x9d1b51b920bc9648,
    0xe77b0546b3956ca0, 0xe2dfbbb32611d72d, 0x06c8fc5f4bea57be, 0x080ff4bef99e606d, 0x6778d75e67ffef56, 0x0f6c80ebc3dfcaac,
    0xf78aca606a38c875, 0x7669473cdfe0adcd, 0x1655cfe77d190340, 0xfeb729972dfe3e02, 0x62c1b3ab4f69cc07, 0x5c49fb0b230ba397,
    0x539a39805bd2806c, 0x144f90946be3ff62, 0xc10742eac36b7345, 0x93cf160fde239a3a, 0x3277248c4e7151c6, 0xfa2f79494c4578c3,
    0x495b5d5ff89c1ef4, 0x17d89e885ee3b224,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const LOG10_2_XW_F: usize = cb_flat_len(LOG10_2_XW_GOLDEN, 307, 615);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static LOG10_2_XW: ConstBand<LOG10_2_XW_F, 309> = cb_build(LOG10_2_XW_GOLDEN, 307, 615);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LOG10_2_XXW_GOLDEN: &[u64] = &[
    0xc36e5878d0b3551d, 0xad6ddbb7f509ec4a, 0x092b76031d222887, 0xf36fff71b187da7a, 0xcf2233db91719dbb, 0xc026a2034c4ea929,
    0xad1fe5eb67eb1533, 0xbfe5dc5cccaf357e, 0x9357f288ae70763c, 0x478a968266831dcc, 0x490609f092546f22, 0x2ae4a33d023824b1,
    0x1c2c44f05b7de601, 0xdfba7b3e517fb73f, 0x865d71daa69dfc85, 0x8acda4df0843edfd, 0x0a8317c44cc9b0f2, 0xd7b1552bd9fb4dd1,
    0x717ab2e7cf9d5f8b, 0x1a09f96ffeebf519, 0xc53a39d26b75c80f, 0xcbd79a3cebcc57ff, 0x75d4be4d23117721, 0x845527e8822c20aa,
    0xeb28a7828723e4a6, 0x032251e27ada8491, 0x42334a93a0ef7ac2, 0xcbccc24e8462c51a, 0xc42d59bc814686e2, 0xe815118495d19cf1,
    0x3d64a7219106a8d2, 0x42838631d0076145, 0xffaa0af334e36e17, 0x358e7f9139a49958, 0x6b0b6a73f6f7a5fd, 0xc8876b9d56b8264a,
    0xeffb64b91e3e238b, 0x0cd666999aa5b14b, 0xc016c97a273291bb, 0x40aadcbf73226020, 0x2f07eea18e3aee00, 0xe24a2d59a0d8276e,
    0x093b4fd5669d53b5, 0x5f44f025bdec9772, 0x033d6518a7523e59, 0x9a948938b51f9dba, 0x86d54f1e65894df4, 0xc23aa3b8454d01c1,
    0xa79f8872943f46bc, 0x5aa00094d96c69c3, 0x70490c954dfb852c, 0x9fb66285bded90ba, 0x6dae4f5ecb3e4b99, 0x054ba862d61bbe8b,
    0x3f8c8f595dc3cdf6, 0x49015c8df5ff2e5d, 0xbbdcc94b6888a7d4, 0xc838a392e5bf20c6, 0x47ced30a0d1809d8, 0x70b33700638911c8,
    0x4a7b740ccd55f926, 0x76979a7bf8270d92, 0xed86b760b142b5c8, 0x0760fafecbcc9206,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const LOG10_2_XXW_F: usize = cb_flat_len(LOG10_2_XXW_GOLDEN, 616, 1231);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static LOG10_2_XXW: ConstBand<LOG10_2_XXW_F, 616> = cb_build(LOG10_2_XXW_GOLDEN, 616, 1231);

const DEG_PER_RAD_NARROW_GOLDEN: &[u64] = &[
    0x046cbc09261dcaf5, 0x608dbec089b7e9cf, 0x00000000000000a8,
];
const DEG_PER_RAD_NARROW_F: usize = cb_flat_len(DEG_PER_RAD_NARROW_GOLDEN, 0, 38);
static DEG_PER_RAD_NARROW: ConstBand<DEG_PER_RAD_NARROW_F, 39> = cb_build(DEG_PER_RAD_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const DEG_PER_RAD_BASE_GOLDEN: &[u64] = &[
    0x93cda50c7f2d91ab, 0xe6ffcfaf1c3a0e96, 0x590826364f724efd, 0x871244b1d8f80c6d, 0xd97774b4a2ef5368, 0x63412229cfa72096,
    0xb97ea219f1775bec, 0x6dc3cc56ca71a853, 0x8a7bdd3e7158b2f0, 0xb889fd29871c3a3c, 0x3ef068fa5c7696aa, 0x58aadda4e065b87e,
    0xd0dd50517b8db405, 0x0436d9d6d26d408c, 0x74148a3c8e7645c9, 0x31b3607c7a499251, 0x364fb9b08c4b78a3, 0x000000283a586cb3,
];
#[cfg(feature = "_wide-support")]
const DEG_PER_RAD_BASE_F: usize = cb_flat_len(DEG_PER_RAD_BASE_GOLDEN, 0, 336);
#[cfg(feature = "_wide-support")]
static DEG_PER_RAD_BASE: ConstBand<DEG_PER_RAD_BASE_F, 337> = cb_build(DEG_PER_RAD_BASE_GOLDEN, 0, 336);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const DEG_PER_RAD_XW_GOLDEN: &[u64] = &[
    0x7e458637a8583713, 0x30a0176bdd5d44da, 0x063ad555e7a259af, 0x7ee49d09902d04a4, 0x63edfc9e1a4ce09b, 0x1b7b75187b6f2e3b,
    0xc2ee62c40f78c078, 0x97aee1acfefbcc73, 0xcb145db462a13b64, 0x27f2345a2bb20974, 0xcc39a83d788bacb5, 0x1e758261974f5349,
    0xdd57fdc528d5a0b5, 0x324acf4c6f879d67, 0x8d57806efcd4f54e, 0x1aab11f8dc55854d, 0x6e33a09d5b5f3af4, 0x869a268688cf2176,
    0x33fd6850734c5a89, 0xeee6f2390468c1d0, 0x398f634967455884, 0xdd0aabf317fd28a4, 0x9c96d2c34bb0087f, 0xa53cfd3351ac16e2,
    0xd204700f3146e1b0, 0xe618348a50cb406b, 0xc144e4533a898fbd, 0xc13acf2ea3ed9fcb, 0x09c8ffa8bcbcb41a, 0x7b2449ec04721b01,
    0xad6d986156a86597, 0x1629e16e2aa7637e, 0x81b3a32e3a817200, 0x000000dfc672a8b1,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const DEG_PER_RAD_XW_F: usize = cb_flat_len(DEG_PER_RAD_XW_GOLDEN, 337, 645);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static DEG_PER_RAD_XW: ConstBand<DEG_PER_RAD_XW_F, 309> = cb_build(DEG_PER_RAD_XW_GOLDEN, 337, 645);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const DEG_PER_RAD_XXW_GOLDEN: &[u64] = &[
    0x6b6011800a556b5b, 0x741883b1a842b899, 0xcc0b86ca6dd46980, 0x55c4e0d5ce090410, 0xa7897dfc3bed5936, 0x7f80879d70919bec,
    0x5ab11f228e7754f6, 0x821f4bf291934994, 0x3a49d9bfdeafdac2, 0x1608322363528b44, 0x6a331a6ee4db6fc4, 0x1777707f84b7e433,
    0x3796ff7979978fe7, 0x20f39e94a472f3dc, 0x310cf354406729ea, 0xd51e4c23d3309fcb, 0xbf7f62063aa3aa36, 0x582ea32290cd5539,
    0x616056cd3c9b4dee, 0x223ae00c93f900b7, 0x5fd6bad75e52558b, 0x39bdf95557f75702, 0xd928e7be0334245f, 0xb3b9288d7276d113,
    0x413a1987cf9cd52f, 0x754d8e85ef67e707, 0x08744018049a10f9, 0xe15c2eff475ec376, 0x16b8e3a3450c8895, 0xab1558d61b1cd0c9,
    0xa88f248c5670106a, 0xca65796e3819ca43, 0xcd477fcb09171baa, 0x63725a7c54e2dd9c, 0xb2b38b492cede2e6, 0x32da6e640c3adef0,
    0x66f69b8d9b8b351e, 0xb7fdc27c6663b97f, 0x04e9876b5b7af552, 0xe881cd2b2e43c223, 0x9de16568236df2b7, 0x3e38c166c60b823d,
    0xac7f6c6ca0ca1424, 0x4e9655cad893e758, 0x347e6fe7f4323fc5, 0xb3c895dc6b7eaf6d, 0x72e1263c4a883f01, 0x1121f2c7de74897a,
    0xbaa4109d77bb824c, 0xdf586767f5f9683c, 0x7765d9b1b8ce6b78, 0xb409ed4f8befa8f0, 0x5b3e2621ecaf353d, 0x50714279930979be,
    0x11cc719a4a880235, 0xb38cf48becc9b726, 0xc6c45b5cab0ba5f2, 0x93d919de723c2345, 0xf0e8e74967688490, 0xa7e754fc65d8091e,
    0x8f9c6963a1859986, 0xe4bf0cbe507d85f4, 0xf55e191004aa2079, 0x434cf54d69c431be, 0x3fd2d186a4a73a55, 0x000000453e68cbba,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const DEG_PER_RAD_XXW_F: usize = cb_flat_len(DEG_PER_RAD_XXW_GOLDEN, 646, 1261);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static DEG_PER_RAD_XXW: ConstBand<DEG_PER_RAD_XXW_F, 616> = cb_build(DEG_PER_RAD_XXW_GOLDEN, 646, 1261);

const RAD_PER_DEG_NARROW_GOLDEN: &[u64] = &[
    0xd0b99db786f6a21e, 0x0d2161c22e91df12,
];
const RAD_PER_DEG_NARROW_F: usize = cb_flat_len(RAD_PER_DEG_NARROW_GOLDEN, 0, 38);
static RAD_PER_DEG_NARROW: ConstBand<RAD_PER_DEG_NARROW_F, 39> = cb_build(RAD_PER_DEG_NARROW_GOLDEN, 0, 38);

#[cfg(feature = "_wide-support")]
const RAD_PER_DEG_BASE_GOLDEN: &[u64] = &[
    0x53662253197dacd6, 0xca93abd546c853af, 0xafb6e7c4fcd6961e, 0xdc3c2c44f6b40a78, 0x7e74f3f9226fa4cf, 0xa351ade7f602237a,
    0xed84d3f743b4195a, 0x47ae225af4b795c0, 0xbe3468ac449e5e7a, 0x1302ba38527038c9, 0x085028c292e93d17, 0x6f633189ab2bcd13,
    0x1e1c234bdec75943, 0x7043c21afc2d46c9, 0x1bf00f22242ce9c9, 0x1d7adbef673099a7, 0x2870caefd142f227, 0x0000000003231610,
];
#[cfg(feature = "_wide-support")]
const RAD_PER_DEG_BASE_F: usize = cb_flat_len(RAD_PER_DEG_BASE_GOLDEN, 0, 336);
#[cfg(feature = "_wide-support")]
static RAD_PER_DEG_BASE: ConstBand<RAD_PER_DEG_BASE_F, 337> = cb_build(RAD_PER_DEG_BASE_GOLDEN, 0, 336);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const RAD_PER_DEG_XW_GOLDEN: &[u64] = &[
    0x553697da54311023, 0xffdf7bd194f284e2, 0x85f13d79b5bd2ed3, 0xa28bd61bfce028af, 0xfef2c30c0c4a4516, 0x53b3a9a4a2d0850d,
    0xed7f47d88b8c25fa, 0xc5f764c3ba8d5a11, 0x62175a64ededd05b, 0xf4499f969a4d09fe, 0xa0659c550a85646c, 0x4f59e5954f432b19,
    0xee49ed32056c2502, 0x8f86d4c334f672e2, 0x5fdac650bf3eda7a, 0xfafa8d9e79b7aec4, 0x72a7194b7eb20413, 0xccb00ccb08aa502a,
    0x52e7308c68856939, 0x36bbaba0a203cd15, 0x86f8d937387fc3e1, 0x6cc5a100d2be9c97, 0x1327e695f74cf27f, 0x293b49128f270679,
    0xf6f0c9e5aeb7f507, 0x525d5252ea006d4e, 0x7052344e4e1c456a, 0xcc5c86391719f82f, 0x70d1d68ed4d7c635, 0xe0edda765cb9d361,
    0x7b498db227a0ffc7, 0x6043138d206c7744, 0x01be9d1b4f341c9f, 0x00000000117350b0,
];
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const RAD_PER_DEG_XW_F: usize = cb_flat_len(RAD_PER_DEG_XW_GOLDEN, 337, 645);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static RAD_PER_DEG_XW: ConstBand<RAD_PER_DEG_XW_F, 309> = cb_build(RAD_PER_DEG_XW_GOLDEN, 337, 645);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const RAD_PER_DEG_XXW_GOLDEN: &[u64] = &[
    0x2a00da24f4b6f6e0, 0xceeba20495ba61e3, 0x2b186c958c06fcd1, 0x767bdc6419b5e1b0, 0xfc51b2eca05ce0b9, 0x5c5c447f1eb6674e,
    0x402fe4f3ce9519bf, 0x0afcb5b2d33959b3, 0x2ccdb89942e80a9c, 0x3d35565316cacf0d, 0x89e80b0fe7bf1df6, 0x5e759b464eed24ee,
    0x2aeda5c4de53295f, 0x9edeaf5449531725, 0x9d6bdd94b0897e63, 0x3dfd91be5d5b6cef, 0xb799ccda2edac6b0, 0x981486f438da0aa2,
    0x17d9e3d4c5fca300, 0x3899247ace89f138, 0x574533f97f231b81, 0xce4b70c5ee7832bb, 0xc5aefcf7bb7b1362, 0x8a61e02aa28e26d0,
    0x94328a3f0ea4c01e, 0x981ffc6e56663a05, 0x1ca7789f7e3c61f0, 0x48e59fee1cc1d6c7, 0xdfc2ec19932446c5, 0x9cb9b2a7b0e2e4a6,
    0x013e16633b6a0d36, 0x863d7aeaad55c5b4, 0x6f30390d11834771, 0xc05b9e961a242520, 0x0844f5947bf7ef06, 0x701d35fb9a464366,
    0xc1902391f8f8dbe1, 0x5bbf78aa2812b3d7, 0x3400d511900d3ced, 0xd7dbec2f933ab1ba, 0xe2762e66e547e17e, 0x03421714980f0c6b,
    0x4a4a8de467deaff5, 0x71b35f9fb86bba28, 0x665b7b007dba743c, 0x80ac4bebccf1600e, 0xfe0f932428f7795b, 0x156df15a7bedfdae,
    0xda5a9546dc56bb4e, 0xc936ed510672760e, 0x5b97b9f332daf70b, 0xddd61fc909c6c269, 0xf5cceb952574f52c, 0xa4c0b9c0cf89fb11,
    0xc4a0fd13b4504384, 0x26d344438557aeec, 0xc2367a752a8f172e, 0x421149fc62654cec, 0xdfca1752710b1b4d, 0xb8dde656b6456a46,
    0xc4aed6b999d5280d, 0xd76180bfa2bdefe1, 0xee83db32147f079e, 0xcc0b86b760465ec7, 0x5454f154337e0208, 0x0000000005665787,
];
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const RAD_PER_DEG_XXW_F: usize = cb_flat_len(RAD_PER_DEG_XXW_GOLDEN, 646, 1261);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static RAD_PER_DEG_XXW: ConstBand<RAD_PER_DEG_XXW_F, 616> = cb_build(RAD_PER_DEG_XXW_GOLDEN, 646, 1261);

/// `floor(pi * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn pi_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 513 {
        return cb_get(&PI_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 513 {
            return cb_get(&PI_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 512 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 512 {
                return cb_get(&PI_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 1024 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 1024 {
                return cb_get(&PI_XXW, idx);
            }
        }
    }
    panic!("const_table: pi scale out of generated range");
}

/// `floor(tau * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn tau_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&TAU_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&TAU_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&TAU_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&TAU_XXW, idx);
            }
        }
    }
    panic!("const_table: tau scale out of generated range");
}

/// `floor(half_pi * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn half_pi_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&HALF_PI_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&HALF_PI_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&HALF_PI_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&HALF_PI_XXW, idx);
            }
        }
    }
    panic!("const_table: half_pi scale out of generated range");
}

/// `floor(quarter_pi * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn quarter_pi_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&QUARTER_PI_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&QUARTER_PI_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&QUARTER_PI_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&QUARTER_PI_XXW, idx);
            }
        }
    }
    panic!("const_table: quarter_pi scale out of generated range");
}

/// `floor(e * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn e_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&E_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&E_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&E_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&E_XXW, idx);
            }
        }
    }
    panic!("const_table: e scale out of generated range");
}

/// `floor(golden * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn golden_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&GOLDEN_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&GOLDEN_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&GOLDEN_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&GOLDEN_XXW, idx);
            }
        }
    }
    panic!("const_table: golden scale out of generated range");
}

/// `floor(ln2 * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn ln2_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 513 {
        return cb_get(&LN2_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 1281 {
            return cb_get(&LN2_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 1280 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 1280 {
                return cb_get(&LN2_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 2560 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 2560 {
                return cb_get(&LN2_XXW, idx);
            }
        }
    }
    panic!("const_table: ln2 scale out of generated range");
}

/// `floor(ln10 * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn ln10_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 513 {
        return cb_get(&LN10_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 513 {
            return cb_get(&LN10_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 512 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 512 {
                return cb_get(&LN10_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 1024 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 1024 {
                return cb_get(&LN10_XXW, idx);
            }
        }
    }
    panic!("const_table: ln10 scale out of generated range");
}

/// `floor(log10_2 * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn log10_2_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&LOG10_2_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 307 {
            return cb_get(&LOG10_2_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 306 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&LOG10_2_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 615 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&LOG10_2_XXW, idx);
            }
        }
    }
    panic!("const_table: log10_2 scale out of generated range");
}

/// `floor(deg_per_rad * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn deg_per_rad_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&DEG_PER_RAD_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 337 {
            return cb_get(&DEG_PER_RAD_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 336 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&DEG_PER_RAD_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 645 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&DEG_PER_RAD_XXW, idx);
            }
        }
    }
    panic!("const_table: deg_per_rad scale out of generated range");
}

/// `floor(rad_per_deg * 10^scale)` limbs (little-endian, narrowest-fit)
/// plus the round-up bit, for the const working `scale`.
///
/// `const fn` so a caller keyed on the const-generic SCALE folds
/// to the single matching entry per monomorphisation — no runtime
/// search on the hot path. The band's per-scale `(limbs, round_up)`
/// is rebuilt at compile time from one golden mantissa ([`cb_build`]).
pub(crate) const fn rad_per_deg_entry(scale: u32) -> (&'static [u64], u8) {
    // NARROW band (0..=38) is always present — the public
    // `DecimalConstants` trait on D18/D38 reads it in every build,
    // including default / no_std (no `_wide-support`).
    if (scale as usize) < 39 {
        return cb_get(&RAD_PER_DEG_NARROW, scale as usize);
    }
    #[cfg(feature = "_wide-support")]
    {
        if (scale as usize) < 337 {
            return cb_get(&RAD_PER_DEG_BASE, scale as usize);
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 336 + 1;
        if scale >= base_lo {
            let idx = (scale - base_lo) as usize;
            if idx < 309 {
                return cb_get(&RAD_PER_DEG_XW, idx);
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 645 + 1;
        if scale >= xw_lo {
            let idx = (scale - xw_lo) as usize;
            if idx < 616 {
                return cb_get(&RAD_PER_DEG_XXW, idx);
            }
        }
    }
    panic!("const_table: rad_per_deg scale out of generated range");
}

use crate::int::types::traits::BigInt;
use crate::support::rounding::RoundingMode;

/// Builds the work integer `W` holding `floor(const * 10^scale)`
/// from a narrow little-endian `limbs` slice by DIRECT limb injection:
/// a little-endian u64 limb slice IS the value (`Σ limbs[i]·2^(64·i)`),
/// so the low `min(len, W::LIMBS)` limbs are copied and the rest stay
/// zero — bit-identical to the previous high-to-low Horner fold
/// (`acc = (acc << 64) | limb`), which kept the same low limbs but paid
/// a full-`W`-width shift + OR + rebuild PER SOURCE LIMB (O(len · W)
/// instead of O(len)). The fold was a measured hot frame in the wide
/// `ln`/`exp` shells, where every `pow10`/`ln2`/`pi` lookup runs this on
/// a multi-limb entry at a 32-limb-plus work integer.
#[inline]
pub(crate) fn limbs_to_w<W: BigInt>(limbs: &[u64]) -> W {
    W::from_mag_sign_u64(limbs, false)
}

/// Applies `mode` to a `(floor-limbs, round_up)` table entry,
/// returning the correctly-rounded constant in the work integer `W`.
///
/// The constants are irrational + positive, so the dropped tail is
/// never an exact tie and never zero. Hence: Trunc / Floor keep the
/// floor; Ceiling always bumps (`+1`); the three half-modes all
/// reduce to round-to-nearest = `floor + round_up`. This reproduces
/// a correct rounding of the mpmath value under every mode.
#[inline]
fn round_entry<W: BigInt>(limbs: &[u64], round_up: u8, mode: RoundingMode) -> W {
    let floor = limbs_to_w::<W>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump { floor.wrapping_add(W::ONE) } else { floor }
}

/// Like [`round_entry`], but returns `None` when the value does
/// not fit the SIGNED positive range of the work/storage integer
/// `W` (i.e. it would exceed `Int::<W::LIMBS>::MAX`). Used by the
/// PUBLIC constant accessors, where a constant requested at a
/// scale too large for the type's storage must surface an overflow
/// (the caller panics with an "out of storage range" message),
/// not silently wrap. The constants are positive and the limbs are
/// narrowest-fit, so the fit test is purely structural:
///
///   * more limbs than `W` holds            -> overflow;
///   * exactly `W::LIMBS` limbs and the top limb has its high bit
///     set (>= 2^63) -> the magnitude reaches into `W`'s sign bit
///     -> overflow (the `+1` round-up bump cannot clear an already-
///     set top bit, so no false negative);
///   * otherwise it fits, and the rounded fold is exact.
///
/// The INTERNAL kernel path (`*_by_scale` / `*_by_working_scale`) does NOT use
/// this — it folds into a wide WORK integer where the value always
/// fits and must never panic.
#[inline]
fn round_entry_checked<W: BigInt>(
    limbs: &[u64],
    round_up: u8,
    mode: RoundingMode,
) -> Option<W> {
    let n = W::LIMBS;
    if limbs.len() > n {
        return None;
    }
    if limbs.len() == n && (limbs[n - 1] & 0x8000_0000_0000_0000) != 0 {
        return None;
    }
    Some(round_entry::<W>(limbs, round_up, mode))
}

/// `pi` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`pi_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn pi_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = pi_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `pi` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`pi_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn pi_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = pi_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `pi` at the CONST working `scale` as in [`pi_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn pi_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = pi_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `tau` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`tau_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn tau_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = tau_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `tau` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`tau_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn tau_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = tau_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `tau` at the CONST working `scale` as in [`tau_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn tau_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = tau_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `half_pi` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`half_pi_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn half_pi_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = half_pi_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `half_pi` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`half_pi_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn half_pi_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = half_pi_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `half_pi` at the CONST working `scale` as in [`half_pi_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn half_pi_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = half_pi_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `quarter_pi` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`quarter_pi_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn quarter_pi_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = quarter_pi_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `quarter_pi` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`quarter_pi_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn quarter_pi_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = quarter_pi_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `quarter_pi` at the CONST working `scale` as in [`quarter_pi_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn quarter_pi_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = quarter_pi_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `e` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`e_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn e_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = e_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `e` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`e_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn e_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = e_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `e` at the CONST working `scale` as in [`e_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn e_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = e_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `golden` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`golden_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn golden_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = golden_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `golden` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`golden_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn golden_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = golden_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `golden` at the CONST working `scale` as in [`golden_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn golden_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = golden_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `ln2` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`ln2_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn ln2_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = ln2_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `ln2` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`ln2_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn ln2_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = ln2_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `ln10` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`ln10_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn ln10_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = ln10_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `ln10` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`ln10_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn ln10_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = ln10_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `log10_2` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`log10_2_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn log10_2_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = log10_2_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `log10_2` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`log10_2_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn log10_2_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = log10_2_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `log10_2` at the CONST working `scale` as in [`log10_2_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn log10_2_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = log10_2_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `deg_per_rad` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`deg_per_rad_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn deg_per_rad_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = deg_per_rad_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `deg_per_rad` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`deg_per_rad_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn deg_per_rad_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = deg_per_rad_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `deg_per_rad` at the CONST working `scale` as in [`deg_per_rad_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn deg_per_rad_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = deg_per_rad_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// `rad_per_deg` at the CONST working `scale`, correctly rounded
/// under `mode`, in the work integer `W`. **The norm.**
///
/// The scale -> entry lookup ([`rad_per_deg_entry`]) is a `const fn`; when
/// `scale` is the const-generic working scale of the
/// monomorphisation it folds to the one matching `(&'static
/// [u64], round_up)`, so the only runtime work is the cheap
/// fixed-count zero-extend into `W` (which LLVM further folds
/// against the const limbs). No runtime search, no divide. The
/// hot (non-Ziv) path uses this.
#[inline]
pub(crate) fn rad_per_deg_by_scale<W: BigInt>(scale: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = rad_per_deg_entry(scale);
    round_entry::<W>(limbs, round_up, mode)
}

/// `rad_per_deg` at a RUNTIME working scale `w`, correctly rounded
/// under `mode`. **Rare fallback** — the Ziv-escalation path
/// (`w != SCALE + GUARD`) where the const scale is not available.
/// Does NOT const-fold; every avoidable call is a const-fold
/// miss. Prefer [`rad_per_deg_by_scale`] when a const SCALE is in hand.
#[inline]
pub(crate) fn rad_per_deg_by_working_scale<W: BigInt>(w: u32, mode: RoundingMode) -> W {
    let (limbs, round_up) = rad_per_deg_entry(w);
    round_entry::<W>(limbs, round_up, mode)
}

/// `rad_per_deg` at the CONST working `scale` as in [`rad_per_deg_by_scale`],
/// but returns `None` when the value does not fit the SIGNED
/// storage range of `W` (see [`round_entry_checked`]). Used by the
/// PUBLIC `DecimalConstants` impls so an over-range request panics
/// rather than silently wrapping; NOT for the internal kernel path.
#[inline]
pub(crate) fn rad_per_deg_by_scale_checked<W: BigInt>(
    scale: u32,
    mode: RoundingMode,
) -> Option<W> {
    let (limbs, round_up) = rad_per_deg_entry(scale);
    round_entry_checked::<W>(limbs, round_up, mode)
}

/// Zero-extends a narrow little-endian limb slice into `Int<N>` as a
/// `const fn` — the strong-fold primitive. Builds `[0u64; N]` (plain
/// const-generic `N`, no `generic_const_exprs`) + `Int::from_limbs`, so a
/// caller can bake the value in a const-block at a concrete `N`.
const fn limbs_to_int_n<const N: usize>(limbs: &[u64]) -> crate::int::types::Int<N> {
    let mut arr = [0u64; N];
    let mut i = 0;
    while i < limbs.len() {
        arr[i] = limbs[i];
        i += 1;
    }
    crate::int::types::Int::<N>::from_limbs(arr)
}

/// `pi` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `pi_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`pi_by_working_scale`].
pub(crate) const fn pi_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = pi_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `tau` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `tau_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`tau_by_working_scale`].
pub(crate) const fn tau_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = tau_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `half_pi` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `half_pi_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`half_pi_by_working_scale`].
pub(crate) const fn half_pi_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = half_pi_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `quarter_pi` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `quarter_pi_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`quarter_pi_by_working_scale`].
pub(crate) const fn quarter_pi_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = quarter_pi_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `e` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `e_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`e_by_working_scale`].
pub(crate) const fn e_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = e_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `golden` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `golden_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`golden_by_working_scale`].
pub(crate) const fn golden_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = golden_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `ln2` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `ln2_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`ln2_by_working_scale`].
pub(crate) const fn ln2_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = ln2_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `ln10` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `ln10_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`ln10_by_working_scale`].
pub(crate) const fn ln10_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = ln10_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `log10_2` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `log10_2_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`log10_2_by_working_scale`].
pub(crate) const fn log10_2_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = log10_2_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `deg_per_rad` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `deg_per_rad_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`deg_per_rad_by_working_scale`].
pub(crate) const fn deg_per_rad_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = deg_per_rad_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

/// `rad_per_deg` at the CONST `scale` as a compile-time-baked `Int<N>`
/// (strong fold). Evaluate it in a const-block at a concrete-`N` leaf:
/// the `rad_per_deg_entry` lookup folds, `limbs_to_int_n` bakes the zero-
/// extend, and the `+1` bump folds when `mode` is const. Runtime / Ziv
/// path: [`rad_per_deg_by_working_scale`].
pub(crate) const fn rad_per_deg_const_n<const N: usize>(
    scale: u32,
    mode: RoundingMode,
) -> crate::int::types::Int<N> {
    let (limbs, round_up) = rad_per_deg_entry(scale);
    let floor = limbs_to_int_n::<N>(limbs);
    let bump = match mode {
        RoundingMode::Trunc | RoundingMode::Floor => false,
        RoundingMode::Ceiling => true,
        RoundingMode::HalfToEven
        | RoundingMode::HalfAwayFromZero
        | RoundingMode::HalfTowardZero => round_up != 0,
    };
    if bump {
        floor.wrapping_add(crate::int::types::Int::<N>::ONE)
    } else {
        floor
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::int::types::Int;
    use crate::support::rounding::RoundingMode::*;

    /// The six modes derive correctly from the stored (floor,
    /// round_up) pair: Trunc=Floor=floor, Ceiling=floor+1, and the
    /// three half-modes coincide at floor+round_up (no ties for
    /// irrationals). Spot-checked against `pi` at a few scales.
    #[test]
    fn modes_derive_from_floor_and_roundbit() {
        // pi = 3.14159265358979323846...; at scale 4 -> 31415.9..,
        // floor 31415, tail .9 >= .5 -> round_up = 1.
        let f: Int<3> = limbs_to_w(&[31415]);
        assert_eq!(pi_by_scale::<Int<3>>(4, Trunc), f);
        assert_eq!(pi_by_scale::<Int<3>>(4, Floor), f);
        assert_eq!(pi_by_scale::<Int<3>>(4, Ceiling), f.wrapping_add(Int::<3>::ONE));
        let up = f.wrapping_add(Int::<3>::ONE);
        assert_eq!(pi_by_scale::<Int<3>>(4, HalfToEven), up);
        assert_eq!(pi_by_scale::<Int<3>>(4, HalfAwayFromZero), up);
        assert_eq!(pi_by_scale::<Int<3>>(4, HalfTowardZero), up);
        // scale 5 -> 314159.26.., floor 314159, tail .26 < .5 ->
        // round_up = 0; all three half-modes keep the floor.
        let f5: Int<3> = limbs_to_w(&[314159]);
        assert_eq!(pi_by_scale::<Int<3>>(5, HalfToEven), f5);
        assert_eq!(pi_by_scale::<Int<3>>(5, Ceiling), f5.wrapping_add(Int::<3>::ONE));
    }

    /// `by_scale` and `by_working_scale` return identical values for the same
    /// scale (they differ only in const-fold behaviour, not value).
    /// Uses an `Int<16>` work integer, which only exists in a
    /// `_wide-support` build, so the test is gated to that build (a
    /// narrow-only build has no work integer this wide to exercise).
    #[cfg(feature = "_wide-support")]
    #[test]
    fn by_scale_eq_by_working_scale() {
        for s in [0u32, 1, 17, 18, 19, 30, 38, 86] {
            for m in [HalfToEven, Trunc, Ceiling, Floor, HalfAwayFromZero, HalfTowardZero] {
                assert_eq!(pi_by_scale::<Int<16>>(s, m), pi_by_working_scale::<Int<16>>(s, m));
                assert_eq!(ln2_by_scale::<Int<16>>(s, m), ln2_by_working_scale::<Int<16>>(s, m));
            }
        }
    }

    /// Width-independence: the same scale gives the same value
    /// (zero-extended) in different work-int widths. Exercises
    /// `Int<16>` / `Int<32>` work integers (and `resize_to` between
    /// them), which only exist in a `_wide-support` build — so the
    /// test is gated there. The always-present narrow band is
    /// covered by `modes_derive_from_floor_and_roundbit` above.
    #[cfg(feature = "_wide-support")]
    #[test]
    fn value_is_width_independent() {
        for s in [0u32, 5, 17, 18, 30, 38, 50] {
            let a = pi_by_scale::<Int<16>>(s, HalfToEven);
            let b = pi_by_scale::<Int<32>>(s, HalfToEven);
            assert_eq!(a, b.resize_to::<Int<16>>());
        }
    }
}

/// A compile-time-built `10^exp` band (exact — no round bit). `flat` packs every
/// exponent's narrowest-fit little-endian limbs; entry `i` (exp `lo + i`) is
/// `flat[off[i] .. off[i]+len[i]]`. Built by [`p10_build`] from `1` by ×10.
pub(crate) struct Pow10Band<const F: usize, const N: usize> {
    flat: [u64; F],
    off: [u32; N],
    len: [u16; N],
}

/// Total narrowest-fit limb count over `10^lo ..= 10^hi`, sizing the flat array.
const fn p10_flat_len(lo: u32, hi: u32) -> usize {
    let mut buf = [0u64; MAXK];
    buf[0] = 1;
    let mut blen = 1usize;
    let mut total = 0usize;
    if lo == 0 {
        total += 1;
    }
    let mut e = 1u32;
    while e <= hi {
        let mut carry: u64 = 0;
        let mut i = 0;
        while i < blen {
            let v = (buf[i] as u128) * 10 + carry as u128;
            buf[i] = v as u64;
            carry = (v >> 64) as u64;
            i += 1;
        }
        if carry > 0 {
            buf[blen] = carry;
            blen += 1;
        }
        if e >= lo {
            total += blen;
        }
        e += 1;
    }
    total
}

/// Build `10^lo ..= 10^hi` by repeated ×10 from 1. `10^exp` is exact, so there
/// is no round bit. Reproduces the former literal POW10 table bit-for-bit.
const fn p10_build<const F: usize, const N: usize>(lo: u32, hi: u32) -> Pow10Band<F, N> {
    let mut b = Pow10Band { flat: [0u64; F], off: [0u32; N], len: [0u16; N] };
    let mut buf = [0u64; MAXK];
    buf[0] = 1;
    let mut blen = 1usize;
    let mut cursor = 0usize;
    if lo == 0 {
        b.off[0] = 0;
        b.len[0] = 1;
        b.flat[0] = 1;
        cursor = 1;
    }
    let mut e = 1u32;
    while e <= hi {
        let mut carry: u64 = 0;
        let mut i = 0;
        while i < blen {
            let v = (buf[i] as u128) * 10 + carry as u128;
            buf[i] = v as u64;
            carry = (v >> 64) as u64;
            i += 1;
        }
        if carry > 0 {
            buf[blen] = carry;
            blen += 1;
        }
        if e >= lo {
            let idx = (e - lo) as usize;
            b.off[idx] = cursor as u32;
            b.len[idx] = blen as u16;
            let mut k = 0;
            while k < blen {
                b.flat[cursor + k] = buf[k];
                k += 1;
            }
            cursor += blen;
        }
        e += 1;
    }
    b
}

/// Limbs of `10^(lo+i)` for entry `i` — a `const fn` so a const `exp` folds.
const fn p10_get<const F: usize, const N: usize>(
    b: &'static Pow10Band<F, N>,
    i: usize,
) -> &'static [u64] {
    let o = b.off[i] as usize;
    let l = b.len[i] as usize;
    b.flat.split_at(o).1.split_at(l).0
}

const POW10_NARROW_F: usize = p10_flat_len(0, 512);
static POW10_NARROW: Pow10Band<POW10_NARROW_F, 513> = p10_build(0, 512);

#[cfg(feature = "_wide-support")]
const POW10_BASE_F: usize = p10_flat_len(0, 1280);
#[cfg(feature = "_wide-support")]
static POW10_BASE: Pow10Band<POW10_BASE_F, 1281> = p10_build(0, 1280);

#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
const POW10_XW_F: usize = p10_flat_len(1281, 2560);
#[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
static POW10_XW: Pow10Band<POW10_XW_F, 1280> = p10_build(1281, 2560);

#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
const POW10_XXW_F: usize = p10_flat_len(2561, 5120);
#[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
static POW10_XXW: Pow10Band<POW10_XXW_F, 2560> = p10_build(2561, 5120);

/// Limbs (little-endian) of `10^exp` if `exp` is within a generated POW10
/// band, else `None`. Bands are feature-gated; the always-present NARROW
/// band covers the default / no_std build. `const fn` so a const `exp`
/// folds to the matching entry. The per-exp limbs are rebuilt at compile
/// time ([`p10_build`]), not shipped as literals.
#[inline]
const fn pow10_entry(exp: u32) -> Option<&'static [u64]> {
    if (exp as usize) < 513 {
        return Some(p10_get(&POW10_NARROW, exp as usize));
    }
    #[cfg(feature = "_wide-support")]
    {
        if (exp as usize) < 1281 {
            return Some(p10_get(&POW10_BASE, exp as usize));
        }
    }
    #[cfg(any(feature = "d462", feature = "d616", feature = "d924", feature = "d1232", feature = "x-wide", feature = "xx-wide"))]
    {
        let base_lo = 1280 + 1;
        if exp >= base_lo {
            let idx = (exp - base_lo) as usize;
            if idx < 1280 {
                return Some(p10_get(&POW10_XW, idx));
            }
        }
    }
    #[cfg(any(feature = "d924", feature = "d1232", feature = "xx-wide"))]
    {
        let xw_lo = 2560 + 1;
        if exp >= xw_lo {
            let idx = (exp - xw_lo) as usize;
            if idx < 2560 {
                return Some(p10_get(&POW10_XXW, idx));
            }
        }
    }
    None
}

/// Raw little-endian u64 limbs of `10^exp` from the generated POW10 table,
/// or `None` beyond the (feature-gated) table range. The untyped sibling of
/// [`pow10_in`] — for callers that need the limbs directly in a `[u64]`
/// scratch (e.g. the Newton-reciprocal `precompute`, which otherwise rebuilds
/// `10^scale` with an O(scale²) ×10 chain per call). `const fn` so a const
/// `exp` folds to the entry.
#[inline]
pub(crate) const fn pow10_limbs(exp: u32) -> Option<&'static [u64]> {
    pow10_entry(exp)
}

// `10^exp` in a work integer is the `pow10` POLICY now: `super::pow10::dispatch`
// (table-first, square-and-multiply fallback). The raw-limbs Table primitive is
// `pow10_limbs` above; `limbs_to_w` is the Table-arm zero-extend it uses.

