use std::ops::{Mul, Neg};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Sign {
Negative,
Zero,
Positive,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum BitSign {
Negative,
Positive,
}
impl Neg for Sign {
type Output = Self;
fn neg(self) -> Self::Output {
match self {
Self::Negative => Self::Positive,
Self::Zero => Self::Zero,
Self::Positive => Self::Negative,
}
}
}
impl Mul for Sign {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output {
match (self, rhs) {
(Self::Zero, _) => Self::Zero,
(_, Self::Zero) => Self::Zero,
(Self::Positive, rhs) => rhs,
(lhs, Self::Positive) => lhs,
(Self::Negative, Self::Negative) => Self::Positive,
}
}
}
impl Neg for BitSign {
type Output = Self;
fn neg(self) -> Self::Output {
match self {
Self::Negative => Self::Positive,
Self::Positive => Self::Negative,
}
}
}
impl Mul for BitSign {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output {
match (self, rhs) {
(Self::Positive, rhs) => rhs,
(lhs, Self::Positive) => lhs,
(Self::Negative, Self::Negative) => Self::Positive,
}
}
}