use crate::util::t;
#[derive(
Clone, Copy, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord,
)]
#[repr(i8)]
pub(crate) enum Sign {
#[default]
Zero = 0,
Positive = 1,
Negative = -1,
}
impl Sign {
pub(crate) fn is_negative(&self) -> bool {
matches!(*self, Sign::Negative)
}
pub(crate) fn as_ranged_integer(&self) -> t::Sign {
match *self {
Sign::Zero => t::Sign::N::<0>(),
Sign::Positive => t::Sign::N::<1>(),
Sign::Negative => t::Sign::N::<-1>(),
}
}
}
impl core::fmt::Display for Sign {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
if self.is_negative() {
write!(f, "-")
} else {
Ok(())
}
}
}