I think this is the fastest method to evaluate ATAN with good precision:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem CORDIC reference: https://bsvi.ru/uploads/CORDIC--_10EBA/cordic.pdf
rem Angles: 45.0000 22.5000 11.2500 5.6250 2.8125 1.4062 0.7031
rem Values below are: tan(angle) * 10000
set "TanTable=10000 4142 1989 985 491 246 123 " & rem NOTE the last space!
rem Values for test
rem Angles: 85 80 75 70 60 45 30 20 15 10 5
for %%t in (114300 56713 37320 27475 17321 10000 5774 3640 2679 1763 875) do (
set /P "=atan(angle)*10000=%%t, " < nul
rem The long SET command below calculate ATAN(%%t^) based on TanTable above
set /A "Y=%%t, x=10000, curAngle=450000, sumAngle=0, sign=(Y>>31)|1, Xnew=X+sign*Y*(Tan=%TanTable: =)/10000, Y-=sign*X*Tan/10000, X=Xnew, sumAngle+=sign*curAngle, curAngle>>=1, sign=(Y>>31)|1, Xnew=X+sign*Y*(Tan=%0), sumAngle=(sumAngle+5000)/10000"
echo Angle = !sumAngle!
)
This code uses CORDIC method with 7 elements. If you want more precision you may increase the number of elements and/or the factor used to multiply tangent values (10000 in this case). As complement, if less precision is enough for you, you may diminish the number of elements and/or the 10000 factor, so the method run faster.
You may also use shorter variable names, so the expression be shorter and run faster. The variable names are the same used in the CORDIC description.
Antonio