summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-03-30 15:28:41 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-04-01 23:11:35 +0200
commit2e044791b8f3c62c32b379f7781799a89165c984 (patch)
tree36f5dd1bfd2b7f7448dc6216cafc8ed09f239fbd /tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
parent3a2e3625d1e710795233aff9601ae9219f498edc (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/auto/corelib/global/qnumeric/tst_qnumeric.cpp')
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp13
1 files changed, 13 insertions, 0 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>