English 中文(简体)
q FastSin and qFastCos (Speed, safety andqiao)
原标题:qFastSin and qFastCos (Speed, safety and precision)

最近,我在<代码>qmath.h上发现了两个数学功能,名称为qFastSinqFastCos。 这些功能是inline,并使用调查表计算 sin和 co的价值:

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;
}

我搜索了谷歌和Qt-Assistant,以了解这方面的情况,但没有很好的文件。

Does anybody know about precision and performance of these function? (Specially precision)

最佳回答

他们不是公共宣传工具的一部分,得不到支持,没有文件记录,而且会发生变化。

仅凭其支持的文件,只支持其文件。 这样做是好的。

它视之为简单的线性干涉,因此精确性取决于<条码>QT_SINE_TABLE_SIZE,也取决于投入的接近点。 更糟糕的个案错误将是1-sin(pi/2 + 2*pi*(QT_SINE_TABLE_SIZE/2)

如果你对业绩的注意超过准确性,那么你就可以在实践中加以利用,但理论上可以在今后完全删除<>。

问题回答

我使用随机值和数百万英亩的频率以及我所发现的最大误差为0.00000246408,而细微是:sin/cos。 这似乎也更快。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签