use half::f16;
pub trait Float {
fn close(&self, other: Self, tolerance: Self) -> bool;
fn epsilon_close(&self, other: Self) -> bool;
}
impl Float for f16 {
fn close(&self, other: Self, tolerance: f16) -> bool {
f16::from_f32((self - other).to_f32().abs()) < tolerance
}
fn epsilon_close(&self, other: Self) -> bool {
self.close(other, f16::EPSILON)
}
}
impl Float for f32 {
fn close(&self, other: Self, tolerance: f32) -> bool {
(self - other).abs() < tolerance
}
fn epsilon_close(&self, other: Self) -> bool {
self.close(other, f32::EPSILON)
}
}
impl Float for f64 {
fn close(&self, other: Self, tolerance: f64) -> bool {
(self - other).abs() < tolerance
}
fn epsilon_close(&self, other: Self) -> bool {
self.close(other, f64::EPSILON)
}
}