diff options
Diffstat (limited to 'src/corelib/kernel/qmath.h')
-rw-r--r-- | src/corelib/kernel/qmath.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index b521323..a9e4378 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -52,6 +52,10 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) +#define QT_SINE_TABLE_SIZE 256 + +extern Q_CORE_EXPORT const qreal qt_sine_table[QT_SINE_TABLE_SIZE]; + inline int qCeil(qreal v) { #ifdef QT_USE_MATH_H_FLOATS @@ -136,6 +140,26 @@ inline qreal qPow(qreal x, qreal y) #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 |