summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-04-15 18:31:51 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-04-29 14:13:23 +0200
commit6dfec83051c3426fcf2336f8b7acfdc290efe94c (patch)
treeb6b9ab31164a48035024df1b01d498de20887003 /tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
parent16c96837182056a1a755e420289dce8a57341c6c (diff)
Add tests for qFuzzyIsNull() to tst_QNumeric and tst_QFloat16
They were missing. I also wanted to verify that it's true for sub-normal values. At the same time, relocate qfloat16's implementation of qFuzzyIsNull() to between those of qFuzzyCompare() and qIsNull(), since its apparent absence initially confused me. Change-Id: I9637c0070e754d16744c76fc9f846596257c6a63 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp')
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
index 0cfb8541ab..5b54eeae01 100644
--- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
+++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -52,6 +52,8 @@ class tst_QNumeric: public QObject
// Support for floating-point:
template<typename F> inline void fuzzyCompare_data();
template<typename F> inline void fuzzyCompare();
+ template<typename F> inline void fuzzyIsNull_data();
+ template<typename F> inline void fuzzyIsNull();
template<typename F> inline void checkNaN(F nan);
template<typename F> inline void rawNaN_data();
template<typename F> inline void rawNaN();
@@ -71,6 +73,10 @@ private slots:
void fuzzyCompareF() { fuzzyCompare<float>(); }
void fuzzyCompareD_data() { fuzzyCompare_data<double>(); }
void fuzzyCompareD() { fuzzyCompare<double>(); }
+ void fuzzyIsNullF_data() { fuzzyIsNull_data<float>(); }
+ void fuzzyIsNullF() { fuzzyIsNull<float>(); }
+ void fuzzyIsNullD_data() { fuzzyIsNull_data<double>(); }
+ void fuzzyIsNullD() { fuzzyIsNull<double>(); }
void rawNaNF_data() { rawNaN_data<float>(); }
void rawNaNF() { rawNaN<float>(); }
void rawNaND_data() { rawNaN_data<double>(); }
@@ -143,6 +149,36 @@ void tst_QNumeric::fuzzyCompare()
QCOMPARE(::qFuzzyCompare(-val2, -val1), isEqual);
}
+template<typename F>
+void tst_QNumeric::fuzzyIsNull_data()
+{
+ QTest::addColumn<F>("value");
+ QTest::addColumn<bool>("isNull");
+ using Bounds = std::numeric_limits<F>;
+ const F one(1), huge = Fuzzy<F>::scale, tiny = one / huge;
+
+ QTest::newRow("zero") << F(0) << true;
+ QTest::newRow("min") << Bounds::min() << true;
+ QTest::newRow("denorm_min") << Bounds::denorm_min() << true;
+ QTest::newRow("tiny") << tiny << true;
+
+ QTest::newRow("deci") << F(.1) << false;
+ QTest::newRow("one") << one << false;
+ QTest::newRow("ten") << F(10) << false;
+ QTest::newRow("large") << F(1e9) << false;
+ QTest::newRow("huge") << huge << false;
+}
+
+template<typename F>
+void tst_QNumeric::fuzzyIsNull()
+{
+ QFETCH(F, value);
+ QFETCH(bool, isNull);
+
+ QCOMPARE(::qFuzzyIsNull(value), isNull);
+ QCOMPARE(::qFuzzyIsNull(-value), isNull);
+}
+
#if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)
// turn -ffast-math off
# pragma GCC optimize "no-fast-math"