use crate::{
error::{panic_infinite, panic_nan, panic_overflow, panic_underflow},
fbig::FBig,
repr::{Context, Repr, Word},
round::{Round, Rounded},
};
pub mod consts;
pub mod trig;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FpResult<const B: Word> {
Normal(Rounded<Repr<B>>),
Overflow,
Underflow,
NaN,
Infinite,
}
impl<const B: Word> FpResult<B> {
#[inline]
#[must_use]
pub fn value<R: Round>(self, context: &Context<R>) -> FBig<R, B> {
match self {
Self::Normal(rounded) => FBig::new(rounded.value(), *context),
Self::NaN => panic_nan(),
Self::Infinite => panic_infinite(),
Self::Overflow => panic_overflow(),
Self::Underflow => panic_underflow(),
}
}
#[inline]
#[must_use]
pub fn ok<R: Round>(self, context: &Context<R>) -> Option<Rounded<FBig<R, B>>> {
match self {
Self::Normal(rounded) => Some(rounded.map(|repr| FBig::new(repr, *context))),
_ => None,
}
}
#[inline]
#[must_use]
pub const fn is_nan(&self) -> bool {
matches!(self, Self::NaN)
}
#[inline]
#[must_use]
pub const fn is_infinite(&self) -> bool {
matches!(self, Self::Infinite)
}
#[inline]
#[must_use]
pub const fn is_normal(&self) -> bool {
matches!(self, Self::Normal(_))
}
#[inline]
#[must_use]
pub const fn is_finite(&self) -> bool {
matches!(self, Self::Normal(_) | Self::Overflow | Self::Underflow)
}
}