Details
-
Bug
-
Resolution: Done
-
P4: Low
-
4.8.6
-
None
-
Windows 7 Pro x64, VS2010
-
4dc597d96c26445a892cfc8f10d0f1da3d8decf1
Description
When using
#include <QtCore> or #include QtXml and having defined
_USE_MATH_DEFINES a warning is triggered by Visual Studio 2010:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\math.h(632) : warning C4005: 'M_PI' : macro redefinition with the hint: qmath.h(261) : see previous definition of 'M_PI'
In qmath.h you can find at the end of the file:
#ifndef M_PI #define M_PI (3.14159265358979323846) #endif inline qreal qFastSin(qreal x) { int si = int(x * (0.5 * QT_SINE_TABLE_SIZE / M_PI)); // Would be more accurate with qRound, but slower. qreal d = x - si * (2.0 * M_PI / QT_SINE_TABLE_SIZE); int ci = si + QT_SINE_TABLE_SIZE / 4; si &= QT_SINE_TABLE_SIZE - 1; ci &= QT_SINE_TABLE_SIZE - 1; return qt_sine_table[si] + (qt_sine_table[ci] - 0.5 * qt_sine_table[si] * d) * d; } inline qreal qFastCos(qreal x) { int ci = int(x * (0.5 * QT_SINE_TABLE_SIZE / M_PI)); // Would be more accurate with qRound, but slower. qreal d = x - ci * (2.0 * M_PI / QT_SINE_TABLE_SIZE); int si = ci + QT_SINE_TABLE_SIZE / 4; si &= QT_SINE_TABLE_SIZE - 1; ci &= QT_SINE_TABLE_SIZE - 1; return qt_sine_table[si] - (qt_sine_table[ci] + 0.5 * qt_sine_table[si] * d) * d; } QT_END_NAMESPACE QT_END_HEADER #endif // QMATH_H
On the one had it is nice to have M_PI defined, but on the other hand math.h defines many additional math constants, too:
#define M_E 2.71828182845904523536 #define M_LOG2E 1.44269504088896340736 #define M_LOG10E 0.434294481903251827651 #define M_LN2 0.693147180559945309417 #define M_LN10 2.30258509299404568402 #define M_PI 3.14159265358979323846 #define M_PI_2 1.57079632679489661923 #define M_PI_4 0.785398163397448309616 #define M_1_PI 0.318309886183790671538 #define M_2_PI 0.636619772367581343076 #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.707106781186547524401
that or not part of qmath.h.
May it be, that the include order in QtCore and QtXml should be changed, to include the math.h before qmath.h, so that M_PI is (optionally) already defined, when qmath.h is included?