我有自己的,非常快的 cos 函数:
float sine(float x)
{
const float B = 4/pi;
const float C = -4/(pi*pi);
float y = B * x + C * x * abs(x);
// const float Q = 0.775;
const float P = 0.225;
y = P * (y * abs(y) - y) + y; // Q * y + P * y * abs(y)
return y;
}
float cosine(float x)
{
return sine(x + (pi / 2));
}
但是现在当我分析时,我看到 acos() 正在杀死处理器。我不需要非常精确的。什么是计算acos(x)的快速方法 谢谢。
最佳答案
一个简单的三次近似,x ∈ {-1, -½, 0, ½, 1} 的拉格朗日多项式是:
double acos(x) {
return (-0.69813170079773212 * x * x - 0.87266462599716477) * x + 1.5707963267948966;
}
最大误差约为 0.18 rad。
关于c++ - 快速 Arc Cos 算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3380628/