diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-03-30 15:28:41 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-04-01 23:11:35 +0200 |
commit | 2e044791b8f3c62c32b379f7781799a89165c984 (patch) | |
tree | 36f5dd1bfd2b7f7448dc6216cafc8ed09f239fbd /tests | |
parent | 3a2e3625d1e710795233aff9601ae9219f498edc (diff) |
Move some purely floating-point testing from tst_QLocale to tst_QNumeric
The testing of infinity and NaN somewhat duplicated existing tests in
tst_QNumeric and, in any case, belongs there.
Change-Id: I6b5d1ff9767daf8e4bbe0025d3efab3d74ed35de
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp | 13 | ||||
-rw-r--r-- | tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 24 |
2 files changed, 13 insertions, 24 deletions
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 43b97555de..41d1e6a995 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -179,6 +179,15 @@ void tst_QNumeric::fuzzyIsNull() QCOMPARE(::qFuzzyIsNull(-value), isNull); } +static void clearFpExceptions() +{ + // Call after any functions that exercise floating-point exceptions, such as + // sqrt(-1) or log(0). +#ifdef Q_OS_WIN + _clearfp(); +#endif +} + #if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404) // turn -ffast-math off # pragma GCC optimize "no-fast-math" @@ -187,6 +196,7 @@ void tst_QNumeric::fuzzyIsNull() template<typename F> void tst_QNumeric::checkNaN(F nan) { + const auto cleanup = qScopeGuard([]() { clearFpExceptions(); }); #define CHECKNAN(value) \ do { \ const F v = (value); \ @@ -211,6 +221,7 @@ void tst_QNumeric::checkNaN(F nan) CHECKNAN(one / nan); CHECKNAN(zero / nan); CHECKNAN(zero * nan); + CHECKNAN(sqrt(-one)); // When any NaN is expected, any NaN will do: QCOMPARE(nan, nan); @@ -298,6 +309,7 @@ void tst_QNumeric::generalNaN() template<typename F> void tst_QNumeric::infinity() { + const auto cleanup = qScopeGuard([]() { clearFpExceptions(); }); const F inf = qInf(); const F zero(0), one(1), two(2); QVERIFY(inf > zero); @@ -320,6 +332,7 @@ void tst_QNumeric::infinity() QCOMPARE(one / -inf, zero); QVERIFY(qIsNaN(zero * inf)); QVERIFY(qIsNaN(zero * -inf)); + QCOMPARE(log(zero), -inf); } template<typename F> diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 25a5f416b2..a7eb29d2d1 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -90,7 +90,6 @@ private slots: void long_long_conversion_data(); void long_long_conversion(); void long_long_conversion_extra(); - void testInfAndNan(); void fpExceptions(); void negativeZero_data(); void negativeZero(); @@ -1409,29 +1408,6 @@ void tst_QLocale::long_long_conversion_extra() QCOMPARE(l.toString((qulonglong)12345), QString("12,345")); } -void tst_QLocale::testInfAndNan() -{ - double neginf = log(0.0); - double nan = sqrt(-1.0); - -#ifdef Q_OS_WIN - // these cause INVALID floating point exception so we want to clear the status. - _clear87(); -#endif - - QVERIFY(qIsInf(-neginf)); - QVERIFY(!qIsNaN(-neginf)); - QVERIFY(!qIsFinite(-neginf)); - - QVERIFY(!qIsInf(nan)); - QVERIFY(qIsNaN(nan)); - QVERIFY(!qIsFinite(nan)); - - QVERIFY(!qIsInf(1.234)); - QVERIFY(!qIsNaN(1.234)); - QVERIFY(qIsFinite(1.234)); -} - void tst_QLocale::fpExceptions() { // Check that double-to-string conversion doesn't throw floating point |