update FuzzyEq to explicit self
This commit is contained in:
parent
52975202af
commit
abb79cb52d
1 changed files with 10 additions and 11 deletions
|
@ -18,31 +18,30 @@ use core::float;
|
|||
const fuzzy_epsilon: float = 1.0e-6;
|
||||
|
||||
pub trait FuzzyEq {
|
||||
pure fn fuzzy_eq(other: &self) -> bool;
|
||||
pure fn fuzzy_eq(&self, other: &self) -> bool;
|
||||
}
|
||||
|
||||
impl float: FuzzyEq {
|
||||
pure fn fuzzy_eq(other: &float) -> bool {
|
||||
return float::abs(self - *other) < fuzzy_epsilon;
|
||||
pure fn fuzzy_eq(&self, other: &float) -> bool {
|
||||
float::abs(*self - *other) < fuzzy_epsilon
|
||||
}
|
||||
}
|
||||
|
||||
impl f32: FuzzyEq {
|
||||
pure fn fuzzy_eq(other: &f32) -> bool {
|
||||
return f32::abs(self - *other) < (fuzzy_epsilon as f32);
|
||||
pure fn fuzzy_eq(&self, other: &f32) -> bool {
|
||||
f32::abs(*self - *other) < (fuzzy_epsilon as f32)
|
||||
}
|
||||
}
|
||||
|
||||
impl f64: FuzzyEq {
|
||||
pure fn fuzzy_eq(other: &f64) -> bool {
|
||||
return f64::abs(self - *other) < (fuzzy_epsilon as f64);
|
||||
pure fn fuzzy_eq(&self, other: &f64) -> bool {
|
||||
f64::abs(*self - *other) < (fuzzy_epsilon as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fuzzy_equals() {
|
||||
assert ((&1.0).fuzzy_eq(&1.0));
|
||||
assert ((&1.0f32).fuzzy_eq(&1.0f32));
|
||||
assert ((&1.0f64).fuzzy_eq(&1.0f64));
|
||||
assert (&1.0).fuzzy_eq(&1.0);
|
||||
assert (&1.0f32).fuzzy_eq(&1.0f32);
|
||||
assert (&1.0f64).fuzzy_eq(&1.0f64);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue