From 2dcd3939a8bd5ff743e4c87f87b2d81b1a101467 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 12 Jul 2011 17:08:35 +0200 Subject: Cleanup qRound and qRound64: provide overloads for double and float 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 Reviewed-on: http://codereview.qt.nokia.com/1542 Reviewed-by: Qt Sanity Bot --- src/corelib/global/qglobal.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index e91e8afdbc..63333b6233 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1173,16 +1173,15 @@ typedef double qreal; template 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 Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; } -- cgit v1.2.3