macro_rules! decl_decimal_helpers {
(wide $Type:ident) => {
$crate::macros::helpers::decl_decimal_helpers!(@common $Type);
impl<const SCALE: u32> $Type<SCALE> {
#[inline]
#[must_use]
pub fn copysign(self, sign: Self) -> Self {
let mag = self.0.abs();
if sign.0.is_negative() { Self(-mag) } else { Self(mag) }
}
}
};
($Type:ident) => {
$crate::macros::helpers::decl_decimal_helpers!(@common $Type);
impl<const SCALE: u32> $Type<SCALE> {
#[inline]
#[must_use]
pub fn copysign(self, sign: Self) -> Self {
let mag = self.0.abs();
if sign.0 < 0 { Self(-mag) } else { Self(mag) }
}
}
};
(@common $Type:ident) => {
impl<const SCALE: u32> $Type<SCALE> {
#[inline]
#[must_use]
pub fn min(self, other: Self) -> Self {
Self(self.0.min(other.0))
}
#[inline]
#[must_use]
pub fn max(self, other: Self) -> Self {
Self(self.0.max(other.0))
}
#[inline]
#[must_use]
pub fn clamp(self, lo: Self, hi: Self) -> Self {
Self(self.0.clamp(lo.0, hi.0))
}
#[inline]
#[must_use]
pub fn recip(self) -> Self {
Self::ONE / self
}
}
};
}
pub(crate) use decl_decimal_helpers;