Cleanup qRound and qRound64: provide overloads for double and float
authorThiago Macieira <thiago@kde.org>
Tue, 12 Jul 2011 15:08:35 +0000 (17:08 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 20 Jul 2011 08:29:33 +0000 (10:29 +0200)
Instead of having #ifdefs for the type of qreal, simply provide
overloads for both types.

Change-Id: I58582f57d5cd68fcad3fe9efb5fea5935f61b9e3
Merge-request: 17
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/1542
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
src/corelib/global/qglobal.h

index e91e8af..63333b6 100644 (file)
@@ -1173,16 +1173,15 @@ typedef double qreal;
 template <typename T>
 Q_DECL_CONSTEXPR inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
 
-Q_DECL_CONSTEXPR inline int qRound(qreal d)
-{ return d >= qreal(0.0) ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1); }
+Q_DECL_CONSTEXPR inline int qRound(double d)
+{ return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }
+Q_DECL_CONSTEXPR inline int qRound(float d)
+{ return d >= 0.0f ? int(d + 0.5f) : int(d - int(d-1) + 0.5f) + int(d-1); }
 
-#if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
 Q_DECL_CONSTEXPR inline qint64 qRound64(double d)
-{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); }
-#else
-Q_DECL_CONSTEXPR inline qint64 qRound64(qreal d)
-{ return d >= qreal(0.0) ? qint64(d + qreal(0.5)) : qint64(d - qreal(qint64(d-1)) + qreal(0.5)) + qint64(d-1); }
-#endif
+{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - double(qint64(d-1)) + 0.5) + qint64(d-1); }
+Q_DECL_CONSTEXPR inline qint64 qRound64(float d)
+{ return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - float(qint64(d-1)) + 0.5f) + qint64(d-1); }
 
 template <typename T>
 Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }