diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2019-09-23 16:46:07 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-10-03 16:30:40 +0200 |
commit | d448f2ecb8bca7de1e69f9f6f10d0ffb8c3d1beb (patch) | |
tree | 76b45bb1213c81eccc2b3d536911dd9de91dccec /tests/auto/corelib/global/qfloat16 | |
parent | a978d21dac57697ae9557b99062bc804b005b9d4 (diff) |
Correct handling of -qfloat16(0)
It is finite and normal; it classifies as a zero; and it should not be > qfloat16(0).
Added tests to match.
Change-Id: I7874fb54f622b4cdf28b0894050ad3e75cf5d77c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/global/qfloat16')
-rw-r--r-- | tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 01a1789188..94f0afa5ed 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -107,6 +107,7 @@ void tst_qfloat16::ltgt_data() QTest::addColumn<float>("val2"); QTest::newRow("zero") << 0.0f << 0.0f; + QTest::newRow("-zero") << -0.0f << 0.0f; QTest::newRow("ten") << 10.0f << 10.0f; QTest::newRow("large") << 100000.0f << 100000.0f; QTest::newRow("small") << 0.0000001f << 0.0000001f; @@ -405,6 +406,7 @@ void tst_qfloat16::finite_data() QTest::addColumn<int>("mode"); QTest::newRow("zero") << qfloat16(0) << FP_ZERO; + QTest::newRow("-zero") << -qfloat16(0) << FP_ZERO; QTest::newRow("one") << qfloat16(1) << FP_NORMAL; QTest::newRow("-one") << qfloat16(-1) << FP_NORMAL; QTest::newRow("ten") << qfloat16(10) << FP_NORMAL; @@ -459,6 +461,12 @@ void tst_qfloat16::limits() // See also: qNaN() and infinity() // A few useful values: const qfloat16 zero(0), one(1), ten(10); + // The specifics of minus zero: + // (IEEE 754 seems to want -zero < zero, but -0. == 0. and -0.f == 0.f in C++.) + QVERIFY(-zero <= zero); + QVERIFY(-zero == zero); + QVERIFY(!(-zero > zero)); + // digits in the mantissa, including the implicit 1 before the binary dot at its left: QVERIFY(qfloat16(1 << (Bounds::digits - 1)) + one > qfloat16(1 << (Bounds::digits - 1))); QVERIFY(qfloat16(1 << Bounds::digits) + one == qfloat16(1 << Bounds::digits)); @@ -523,7 +531,10 @@ void tst_qfloat16::limits() // See also: qNaN() and infinity() QVERIFY(Bounds::denorm_min() > zero); if (overOptimized) QEXPECT_FAIL("", "Over-optimized on ARM", Continue); - QCOMPARE(Bounds::denorm_min() / rose, zero); + QVERIFY(Bounds::denorm_min() / rose == zero); + if (overOptimized) + QEXPECT_FAIL("", "Over-optimized on ARM", Continue); + QVERIFY(-Bounds::denorm_min() / rose == -zero); } QTEST_APPLESS_MAIN(tst_qfloat16) |