Fast Sin/Cos using a pre computed translation array

前端 未结 7 1440
渐次进展
渐次进展 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:04

    One thing you could try would be to use the fact that cos(x) = sin(x + pi/2). And make the sine table one quarter larger, so you can reuse it as the cosine table starting one quarter in. Not sure if C# allows you to get a pointer to the middle of the table, as C would. But even if not, the decreased cache usage might be worth more than the added time for the offset into the sine table.

    That, is, expressed with C:

    double* _CosineDoubleTable = &_SineDoubleTable[TABLESIZE / 4];
    

提交回复
热议问题