MATHEMATICS
Speed up Sine/Cosine calculations
How about using table?
At first, you should make table....
DIM mySin!(90)
FOR i%=0 TO 90
mySin!(i%) = SIN(i% * 3.14159265358979! / 180!)
NEXT
Then output mySin! array to the resource fork for mini application.
Make sure to set it be able to purge.
If you have to calc sin, just do this!
mySin& = FN GETRESOURCE(_"SINT",128)
XREF @mySin!(90)
Cosine or Sin which over 90 (not radian, just degrees) are easily convert from sin table.
LOCAL FN myFastSin(radian!)
mySin& = FN GETRESOURCE(_"SINT",128)
XREF @mySin!(90)
deg% = (radina! * 180! / 3.14159265358979!) + .5
deg% = deg% MOD 360
SELECT deg%
CASE <= 90 : result! = mySin!(deg%)
CASE <=180 : result! = mySin!(90-deg%)
CASE <=270 : result! = -mySin!(deg%-180)
CASE ELSE : result! = -mySin!(360-deg%)
END SELECT
END FN = result!
<< Also, given that sin^2 + cos^2 = 1, you would only need one table and could calculate the other with a square root. >>
And given that sin(x) = cos(90^o - x), you can dispense with the square root as well.
|