pub mod approx;
pub mod filtered;
pub mod intpred;
pub mod predicates;
pub mod rational;
#[cfg(test)]
mod tests;
use num_rational::BigRational;
use num_traits::Signed;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Sign {
Neg,
Zero,
Pos,
}
impl Sign {
#[inline]
pub fn of_f64(v: f64) -> Sign {
if v > 0.0 {
Sign::Pos
} else if v < 0.0 {
Sign::Neg
} else {
Sign::Zero
}
}
#[inline]
pub fn of_rat(r: &BigRational) -> Sign {
if r.is_positive() {
Sign::Pos
} else if r.is_negative() {
Sign::Neg
} else {
Sign::Zero
}
}
#[inline]
pub fn flip(self) -> Sign {
match self {
Sign::Neg => Sign::Pos,
Sign::Zero => Sign::Zero,
Sign::Pos => Sign::Neg,
}
}
#[inline]
pub fn as_i32(self) -> i32 {
match self {
Sign::Neg => -1,
Sign::Zero => 0,
Sign::Pos => 1,
}
}
#[inline]
pub fn is_zero(self) -> bool {
self == Sign::Zero
}
}