use crate::int::types::traits::BigInt;
use crate::int::types::Int;
use crate::support::rounding::RoundingMode;
#[cfg(feature = "_wide-support")]
use crate::algos::support::wide_trig_core::WideTrigCore;
#[derive(Clone, Copy, PartialEq, Eq)]
enum Algorithm {
Series,
#[cfg(feature = "_wide-support")]
Tang,
#[allow(dead_code)]
Schoolbook,
}
#[derive(Clone, Copy)]
enum Select<const N: usize> {
ByAlgorithm(Algorithm),
#[allow(dead_code)]
ByValue(fn(&Int<N>) -> Algorithm),
}
const fn select<const N: usize, const SCALE: u32>() -> Select<N> {
match (N, SCALE) {
#[cfg(any(feature = "d57", feature = "wide"))]
(3, 0..=56) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d76", feature = "wide"))]
(4, 0..=75) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d115", feature = "wide"))]
(6, 0..=114) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d153", feature = "wide"))]
(8, 0..=152) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d230", feature = "wide"))]
(12, 0..=229) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
(16, 0..=306) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d462", feature = "x-wide"))]
(24, 0..=461) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d616", feature = "x-wide"))]
(32, 0..=615) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
(48, 0..=923) => Select::ByAlgorithm(Algorithm::Tang),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
(64, 0..=1231) => Select::ByAlgorithm(Algorithm::Tang),
_ => Select::ByAlgorithm(Algorithm::Series),
}
}
#[inline]
fn resolve<const N: usize, const SCALE: u32>(raw: &Int<N>) -> Algorithm {
match const { select::<N, SCALE>() } {
Select::ByAlgorithm(a) => a,
Select::ByValue(f) => f(raw),
}
}
#[cfg(feature = "_wide-support")]
#[inline]
#[must_use]
pub(crate) const fn is_tang<const N: usize, const SCALE: u32>() -> bool {
matches!(select::<N, SCALE>(), Select::ByAlgorithm(Algorithm::Tang))
}
#[inline]
#[must_use]
pub(crate) fn dispatch<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Int<N> {
checked_dispatch::<N, SCALE>(raw, mode).unwrap_or_else(|| {
crate::support::diagnostics::overflow_panic_with_scale("ln_strict", SCALE)
})
}
#[inline]
#[must_use]
pub(crate) fn checked_dispatch<const N: usize, const SCALE: u32>(
raw: Int<N>,
mode: RoundingMode,
) -> Option<Int<N>> {
match resolve::<N, SCALE>(&raw) {
Algorithm::Series => series_routed::<N, SCALE>(raw, mode),
#[cfg(feature = "_wide-support")]
Algorithm::Tang => tang_routed::<N, SCALE>(raw, mode),
Algorithm::Schoolbook => schoolbook_routed::<N, SCALE>(raw, mode),
}
}
#[inline]
#[must_use]
pub(crate) fn dispatch_with<const N: usize, const SCALE: u32>(
raw: Int<N>,
working_digits: u32,
mode: RoundingMode,
) -> Int<N> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::ln_with(
raw.resize_to::<Int<2>>(),
SCALE,
working_digits,
mode,
)
.and_then(super::narrow_fit::<N>)
.unwrap_or_else(|| {
crate::support::diagnostics::overflow_panic_with_scale("ln_with", SCALE)
}),
_ => {
let _ = working_digits;
dispatch::<N, SCALE>(raw, mode)
}
}
}
#[inline]
fn series_routed<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Option<Int<N>> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::ln_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d57::Core, SCALE>(raw.resize_to::<Int<3>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d76::Core, SCALE>(raw.resize_to::<Int<4>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d115::Core, SCALE>(raw.resize_to::<Int<6>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d153::Core, SCALE>(raw.resize_to::<Int<8>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d230::Core, SCALE>(raw.resize_to::<Int<12>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d307::Core, SCALE>(raw.resize_to::<Int<16>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d462::Core, SCALE>(raw.resize_to::<Int<24>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d616::Core, SCALE>(raw.resize_to::<Int<32>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d924::Core, SCALE>(raw.resize_to::<Int<48>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => Some(crate::algos::support::wide_trig_core::ln_series::<crate::types::widths::wide_trig_d1232::Core, SCALE>(raw.resize_to::<Int<64>>(), mode).resize_to::<Int<N>>()),
_ => crate::algos::ln::ln_series_2limb::ln_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
}
}
#[inline]
fn schoolbook_routed<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Option<Int<N>> {
match N {
1 | 2 => super::narrow_fit::<N>(crate::algos::ln::ln_schoolbook::ln_schoolbook_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode)),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d57::Core, SCALE>(raw.resize_to::<Int<3>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d76::Core, SCALE>(raw.resize_to::<Int<4>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d115::Core, SCALE>(raw.resize_to::<Int<6>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d153::Core, SCALE>(raw.resize_to::<Int<8>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d230::Core, SCALE>(raw.resize_to::<Int<12>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d307::Core, SCALE>(raw.resize_to::<Int<16>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d462::Core, SCALE>(raw.resize_to::<Int<24>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d616::Core, SCALE>(raw.resize_to::<Int<32>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d924::Core, SCALE>(raw.resize_to::<Int<48>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => Some(crate::algos::ln::ln_schoolbook::ln_schoolbook::<crate::types::widths::wide_trig_d1232::Core, SCALE>(raw.resize_to::<Int<64>>(), mode).resize_to::<Int<N>>()),
_ => super::narrow_fit::<N>(crate::algos::ln::ln_schoolbook::ln_schoolbook_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode)),
}
}
#[cfg(feature = "_wide-support")]
use super::work_rung::{ln_rung, Rung};
#[cfg(feature = "_wide-support")]
#[inline]
fn tang_at_rung<
C: WideTrigCore,
const SCALE: u32,
const G: u32,
const CAP: u128,
const DIR: bool,
const IE: bool,
>(
raw: C::Storage,
mode: RoundingMode,
) -> C::Storage
where
<C::W as BigInt>::Scratch: crate::int::types::compute_limbs::ComputeLimbs,
{
use crate::algos::ln::ln_tang::ln_tang_g;
match const { ln_rung::<C, SCALE>() } {
Rung::W3 => ln_tang_g::<C, Int<3>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W4 => ln_tang_g::<C, Int<4>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W6 => ln_tang_g::<C, Int<6>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W8 => ln_tang_g::<C, Int<8>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W12 => ln_tang_g::<C, Int<12>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W16 => ln_tang_g::<C, Int<16>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W24 => ln_tang_g::<C, Int<24>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W32 => ln_tang_g::<C, Int<32>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W48 => ln_tang_g::<C, Int<48>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W64 => ln_tang_g::<C, Int<64>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W96 => ln_tang_g::<C, Int<96>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W128 => ln_tang_g::<C, Int<128>, SCALE, G, CAP, DIR, IE>(raw, mode),
Rung::W176 => ln_tang_g::<C, Int<176>, SCALE, G, CAP, DIR, IE>(raw, mode),
}
}
#[cfg(feature = "_wide-support")]
#[inline]
fn tang_routed<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Option<Int<N>> {
match N {
#[cfg(any(feature = "d57", feature = "wide"))]
3 => Some(tang_at_rung::<crate::types::widths::wide_trig_d57::Core, SCALE, 8, 100, true, false>(raw.resize_to::<Int<3>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => Some(tang_at_rung::<crate::types::widths::wide_trig_d76::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<4>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => Some(tang_at_rung::<crate::types::widths::wide_trig_d115::Core, SCALE, 8, 200, true, false>(raw.resize_to::<Int<6>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => Some(tang_at_rung::<crate::types::widths::wide_trig_d153::Core, SCALE, 10, 200, true, false>(raw.resize_to::<Int<8>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => Some(tang_at_rung::<crate::types::widths::wide_trig_d230::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<12>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => Some(tang_at_rung::<crate::types::widths::wide_trig_d307::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<16>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => Some(tang_at_rung::<crate::types::widths::wide_trig_d462::Core, SCALE, 10, 400, true, true>(raw.resize_to::<Int<24>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => Some(tang_at_rung::<crate::types::widths::wide_trig_d616::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<32>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => Some(tang_at_rung::<crate::types::widths::wide_trig_d924::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<48>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => Some(tang_at_rung::<crate::types::widths::wide_trig_d1232::Core, SCALE, 10, 400, true, false>(raw.resize_to::<Int<64>>(), mode).resize_to::<Int<N>>()),
_ => series_routed::<N, SCALE>(raw, mode),
}
}
#[inline]
#[must_use]
pub(crate) fn log2_dispatch<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Int<N> {
checked_log2_dispatch::<N, SCALE>(raw, mode).unwrap_or_else(|| {
crate::support::diagnostics::overflow_panic_with_scale("log2_strict", SCALE)
})
}
#[inline]
#[must_use]
pub(crate) fn checked_log2_dispatch<const N: usize, const SCALE: u32>(
raw: Int<N>,
mode: RoundingMode,
) -> Option<Int<N>> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::log2_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => Some(crate::types::widths::wide_trig_d57::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<3>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => Some(crate::types::widths::wide_trig_d76::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<4>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => Some(crate::types::widths::wide_trig_d115::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<6>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => Some(crate::types::widths::wide_trig_d153::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<8>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => Some(crate::types::widths::wide_trig_d230::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<12>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => Some(crate::types::widths::wide_trig_d307::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<16>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => Some(crate::types::widths::wide_trig_d462::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<24>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => Some(crate::types::widths::wide_trig_d616::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<32>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => Some(crate::types::widths::wide_trig_d924::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<48>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => Some(crate::types::widths::wide_trig_d1232::log2_strict_with_kernel::<SCALE>(raw.resize_to::<Int<64>>(), mode).resize_to::<Int<N>>()),
_ => crate::algos::ln::ln_series_2limb::log2_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
}
}
#[inline]
#[must_use]
pub(crate) fn log2_dispatch_with<const N: usize, const SCALE: u32>(raw: Int<N>, working_digits: u32, mode: RoundingMode) -> Int<N> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::log2_with(raw.resize_to::<Int<2>>(), SCALE, working_digits, mode).and_then(super::narrow_fit::<N>).unwrap_or_else(|| crate::support::diagnostics::overflow_panic_with_scale("log2_with", SCALE)),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => crate::types::widths::wide_trig_d57::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<3>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => crate::types::widths::wide_trig_d76::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<4>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => crate::types::widths::wide_trig_d115::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<6>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => crate::types::widths::wide_trig_d153::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<8>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => crate::types::widths::wide_trig_d230::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<12>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => crate::types::widths::wide_trig_d307::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<16>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => crate::types::widths::wide_trig_d462::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<24>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => crate::types::widths::wide_trig_d616::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<32>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => crate::types::widths::wide_trig_d924::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<48>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => crate::types::widths::wide_trig_d1232::log2_approx_with_kernel::<SCALE>(raw.resize_to::<Int<64>>(), working_digits, mode).resize_to::<Int<N>>(),
_ => crate::algos::ln::ln_series_2limb::log2_with(raw.resize_to::<Int<2>>(), SCALE, working_digits, mode).and_then(super::narrow_fit::<N>).unwrap_or_else(|| crate::support::diagnostics::overflow_panic_with_scale("log2_with", SCALE)),
}
}
#[inline]
#[must_use]
pub(crate) fn log10_dispatch<const N: usize, const SCALE: u32>(raw: Int<N>, mode: RoundingMode) -> Int<N> {
checked_log10_dispatch::<N, SCALE>(raw, mode).unwrap_or_else(|| {
crate::support::diagnostics::overflow_panic_with_scale("log10_strict", SCALE)
})
}
#[inline]
#[must_use]
pub(crate) fn checked_log10_dispatch<const N: usize, const SCALE: u32>(
raw: Int<N>,
mode: RoundingMode,
) -> Option<Int<N>> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::log10_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => Some(crate::types::widths::wide_trig_d57::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<3>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => Some(crate::types::widths::wide_trig_d76::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<4>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => Some(crate::types::widths::wide_trig_d115::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<6>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => Some(crate::types::widths::wide_trig_d153::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<8>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => Some(crate::types::widths::wide_trig_d230::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<12>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => Some(crate::types::widths::wide_trig_d307::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<16>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => Some(crate::types::widths::wide_trig_d462::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<24>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => Some(crate::types::widths::wide_trig_d616::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<32>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => Some(crate::types::widths::wide_trig_d924::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<48>>(), mode).resize_to::<Int<N>>()),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => Some(crate::types::widths::wide_trig_d1232::log10_strict_with_kernel::<SCALE>(raw.resize_to::<Int<64>>(), mode).resize_to::<Int<N>>()),
_ => crate::algos::ln::ln_series_2limb::log10_strict::<SCALE>(raw.resize_to::<Int<2>>(), mode).and_then(super::narrow_fit::<N>),
}
}
#[inline]
#[must_use]
pub(crate) fn log10_dispatch_with<const N: usize, const SCALE: u32>(raw: Int<N>, working_digits: u32, mode: RoundingMode) -> Int<N> {
match N {
1 | 2 => crate::algos::ln::ln_series_2limb::log10_with(raw.resize_to::<Int<2>>(), SCALE, working_digits, mode).and_then(super::narrow_fit::<N>).unwrap_or_else(|| crate::support::diagnostics::overflow_panic_with_scale("log10_with", SCALE)),
#[cfg(any(feature = "d57", feature = "wide"))]
3 => crate::types::widths::wide_trig_d57::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<3>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d76", feature = "wide"))]
4 => crate::types::widths::wide_trig_d76::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<4>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d115", feature = "wide"))]
6 => crate::types::widths::wide_trig_d115::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<6>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d153", feature = "wide"))]
8 => crate::types::widths::wide_trig_d153::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<8>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d230", feature = "wide"))]
12 => crate::types::widths::wide_trig_d230::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<12>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d307", feature = "wide", feature = "x-wide"))]
16 => crate::types::widths::wide_trig_d307::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<16>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d462", feature = "x-wide"))]
24 => crate::types::widths::wide_trig_d462::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<24>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d616", feature = "x-wide"))]
32 => crate::types::widths::wide_trig_d616::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<32>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d924", feature = "xx-wide"))]
48 => crate::types::widths::wide_trig_d924::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<48>>(), working_digits, mode).resize_to::<Int<N>>(),
#[cfg(any(feature = "d1232", feature = "xx-wide"))]
64 => crate::types::widths::wide_trig_d1232::log10_approx_with_kernel::<SCALE>(raw.resize_to::<Int<64>>(), working_digits, mode).resize_to::<Int<N>>(),
_ => crate::algos::ln::ln_series_2limb::log10_with(raw.resize_to::<Int<2>>(), SCALE, working_digits, mode).and_then(super::narrow_fit::<N>).unwrap_or_else(|| crate::support::diagnostics::overflow_panic_with_scale("log10_with", SCALE)),
}
}
#[cfg(test)]
mod tang_rung_tests {
#[cfg(feature = "d307")]
const ALL_MODES: [crate::support::rounding::RoundingMode; 6] = [
crate::support::rounding::RoundingMode::HalfToEven,
crate::support::rounding::RoundingMode::HalfAwayFromZero,
crate::support::rounding::RoundingMode::HalfTowardZero,
crate::support::rounding::RoundingMode::Trunc,
crate::support::rounding::RoundingMode::Floor,
crate::support::rounding::RoundingMode::Ceiling,
];
#[test]
#[cfg(feature = "d307")]
fn d307_s153_tang_rung_matches_tier() {
type Core = crate::types::widths::wide_trig_d307::Core;
let one = crate::int::types::Int::<16>::from_i128(10i128).pow(153);
let tiny = crate::int::types::Int::<16>::from_i128(3 * 10i128.pow(35));
let half = one / crate::int::types::Int::<16>::from_i128(2); let raws = [one + tiny, one - tiny, one + one, half];
for raw in raws {
for mode in ALL_MODES {
assert_eq!(
super::tang_at_rung::<Core, 153, 10, 400, true, false>(raw, mode),
crate::algos::ln::ln_tang::ln_tang::<Core, 153, 10, 400, true, false>(raw, mode),
"ln raw={raw:?} mode {mode:?}"
);
}
}
}
}