1
最近我在qmath.h
中發現了兩個數學函數qFastSin
和qFastCos
。這些功能是inline
並使用查找表來計算sin和cos的價值:我搜索谷歌和Qt的助理有關它們的信息qFastSin和qFastCos(速度,安全和精度)
inline qreal qFastSin(qreal x)
{
// Calculating si would be more accurate with qRound, but slower.
int si = int(x * (0.5 * QT_SINE_TABLE_SIZE/M_PI));
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)
{
// Calculating ci would be more accurate with qRound, but slower.
int ci = int(x * (0.5 * QT_SINE_TABLE_SIZE/M_PI));
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;
}
,但沒有很好的文件建立。
有人知道這些功能的精度和性能嗎? (特別精準)