Here's my c++ code trying to do the same (for better accuracy just change all math inside the function use double precision, slower then of course):
Code: Select all
float cos_jp(float x)
{
float z = x * 0.5f;
int k = 1;
while (std::abs(z)>0.25){
z *= 0.5f;
k++;
}
z *= z;
float r = ((313.0f * z - 6900.0f) * z + 15120.0f)/((13.0f * z + 660.0f) * z + 15120.0f);
while(k > 0){
r = 2.0f * r * r - 1.0f;
k--;
}
return r;
}
cos_jp() (as it is written in above code) is about EDIT: 30% slower than std::cos but, maybe SSE/AVX could perform better (Q: hows the while loop done in SSE/AVX?).
There's 'shared' cos/sin approximation available later in given stackexchange thread but, I would like to try sin approximation using same method as how cos approximation is done there.
Q: What all changes are needed to get method work for sine (there maybe are some winks given but, I'm not good in math so, ...)?