0
4

2 回答 2

6

您可以使用表格(实际上是数组)将输入值(度数)映射为该值乘以公因数的正弦值,因此您可以使用这种中间结果实现算术运算。例如:

@echo off 
setlocal EnableDelayedExpansion

call :DefineSinTable

set st=
For /L %%i in (1,1,52) do set st=#!st!

For /L %%x in (0,4,90) do (
   set /a "int_sinx_result=(SIN[%%x]*52)>>16"
   call set st_=%%st:~0,-!int_sinx_result!%%
   echo/!st_!
)

For /L %%x in (90,-4,0) do ( 
   set /a "int_sinx_result=(SIN[%%x]*52)>>16"
   call set st_=%%st:~0,-!int_sinx_result!%%
   echo/!st_!
)
goto :EOF


:DefineSinTable

rem Definition of SIN table values (SIN(x)*65535) for 0-360 degrees
rem Antonio Perez Ayala

set Quad1=0
for %%a in ( 1144  2287  3430  4572  5712  6850  7987  9121 10252 11380 12505 13626 14742 15855 16962 
            18064 19161 20252 21336 22415 23486 24550 25607 26656 27697 28729 29753 30767 31772 32768 
            33754 34729 35693 36647 37590 38521 39441 40348 41243 42126 42995 43852 44695 45525 46341 
            47143 47930 48703 49461 50203 50931 51643 52339 53020 53684 54332 54963 55578 56175 56756 
            57319 57865 58393 58903 59396 59870 60326 60764 61183 61584 61966 62328 62672 62997 63303 
            63589 63856 64104 64332 64540 64729 64898 65048 65177 65287 65376 65446 65496 65526 65535
           ) do (
   set /A Quad1+=1, Quad2=180-Quad1, Quad3=180+Quad1, Quad4=360-Quad1
   set SIN[!Quad1!]=%%a
   set SIN[!Quad2!]=%%a
   set SIN[!Quad3!]=-%%a
   set SIN[!Quad4!]=-%%a
)
for %%a in (0 180 360) do set SIN[%%a]=0
exit /B

您可以使用相同的方法来获得任何其他函数的结果,或者您可以使用迭代方法来计算平方根。

编辑:添加平方根函数。

@echo off

:SquareRoot number

set /A number=%1, last=2, sqrt=number/last
:nextIter
   set /A last=(last+sqrt)/2, sqrt=number/last
if %sqrt% lss %last% goto nextIter
echo %last%

例如:

> SquareRoot.bat 214358881
14641

> SquareRoot.bat 14641
121

> SquareRoot.bat 121
11
于 2013-10-26T08:51:23.437 回答
1

这有效:

@echo off
echo what number do you want to get the sin cos and tan values from of?
set /p in=num:
for /f "delims=" %%a in (' powershell "[Math]::sin(%in%)" ') do set "sin=%%a"
echo the sin of %in% is %sin%
for /f "delims=" %%a in (' powershell "[Math]::cos(%in%)" ') do set "cos=%%a"
echo the cos of %in% is %cos%
for /f "delims=" %%a in (' powershell "[Math]::tan(%in%)" ') do set "tan=%%a"
echo the tan of %in% is %tan%
pause
于 2019-05-04T06:51:13.630 回答