It depends on the required accuracy. The maximum derivative of sin is 1, so if x1 and x2 are inside epsilon from each other, then sin (x1) and sin (x2) are also inside epsilon. If you only want accuracy, say 0.001, then you can create a lookup table of 1000 * PI = 3142 points and just look at the value closest to the one you need. This can be faster than what the native code does, since the native code (possibly) uses a lookup table for polynomial coefficients and then interpolates, and since this table can be small enough to stay in the cache easily.
If you need full accuracy over the entire range, then there is probably nothing better than what you can do.
If you want, you can also create a lookup table (1 / sin (x)), as this is your actual function of interest. In any case, you need to be careful around sin (x) = 0, since a small error in sin (x) can cause a big error in 1 / sin (x). Determining the tolerance of errors is important in determining which shortcuts you can use.
You will create a lookup table with something like:
float *table = malloc(1000 * sizeof(float)); for(int i = 0; i < 1000; i++){ table[i] = sin(i/1000.0); }
and get to him something like
void fastSin(float x){ int index = x * 1000.0; return table[index]; }
This code is not complete (and will break into anything outside 0 <x <1 due to array limitations), but should start working.
source share