Make QCOMPARE()'s handling of non-finite float match double

The qCompare() implementation for double was handling infinities and
NaN the way tests need, but the one for float didn't; it has just the
same need, so apply the same fix.  Extends 79493a3ee1.

Change-Id: I8425026acb61d535e449f579b77fdcd609157f7c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2018-11-19 19:05:13 +01:00
parent 755521aba6
commit 6dcc13d402

View File

@ -2437,7 +2437,16 @@ bool QTest::compare_helper(bool success, const char *failureMsg,
bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected,
const char *file, int line)
{
return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)",
bool equal = false;
int cl1 = std::fpclassify(t1);
int cl2 = std::fpclassify(t2);
if (cl1 == FP_INFINITE)
equal = ((t1 < 0) == (t2 < 0)) && cl2 == FP_INFINITE;
else if (cl1 == FP_NAN)
equal = (cl2 == FP_NAN);
else
equal = qFuzzyCompare(t1, t2);
return compare_helper(equal, "Compared floats are not the same (fuzzy compare)",
toString(t1), toString(t2), actual, expected, file, line);
}