summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-02-10 17:56:17 -0500
committerLinus Groh <mail@linusgroh.de>2022-02-13 21:30:38 +0000
commit8fab99e920a56cab7b16640e3be74dbb9926d453 (patch)
treea1433a73c0f87e9133cc7c1cb2d8892a2e5b64ca /Userland/Libraries/LibSQL
parente649ff5d31c7fedb88e295f8a21da343187a4116 (diff)
downloadserenity-8fab99e920a56cab7b16640e3be74dbb9926d453.zip
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.
Diffstat (limited to 'Userland/Libraries/LibSQL')
-rw-r--r--Userland/Libraries/LibSQL/Value.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Libraries/LibSQL/Value.cpp b/Userland/Libraries/LibSQL/Value.cpp
index 80ddeea19e..0e1146e10e 100644
--- a/Userland/Libraries/LibSQL/Value.cpp
+++ b/Userland/Libraries/LibSQL/Value.cpp
@@ -773,8 +773,11 @@ int FloatImpl::compare(Value const& other) const
if (!casted.has_value()) {
return 1;
}
+
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