#[derive(Debug, Clone, PartialEq)]
pub enum Tolerance {
Absolute(f64),
Relative(f64),
AbsOrRel(f64, f64),
AbsAndRel(f64, f64),
}
impl Tolerance {
#[inline]
pub(crate) fn contains_nan(&self) -> bool {
match *self {
Tolerance::Absolute(x) | Tolerance::Relative(x) if x.is_nan() => true,
Tolerance::AbsOrRel(x, y) | Tolerance::AbsAndRel(x, y) if x.is_nan() || y.is_nan() => {
true
}
_ => false,
}
}
#[inline]
pub fn to_abs(&self, value: f64) -> f64 {
match *self {
Tolerance::Absolute(x) => x,
Tolerance::Relative(y) => value * y,
Tolerance::AbsOrRel(x, y) => f64::max(x, value * y),
Tolerance::AbsAndRel(x, y) => f64::min(x, value * y),
}
}
}
impl Default for Tolerance {
#[inline]
fn default() -> Self {
Tolerance::AbsOrRel(1.49e-8, 1.49e-8)
}
}