------------------------------------------------------------------------
r352204 | sammccall | 2019-01-25 16:05:33 +0100 (Fri, 25 Jan 2019) | 7 lines
[JSON] Work around excess-precision issue when comparing T_Integer numbers.
Reviewers: bkramer
Subscribers: kristina, llvm-commits
Differential Revision: https://reviews.llvm.org/D57237
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_80@352233
91177308-0d34-0410-b5e6-
96231b3b80d8
mutable llvm::AlignedCharArrayUnion<bool, double, int64_t, llvm::StringRef,
std::string, json::Array, json::Object>
Union;
+ friend bool operator==(const Value &, const Value &);
};
bool operator==(const Value &, const Value &);
case Value::Boolean:
return *L.getAsBoolean() == *R.getAsBoolean();
case Value::Number:
+ // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
+ // The same integer must convert to the same double, per the standard.
+ // However we see 64-vs-80-bit precision comparisons with gcc-7 -O3 -m32.
+ // So we avoid floating point promotion for exact comparisons.
+ if (L.Type == Value::T_Integer || R.Type == Value::T_Integer)
+ return L.getAsInteger() == R.getAsInteger();
return *L.getAsNumber() == *R.getAsNumber();
case Value::String:
return *L.getAsString() == *R.getAsString();