Przeglądaj źródła

LibSQL: Use absolute value when comparing against floating point epsilon

Otherwise, any value that is less than another value would be considered
about equal by mistake.
Timothy Flynn 3 lat temu
rodzic
commit
8fab99e920
1 zmienionych plików z 4 dodań i 1 usunięć
  1. 4 1
      Userland/Libraries/LibSQL/Value.cpp

+ 4 - 1
Userland/Libraries/LibSQL/Value.cpp

@@ -773,8 +773,11 @@ int FloatImpl::compare(Value const& other) const
     if (!casted.has_value()) {
     if (!casted.has_value()) {
         return 1;
         return 1;
     }
     }
+
     auto diff = value() - casted.value();
     auto diff = value() - casted.value();
-    return (diff < NumericLimits<double>::epsilon()) ? 0 : ((diff > 0) ? 1 : -1);
+    if (fabs(diff) < NumericLimits<double>::epsilon())
+        return 0;
+    return diff < 0 ? -1 : 1;
 }
 }
 
 
 String BooleanImpl::to_string() const
 String BooleanImpl::to_string() const