# Thread: A faster way to calculate sine function?

1. ## A faster way to calculate sine function?

I remember reading an interesting article about some guy who made up a new algorithm for calculating approximate values of the sine function, which I found out to be at least 30%-40% faster than the one used in math.h. Unfortunately I lost the code where I used this algorithm and now that I've spent several hours searching for it over the 'net, it feels like it just vanished somewhere...
So... does anyone happen to know what am I talking about or has a link to that article? I'm sure I'm not the only one who has read it, and I'd really appreciate it if anyone could either give me a link to that page or the algorithm itself

2. here's a little place full of code: http://www.frees3x.org

4. For small values of x,
sin x ~= x

5. true if they're out of the variable's accuracy range

6. Take a look at this....hope it helps
Code:
```//The code below calculates the cosine of 50000000 random values
//using both a look up table, which is calculated at the beginning
//of the program, and using the normal cos function during runtime.
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
//Declare look up table
double COSTable[360]; //360 elements for all angles between 0 and 359.
int Number;

//Calculate look up table
cout << "Calculating Cosine look up table..." << endl;

for(Number = 0; Number < 360; Number++)
{
COSTable[Number] = cos(Number * 3.14159 / 180);
}

//Calculate Cosine of 50000000 values using look up table
// and then using cos.
cout << "Calculating cosine of 50000000 random values using look"
<< " up table..." << endl;

//Look up table
for(Number = 0; Number < 50000000; Number++)
{
COSTable[rand() % 360];
}

cout << "Complete..." << endl;

cout << "Calculating cosine of 50000000 random values using cos"
<< " function..." << endl;

//cos function
for(Number = 0; Number < 50000000; Number++)
{
cos(double(rand() % 360));
}

cout << "Complete..." << endl;

return 0;
}```

7. Interesting solution
It's not exactly what I was looking for, but I do agree that it's a pretty nice way to speed up things if you're dealing a lot with exact degree values. I'll keep that in mind