diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index b0272c51c3..054d503249 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -62,8 +62,6 @@ public: Q_DECL_CONSTEXPR inline qfloat16() Q_DECL_NOTHROW : b16(0) { } inline qfloat16(float f) Q_DECL_NOTHROW; inline operator float() const Q_DECL_NOTHROW; - inline operator double() const Q_DECL_NOTHROW; - inline operator long double() const Q_DECL_NOTHROW; #endif private: @@ -153,16 +151,6 @@ inline qfloat16::operator float() const Q_DECL_NOTHROW #endif } -inline qfloat16::operator double() const Q_DECL_NOTHROW -{ - return static_cast(float(*this)); -} - -inline qfloat16::operator long double() const Q_DECL_NOTHROW -{ - return static_cast(float(*this)); -} - inline qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW { qfloat16 f; diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 3ec863302e..9bd87e3f21 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -44,6 +44,8 @@ private slots: void float_cast(); void float_cast_data(); void promotionTests(); + void arithOps_data(); + void arithOps(); }; void tst_qfloat16::fuzzyCompare_data() @@ -198,8 +200,12 @@ void tst_qfloat16::float_cast() { QFETCH(float, val); - QVERIFY(qFuzzyCompare(float(qfloat16(val)),val)); - QVERIFY(qFuzzyCompare(float(qfloat16(-val)),-val)); + QVERIFY(qFuzzyCompare((float)(qfloat16(val)),val)); + QVERIFY(qFuzzyCompare((float)(qfloat16(-val)),-val)); + QVERIFY(qFuzzyCompare((double)(qfloat16(val)),(double)(val))); + QVERIFY(qFuzzyCompare((double)(qfloat16(-val)),(double)(-val))); + //QVERIFY(qFuzzyCompare((long double)(qfloat16(val)),(long double)(val))); + //QVERIFY(qFuzzyCompare((long double)(qfloat16(-val)),(long double)(-val))); } void tst_qfloat16::promotionTests() @@ -248,6 +254,55 @@ void tst_qfloat16::promotionTests() QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)-1)); QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)*1)); QCOMPARE(sizeof(double),sizeof(qfloat16(1.f)/1)); + + QCOMPARE(QString::number(1.f),QString::number(qfloat16(1.f))); +} + +void tst_qfloat16::arithOps_data() +{ + QTest::addColumn("val1"); + QTest::addColumn("val2"); + + QTest::newRow("zero") << 0.0f << 2.0f; + QTest::newRow("one") << 1.0f << 4.0f; + QTest::newRow("ten") << 10.0f << 20.0f; +} + +void tst_qfloat16::arithOps() +{ + QFETCH(float, val1); + QFETCH(float, val2); + + QVERIFY(qFuzzyCompare(float(qfloat16(val1) + qfloat16(val2)), val1 + val2)); + QVERIFY(qFuzzyCompare(float(qfloat16(val1) - qfloat16(val2)), val1 - val2)); + QVERIFY(qFuzzyCompare(float(qfloat16(val1) * qfloat16(val2)), val1 * val2)); + QVERIFY(qFuzzyCompare(float(qfloat16(val1) / qfloat16(val2)), val1 / val2)); + + QVERIFY(qFuzzyCompare(qfloat16(val1) + val2, val1 + val2)); + QVERIFY(qFuzzyCompare(qfloat16(val1) - val2, val1 - val2)); + QVERIFY(qFuzzyCompare(qfloat16(val1) * val2, val1 * val2)); + QVERIFY(qFuzzyCompare(qfloat16(val1) / val2, val1 / val2)); + + QVERIFY(qFuzzyCompare(val1 + qfloat16(val2), val1 + val2)); + QVERIFY(qFuzzyCompare(val1 - qfloat16(val2), val1 - val2)); + QVERIFY(qFuzzyCompare(val1 * qfloat16(val2), val1 * val2)); + QVERIFY(qFuzzyCompare(val1 / qfloat16(val2), val1 / val2)); + + float r1 = 0.f; + r1 += qfloat16(val2); + QVERIFY(qFuzzyCompare(r1,val2)); + + float r2 = 0.f; + r2 -= qfloat16(val2); + QVERIFY(qFuzzyCompare(r2,-val2)); + + float r3 = 1.f; + r3 *= qfloat16(val2); + QVERIFY(qFuzzyCompare(r3,val2)); + + float r4 = 1.f; + r4 /= qfloat16(val2); + QVERIFY(qFuzzyCompare(r4,1.f/val2)); } QTEST_APPLESS_MAIN(tst_qfloat16)