I had to make good on what I was lecturing bplus about (even if the recent plasma program is speedier)...
So I create two things:
1) Trig tables, strictly 360 degrees. These are lightning fast, like by an order of 10 compared to the native trig functions.
Of course, sometimes you want fractional degrees, which brings me to the next thing:
2) Two functions, InterSin and InterCos - and these can completely (maybe need to convert them to radians first) replace the native SIN and COS. Without any optimization, they are 5% to 10% faster as-is pasted below. The reason they are quick is trigonometric interpolation. Fractional angles are inspired by a first-order approximation using the derivative.
Below is the whole package. Tables, functions, testing, etc. Enjoy. (By that I mean optimize away - I bet these functions can be made faster.)
' Constants.
' Define trig tables.
' Create trig tables in degrees.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Accuracy and testing section (optional)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Speed test native SIN and COS.
' Speed test table SIN and COS (integer arguments only).
a = SinTable(3)
b = CosTable(3)
' Speed test interpolated SIN and COS (any argument).
a = InterSin(3)
b = InterCos(3)
' Error test table at standard intervals:
es = 0
ec = 0
es
= es
+ (SIN(_D2R(k
)) - SinTable
(k
)) ^ 2 ec
= ec
+ (COS(_D2R(k
)) - CosTable
(k
)) ^ 2
' Error test table at smaller intervals:
es = 0
ec = 0
es
= es
+ (SIN(_D2R(k
)) - InterSin
(k
)) ^ 2 ec
= ec
+ (COS(_D2R(k
)) - InterCos
(k
)) ^ 2
' Exampe:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Functions
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
x = arg - z
InterSin = SinTable(z)
InterSin = SinTable(z) + x * (PI180) * CosTable(z)
x = arg - z
InterCos = CosTable(z)
InterCos = CosTable(z) - x * (PI180) * SinTable(z)