mod rounding_mode;
mod signal_traps;
pub use rounding_mode::RoundingMode;
pub use signal_traps::SignalsTraps;
use core::fmt::{Debug, Display, Formatter};
use crate::utils::assert_eq_size;
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
#[repr(C)]
pub struct Context {
rounding_mode: RoundingMode,
signal_traps: SignalsTraps,
}
impl Context {
const DEFAULT: Self = Self {
rounding_mode: RoundingMode::default(),
signal_traps: SignalsTraps::default(),
};
#[inline(always)]
#[must_use]
pub const fn default() -> Self {
Self::DEFAULT
}
#[must_use]
#[inline(always)]
pub const fn with_rounding_mode(mut self, rm: RoundingMode) -> Self {
self.rounding_mode = rm;
self
}
#[inline(always)]
#[must_use]
pub const fn without_traps(mut self) -> Self {
self.signal_traps = SignalsTraps::empty();
self
}
#[must_use]
#[inline(always)]
pub const fn with_signal_traps(mut self, traps: SignalsTraps) -> Self {
self.signal_traps = traps;
self
}
#[must_use]
#[inline(always)]
pub const fn rounding_mode(&self) -> RoundingMode {
self.rounding_mode
}
#[must_use]
#[inline(always)]
pub const fn signal_traps(&self) -> SignalsTraps {
self.signal_traps
}
#[inline(always)]
pub(crate) const fn new(rounding_mode: RoundingMode, signal_traps: SignalsTraps) -> Self {
Self {
rounding_mode,
signal_traps,
}
}
#[inline(always)]
pub(crate) const fn merge(mut self, other: Self) -> Self {
self.signal_traps = self.signal_traps.merge(other.signal_traps);
if !other.rounding_mode.is_default() {
self.rounding_mode = other.rounding_mode;
}
self
}
}
impl Display for Context {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "R={}, S={}", self.rounding_mode, self.signal_traps)
}
}
impl Debug for Context {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self)
}
}
assert_eq_size!(Context, u16);