pub mod approx;
pub mod backend;
pub mod filtered;
pub mod intpred;
pub mod predicates;
pub mod rational;
#[cfg(test)]
mod tests;
use backend::{rat_is_negative, rat_is_positive, Rational};
#[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: &Rational) -> Sign {
if rat_is_positive(r) {
Sign::Pos
} else if rat_is_negative(r) {
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
}
}