diff options
-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 |