use crate::types::widths::{D38, D57};
use crate::support::rounding::RoundingMode;
#[inline]
#[must_use]
pub(crate) fn ln_strict<const SCALE: u32>(raw: i128, mode: RoundingMode) -> i128 {
let widened: D57<SCALE> = D38::<SCALE>::from_bits(raw).into();
let raw_wide = super::wide_kernel::ln_strict_d57(widened.0, mode, SCALE);
let wide = D57::<SCALE>::from_bits(raw_wide);
let narrowed: D38<SCALE> = wide.try_into().unwrap_or_else(|_| panic!(
"ln_strict: result out of range — produced {wide}, D38<{SCALE}> represents only |x| < 1.7e{}",
38_i32 - SCALE as i32,
));
narrowed.0
}
#[inline]
#[must_use]
pub(crate) fn log2_strict<const SCALE: u32>(raw: i128, mode: RoundingMode) -> i128 {
let widened: D57<SCALE> = D38::<SCALE>::from_bits(raw).into();
let result = widened.log2_strict_with(mode);
let narrowed: D38<SCALE> = result.try_into().unwrap_or_else(|_| panic!(
"log2_strict: result out of range — produced {result}, D38<{SCALE}> represents only |x| < 1.7e{}",
38_i32 - SCALE as i32,
));
narrowed.0
}
#[inline]
#[must_use]
pub(crate) fn log10_strict<const SCALE: u32>(raw: i128, mode: RoundingMode) -> i128 {
let widened: D57<SCALE> = D38::<SCALE>::from_bits(raw).into();
let result = widened.log10_strict_with(mode);
let narrowed: D38<SCALE> = result.try_into().unwrap_or_else(|_| panic!(
"log10_strict: result out of range — produced {result}, D38<{SCALE}> represents only |x| < 1.7e{}",
38_i32 - SCALE as i32,
));
narrowed.0
}
#[inline]
#[must_use]
pub(crate) fn log_strict<const SCALE: u32>(
raw: i128,
base_raw: i128,
mode: RoundingMode,
) -> i128 {
let widened: D57<SCALE> = D38::<SCALE>::from_bits(raw).into();
let base_wide: D57<SCALE> = D38::<SCALE>::from_bits(base_raw).into();
let result = widened.log_strict_with(base_wide, mode);
let narrowed: D38<SCALE> = result.try_into().unwrap_or_else(|_| panic!(
"log_strict: result out of range — produced {result}, D38<{SCALE}> represents only |x| < 1.7e{}",
38_i32 - SCALE as i32,
));
narrowed.0
}