macro_rules! decl_decimal_sign_methods {
(wide $Type:ident, $Storage:ty) => {
impl<const SCALE: u32> $Type<SCALE> {
#[inline]
#[must_use]
pub const fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
#[must_use]
pub fn signum(self) -> Self {
if self.0.is_positive() {
Self::ONE
} else if self.0.is_negative() {
Self(-Self::multiplier())
} else {
Self::ZERO
}
}
#[inline]
#[must_use]
pub const fn is_positive(self) -> bool {
self.0.is_positive()
}
#[inline]
#[must_use]
pub const fn is_negative(self) -> bool {
self.0.is_negative()
}
}
};
($Type:ident, $Storage:ty) => {
impl<const SCALE: u32> $Type<SCALE> {
#[inline]
#[must_use]
pub const fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
#[must_use]
pub fn signum(self) -> Self {
match self.0.signum() {
1 => Self::ONE,
-1 => Self(-Self::multiplier()),
_ => Self::ZERO,
}
}
#[inline]
#[must_use]
pub const fn is_positive(self) -> bool {
self.0 > 0
}
#[inline]
#[must_use]
pub const fn is_negative(self) -> bool {
self.0 < 0
}
}
};
}
pub(crate) use decl_decimal_sign_methods;