use crate::int::types::compute_limbs::{ComputeLimbs, Limbs};
use crate::int::types::Int;
use crate::support::rounding::{RoundingMode, DEFAULT_ROUNDING_MODE};
#[allow(private_bounds)]
impl<const N: usize, const SCALE: u32> crate::D<Int<N>, SCALE> {
#[inline]
fn unit_bits() -> Int<N> {
const { Int::<N>::TEN.pow(SCALE) }
}
#[inline]
#[must_use]
pub fn checked_ln_strict_with(self, mode: RoundingMode) -> Option<Self> {
if self.0 <= Int::<N>::ZERO {
return None;
}
crate::policy::ln::checked_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_ln_strict(self) -> Option<Self> {
self.checked_ln_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_log_strict_with(self, base: Self, mode: RoundingMode) -> Option<Self> {
if self.0 <= Int::<N>::ZERO
|| base.0 <= Int::<N>::ZERO
|| base.0 == Self::unit_bits()
{
return None;
}
crate::policy::log::checked_dispatch::<N, SCALE>(self.0, base.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_log_strict(self, base: Self) -> Option<Self> {
self.checked_log_strict_with(base, DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_log2_strict_with(self, mode: RoundingMode) -> Option<Self> {
if self.0 <= Int::<N>::ZERO {
return None;
}
crate::policy::ln::checked_log2_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_log2_strict(self) -> Option<Self> {
self.checked_log2_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_log10_strict_with(self, mode: RoundingMode) -> Option<Self> {
if self.0 <= Int::<N>::ZERO {
return None;
}
crate::policy::ln::checked_log10_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_log10_strict(self) -> Option<Self> {
self.checked_log10_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_exp_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::exp::checked_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_exp_strict(self) -> Option<Self> {
self.checked_exp_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_exp2_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::exp::checked_exp2_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_exp2_strict(self) -> Option<Self> {
self.checked_exp2_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_powf_strict_with(self, exp: Self, mode: RoundingMode) -> Option<Self> {
crate::policy::pow::checked_dispatch::<N, SCALE>(self.0, exp.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_powf_strict(self, exp: Self) -> Option<Self> {
self.checked_powf_strict_with(exp, DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_sqrt_strict_with(self, mode: RoundingMode) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
Some(Self(crate::policy::sqrt::dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_sqrt_strict(self) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
self.checked_sqrt_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_cbrt_strict_with(self, mode: RoundingMode) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
Some(Self(crate::policy::cbrt::dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_cbrt_strict(self) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
self.checked_cbrt_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_hypot_strict_with(self, other: Self, mode: RoundingMode) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
crate::policy::hypot::checked_dispatch::<N, SCALE>(self.0, other.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_hypot_strict(self, other: Self) -> Option<Self>
where
Limbs<N>: ComputeLimbs,
{
self.checked_hypot_strict_with(other, DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_sin_strict_with(self, mode: RoundingMode) -> Option<Self> {
Some(Self(crate::policy::trig::sin_dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_sin_strict(self) -> Option<Self> {
self.checked_sin_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_cos_strict_with(self, mode: RoundingMode) -> Option<Self> {
Some(Self(crate::policy::trig::cos_dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_cos_strict(self) -> Option<Self> {
self.checked_cos_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_tan_strict_with(self, mode: RoundingMode) -> Option<Self> {
Some(Self(crate::policy::trig::tan_dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_tan_strict(self) -> Option<Self> {
self.checked_tan_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_asin_strict_with(self, mode: RoundingMode) -> Option<Self> {
let one = Self::unit_bits();
if self.0 > one || self.0 < -one {
return None;
}
crate::policy::trig::checked_asin_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_asin_strict(self) -> Option<Self> {
self.checked_asin_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_acos_strict_with(self, mode: RoundingMode) -> Option<Self> {
let one = Self::unit_bits();
if self.0 > one || self.0 < -one {
return None;
}
crate::policy::trig::checked_acos_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_acos_strict(self) -> Option<Self> {
self.checked_acos_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_atan_strict_with(self, mode: RoundingMode) -> Option<Self> {
Some(Self(crate::policy::trig::atan_dispatch::<N, SCALE>(self.0, mode)))
}
#[inline]
#[must_use]
pub fn checked_atan_strict(self) -> Option<Self> {
self.checked_atan_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_atan2_strict_with(self, other: Self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_atan2_dispatch::<N, SCALE>(self.0, other.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_atan2_strict(self, other: Self) -> Option<Self> {
self.checked_atan2_strict_with(other, DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_sinh_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_sinh_dispatch::<N, SCALE>(self.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_sinh_strict(self) -> Option<Self> {
self.checked_sinh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_cosh_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_cosh_dispatch::<N, SCALE>(self.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_cosh_strict(self) -> Option<Self> {
self.checked_cosh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_tanh_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_tanh_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_tanh_strict(self) -> Option<Self> {
self.checked_tanh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_asinh_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_asinh_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_asinh_strict(self) -> Option<Self> {
self.checked_asinh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_acosh_strict_with(self, mode: RoundingMode) -> Option<Self> {
if self.0 < Self::unit_bits() {
return None;
}
crate::policy::trig::checked_acosh_dispatch::<N, SCALE>(self.0, mode).map(Self)
}
#[inline]
#[must_use]
pub fn checked_acosh_strict(self) -> Option<Self> {
self.checked_acosh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_atanh_strict_with(self, mode: RoundingMode) -> Option<Self> {
let one = Self::unit_bits();
if self.0 >= one || self.0 <= -one {
return None;
}
crate::policy::trig::checked_atanh_dispatch::<N, SCALE>(self.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_atanh_strict(self) -> Option<Self> {
self.checked_atanh_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_to_degrees_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_to_degrees_dispatch::<N, SCALE>(self.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_to_degrees_strict(self) -> Option<Self> {
self.checked_to_degrees_strict_with(DEFAULT_ROUNDING_MODE)
}
#[inline]
#[must_use]
pub fn checked_to_radians_strict_with(self, mode: RoundingMode) -> Option<Self> {
crate::policy::trig::checked_to_radians_dispatch::<N, SCALE>(self.0, mode)
.map(Self)
}
#[inline]
#[must_use]
pub fn checked_to_radians_strict(self) -> Option<Self> {
self.checked_to_radians_strict_with(DEFAULT_ROUNDING_MODE)
}
}