diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-01-14 11:17:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-02-16 16:21:15 +0000 |
commit | 515e802ae20c045e5c47b400ee6ef6e92349c978 (patch) | |
tree | f9f4be4c9e360611b5823ef28c2cb293733aee42 /src/corelib/kernel/qmath.h | |
parent | 3d835eb62e70435fe32318441dc7c10aba3a6fba (diff) |
Use C++ <cmath> instead of <math.h>
Including math.h can pollute the default namespace, and break
some compilers if cmath versions of the method are declared as using.
Switching to C++ math functions also greatly simplifies handling of
float qreal as C++ automatically chooses the right method.
[ChangeLog][QtCore][QtMath] qmath.h no longer includes math.h, so any
sources depending on that indirect inclusion may fail to build.
Change-Id: I4d0e331dafba354ec05dc5052e61ef4ff8d387fe
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qmath.h')
-rw-r--r-- | src/corelib/kernel/qmath.h | 113 |
1 files changed, 29 insertions, 84 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index 2395e9ee1c..5cc3ec586e 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -38,13 +38,11 @@ #pragma qt_class(QtMath) #endif -#include <math.h> - #include <QtCore/qglobal.h> -#include <QtCore/qcompilerdetection.h> -QT_BEGIN_NAMESPACE +#include <cmath> +QT_BEGIN_NAMESPACE #define QT_SINE_TABLE_SIZE 256 @@ -52,139 +50,86 @@ extern Q_CORE_EXPORT const qreal qt_sine_table[QT_SINE_TABLE_SIZE]; inline int qCeil(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return int(ceilf(float(v))); - else -#endif - return int(ceil(v)); + using std::ceil; + return int(ceil(v)); } inline int qFloor(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return int(floorf(float(v))); - else -#endif - return int(floor(v)); + using std::floor; + return int(floor(v)); } inline qreal qFabs(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if(sizeof(qreal) == sizeof(float)) - return fabsf(float(v)); - else -#endif - return fabs(v); + using std::fabs; + return fabs(v); } inline qreal qSin(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return sinf(float(v)); - else -#endif - return sin(v); + using std::sin; + return sin(v); } inline qreal qCos(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return cosf(float(v)); - else -#endif - return cos(v); + using std::cos; + return cos(v); } inline qreal qTan(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return tanf(float(v)); - else -#endif - return tan(v); + using std::tan; + return tan(v); } inline qreal qAcos(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return acosf(float(v)); - else -#endif - return acos(v); + using std::acos; + return acos(v); } inline qreal qAsin(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return asinf(float(v)); - else -#endif - return asin(v); + using std::asin; + return asin(v); } inline qreal qAtan(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return atanf(float(v)); - else -#endif - return atan(v); + using std::atan; + return atan(v); } inline qreal qAtan2(qreal y, qreal x) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return atan2f(float(y), float(x)); - else -#endif - return atan2(y, x); + using std::atan2; + return atan2(y, x); } inline qreal qSqrt(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return sqrtf(float(v)); - else -#endif - return sqrt(v); + using std::sqrt; + return sqrt(v); } inline qreal qLn(qreal v) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return logf(float(v)); - else -#endif - return log(v); + using std::log; + return log(v); } inline qreal qExp(qreal v) { - // only one signature - // exists, exp(double) + using std::exp; return exp(v); } inline qreal qPow(qreal x, qreal y) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return powf(float(x), float(y)); - else -#endif - return pow(x, y); + using std::pow; + return pow(x, y); } #ifndef M_E |