/*
This function tests a double for a null value. It doesn't
check whether the actual value is 0 or close to 0, but whether
- it is binary 0.
+ it is binary 0, disregarding sign.
*/
static inline bool qIsNull(double d)
{
};
U val;
val.d = d;
- return val.u == quint64(0);
+ return (val.u & Q_UINT64_C(0x7fffffffffffffff)) == 0;
}
/*
This function tests a float for a null value. It doesn't
check whether the actual value is 0 or close to 0, but whether
- it is binary 0.
+ it is binary 0, disregarding sign.
*/
static inline bool qIsNull(float f)
{
};
U val;
val.f = f;
- return val.u == 0u;
+ return (val.u & 0x7fffffff) == 0;
}
/*
QVERIFY(!::qIsNull(d));
QVERIFY(!::qIsNull(f));
+
+ d = -0.0;
+ f = -0.0f;
+
+ QVERIFY(::qIsNull(d));
+ QVERIFY(::qIsNull(f));
}
void tst_QGlobal::for_each()
QVERIFY(!point.isNull());
point.rx() -= 2;
QVERIFY(!point.isNull());
+
+ QPointF nullNegativeZero(qreal(-0.0), qreal(-0.0));
+ QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
+ QVERIFY(nullNegativeZero.isNull());
}
void tst_QPointF::manhattanLength_data()
{
Q_OBJECT
private slots:
+ void isNull_data();
+ void isNull();
+
void scale();
void expandedTo();
void transpose();
};
+void tst_QSizeF::isNull_data()
+{
+ QTest::addColumn<qreal>("width");
+ QTest::addColumn<qreal>("height");
+ QTest::addColumn<bool>("isNull");
+
+ QTest::newRow("0, 0") << qreal(0.0) << qreal(0.0) << true;
+ QTest::newRow("-0, -0") << qreal(-0.0) << qreal(-0.0) << true;
+ QTest::newRow("0, -0") << qreal(0) << qreal(-0.0) << true;
+ QTest::newRow("-0, 0") << qreal(-0.0) << qreal(0) << true;
+ QTest::newRow("-0.1, 0") << qreal(-0.1) << qreal(0) << false;
+ QTest::newRow("0, -0.1") << qreal(0) << qreal(-0.1) << false;
+ QTest::newRow("0.1, 0") << qreal(0.1) << qreal(0) << false;
+ QTest::newRow("0, 0.1") << qreal(0) << qreal(0.1) << false;
+}
+
+void tst_QSizeF::isNull()
+{
+ QFETCH(qreal, width);
+ QFETCH(qreal, height);
+ QFETCH(bool, isNull);
+
+ QSizeF size(width, height);
+ QCOMPARE(size.width(), width);
+ QCOMPARE(size.height(), height);
+ QCOMPARE(size.isNull(), isNull);
+}
+
void tst_QSizeF::scale() {
QSizeF t1(10.4, 12.8);
t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio);
QCOMPARE(identity.scalar(), (qreal)1.0f);
QVERIFY(identity.isIdentity());
+ QQuaternion negativeZeroIdentity(qreal(1.0), qreal(-0.0), qreal(-0.0), qreal(-0.0));
+ QCOMPARE(negativeZeroIdentity.x(), qreal(-0.0));
+ QCOMPARE(negativeZeroIdentity.y(), qreal(-0.0));
+ QCOMPARE(negativeZeroIdentity.z(), qreal(-0.0));
+ QCOMPARE(negativeZeroIdentity.scalar(), qreal(1.0));
+ QVERIFY(negativeZeroIdentity.isIdentity());
+
QQuaternion v1(34.0f, 1.0f, 2.5f, -89.25f);
QCOMPARE(v1.x(), (qreal)1.0f);
QCOMPARE(v1.y(), (qreal)2.5f);
QCOMPARE(null.y(), (qreal)0.0f);
QVERIFY(null.isNull());
+ QVector2D nullNegativeZero(qreal(-0.0), qreal(-0.0));
+ QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
+ QVERIFY(nullNegativeZero.isNull());
+
QVector2D v1(1.0f, 2.5f);
QCOMPARE(v1.x(), (qreal)1.0f);
QCOMPARE(v1.y(), (qreal)2.5f);
QCOMPARE(null.z(), (qreal)0.0f);
QVERIFY(null.isNull());
+ QVector3D nullNegativeZero(qreal(-0.0), qreal(-0.0), qreal(-0.0));
+ QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.z(), (qreal)-0.0f);
+ QVERIFY(nullNegativeZero.isNull());
+
QVector3D v1(1.0f, 2.5f, -89.25f);
QCOMPARE(v1.x(), (qreal)1.0f);
QCOMPARE(v1.y(), (qreal)2.5f);
QCOMPARE(null.w(), (qreal)0.0f);
QVERIFY(null.isNull());
+ QVector4D nullNegativeZero(qreal(-0.0), qreal(-0.0), qreal(-0.0), qreal(-0.0));
+ QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.z(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.w(), (qreal)-0.0f);
+ QVERIFY(nullNegativeZero.isNull());
+
QVector4D v1(1.0f, 2.5f, -89.25f, 34.0f);
QCOMPARE(v1.x(), (qreal)1.0f);
QCOMPARE(v1.y(), (qreal)2.5f);