summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/global/qglobal.h5
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp26
2 files changed, 31 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 27aaac1..b075db6 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1055,8 +1055,13 @@ inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
inline int qRound(qreal d)
{ return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }
+#if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
+inline qint64 qRound64(double d)
+{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); }
+#else
inline qint64 qRound64(qreal d)
{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); }
+#endif
template <typename T>
inline const T &qMin(const T &a, const T &b) { if (a < b) return a; return b; }
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index d15f9c8..9c9ff33 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -255,6 +255,7 @@ private slots:
void convertByteArrayToBool() const;
void convertByteArrayToBool_data() const;
void toIntFromQString() const;
+ void toIntFromDouble() const;
};
Q_DECLARE_METATYPE(QDate)
@@ -2909,5 +2910,30 @@ void tst_QVariant::toIntFromQString() const
QVERIFY(ok);
}
+/*!
+ We verify that:
+ 1. Conversion from (64 bit) double to int works (no overflow).
+ 2. Same conversion works for QVariant::convert.
+
+ Rationale: if 2147483630 is set in float and then converted to int,
+ there will be overflow and the result will be -2147483648.
+
+ See task 250267.
+ */
+void tst_QVariant::toIntFromDouble() const
+{
+ double d = 2147483630; // max int 2147483647
+ QVERIFY((int)d == 2147483630);
+
+ QVariant var(d);
+ QVERIFY( var.canConvert( QVariant::Int ) );
+
+ bool ok;
+ int result = var.toInt(&ok);
+
+ QVERIFY( ok == true );
+ QCOMPARE(result, 2147483630);
+}
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"