diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-11-19 19:05:13 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2018-11-23 10:04:20 +0000 |
commit | 6dcc13d4024ed5fd56610c44140aed72e0248a8e (patch) | |
tree | e3b88d7b98ce1c11552d68ee98a3ed9f65c543f4 /src/testlib/qtestcase.cpp | |
parent | 755521aba6d63fc572b5b3ee43193ea24a2d5513 (diff) |
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>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index f5668c274e..1090428bb0 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -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); } |