Fast Sin/Cos using a pre computed translation array

前端 未结 7 1398
渐次进展
渐次进展 2020-12-09 10:43

I have the following code doing Sin/Cos function using a pre-calculated memory table. in the following example the table has 1024*128 items covering all the Sin/Cos values f

7条回答
  •  囚心锁ツ
    2020-12-09 11:17

    This looks pretty good, except for the mod operation. Can you do without it?

    If the values are near zero, you can use

    while(Value > PI2) Value -= PI2;
    while(Value < 0) Value += PI2;
    

    Or it may be faster to cast the index to an integer (possibly out of range) first, then mod that as as integer. If the table size is going to be a multiple of 2, you can even use bit operations (if the compiler doesn't do this already).

提交回复
热议问题