1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Global: Avoid floating-point equality checks where possible

This commit is contained in:
reuk 2023-03-23 12:02:38 +00:00
parent 081b1ff216
commit 28414a6af8
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
150 changed files with 762 additions and 672 deletions

View file

@ -404,7 +404,7 @@ public:
auto endPtr = values.end();
for (; e != endPtr; ++e)
if (elementToLookFor == *e)
if (exactlyEqual (elementToLookFor, *e))
return true;
return false;

View file

@ -123,7 +123,7 @@ public:
auto* e = begin();
for (auto& o : other)
if (! (*e++ == o))
if (! exactlyEqual (*e++, o))
return false;
return true;

View file

@ -201,7 +201,7 @@ struct var::VariantType
static int64 doubleToInt64 (const ValueUnion& data) noexcept { return (int64) data.doubleValue; }
static double doubleToDouble (const ValueUnion& data) noexcept { return data.doubleValue; }
static String doubleToString (const ValueUnion& data) { return serialiseDouble (data.doubleValue); }
static bool doubleToBool (const ValueUnion& data) noexcept { return data.doubleValue != 0.0; }
static bool doubleToBool (const ValueUnion& data) noexcept { return ! exactlyEqual (data.doubleValue, 0.0); }
static bool doubleEquals (const ValueUnion& data, const ValueUnion& otherData, const VariantType& otherType) noexcept
{
@ -645,7 +645,7 @@ static int compare (const var& v1, const var& v2)
return v1.toString().compare (v2.toString());
auto diff = static_cast<double> (v1) - static_cast<double> (v2);
return diff == 0 ? 0 : (diff < 0 ? -1 : 1);
return exactlyEqual (diff, 0.0) ? 0 : (diff < 0 ? -1 : 1);
}
bool operator== (const var& v1, const var& v2) { return v1.equals (v2); }