diff --git a/crates/nu-protocol/src/value/range.rs b/crates/nu-protocol/src/value/range.rs index 2832d09b2..44a97d7b5 100644 --- a/crates/nu-protocol/src/value/range.rs +++ b/crates/nu-protocol/src/value/range.rs @@ -153,11 +153,11 @@ impl RangeIterator { } // 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 { - 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); }