Do not allow precision interval to rach < epsilon

This commit is contained in:
Jakub Žádník 2021-09-12 14:55:11 +03:00
parent 2f04c172fe
commit 013b12a864

View File

@ -153,11 +153,11 @@ impl RangeIterator {
} }
// Compare two floating point numbers. The decision interval for equality is dynamically scaled // Compare two floating point numbers. The decision interval for equality is dynamically scaled
// based on the value being compared. // as the value being compared increases in magnitude.
fn compare_floats(val: f64, other: f64) -> Option<Ordering> { fn compare_floats(val: f64, other: f64) -> Option<Ordering> {
let prec = val * f64::EPSILON; let prec = f64::EPSILON.max(val.abs() * f64::EPSILON);
if (other - val).abs() < prec.abs() { if (other - val).abs() < prec {
return Some(Ordering::Equal); return Some(Ordering::Equal);
} }