Skip to content

Commit

Permalink
LibSQL: Use absolute value when comparing against floating point epsilon
Browse files Browse the repository at this point in the history
Otherwise, any value that is less than another value would be considered
about equal by mistake.
  • Loading branch information
trflynn89 authored and linusg committed Feb 13, 2022
1 parent e649ff5 commit 8fab99e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Userland/Libraries/LibSQL/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8fab99e

Please sign in to comment.