From 013b12a86451556903ea1866010864d234afdbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 12 Sep 2021 14:55:11 +0300 Subject: [PATCH] Do not allow precision interval to rach < epsilon --- crates/nu-protocol/src/value/range.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/nu-protocol/src/value/range.rs b/crates/nu-protocol/src/value/range.rs index 2832d09b2b..44a97d7b59 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); }