I have tested the Sin(x) of previus post for see the error.
The result on single test is VERY GOOD!
Code: Select all
@echo off
rem sin(x)
call :sin "1.73"
goto :eof
:sin %1=x radiants
set x=%~1
rem calculate SIN(x) ~ x * ( 1 - x^2 * (1/6 - x^2 * (1/120 - x^2 * (1/5040 - x^2 * (1/362880 - x^2 * 1/39916800 )))))
rem calculate x^2
call :floatTestMul2 "%x%" "%x%" "xx"
call :floatTestMul2 "%xx%" "2.5052108385441718775052108385442e-8" "sinp"
call :floatTestSub2 "2.7557319223985890652557319223986e-6" "%sinp%" "sinp2"
call :floatTestMul2 "%xx%" "%sinp2%" "sinp3"
call :floatTestSub2 "1.984126984126984126984126984127e-4" "%sinp3%" "sinp4"
call :floatTestMul2 "%xx%" "%sinp4%" "sinp5"
call :floatTestSub2 "0.00833333333333333" "%sinp5%" "sinp6"
call :floatTestMul2 "%xx%" "%sinp6%" "sinp7"
call :floatTestSub2 "0.16666666666666666" "%sinp7%" "sinp8"
call :floatTestMul2 "%xx%" "%sinp8%" "sinp9"
call :floatTestSub2 "1" "%sinp9%" "sinp10"
call :floatTestMul2 "%x%" "%sinp10%" "sin"
echo Sin(%x%)=%sin%
pause
goto :eof
:: functions add for return a value in variable
:floatTestMul2
:: %~1 float string multiplicand1
:: %~2 float string multiplicand2
setlocal
set "value1=%~1"
set "value2=%~2"
call :str2float "%value1%" "float1"
call :str2float "%value2%" "float2"
call :floatMul "%float1%" "%float2%" "float3"
call :intToHex "hex1" "%float1%"
call :intToHex "hex2" "%float2%"
call :intToHex "hex3" "%float3%"
call :float2str "%float3%" "string1"
rem echo %value1% * %value2% = %float1% * %float2% == %hex1% * %hex2% == %hex3% == %float3% == %string1%
endlocal & set "%~3=%string1%"
goto :eof
:floatTestSub2
:: %~1 float string minuend
:: %~2 float string subtrahend
:: else echo hex value if undefined
setlocal
set "value1=%~1"
set "value2=%~2"
call :str2float "%value1%" "float1"
call :str2float "%value2%" "float2"
call :floatSub "%float1%" "%float2%" "float3"
call :intToHex "hex1" "%float1%"
call :intToHex "hex2" "%float2%"
call :intToHex "hex3" "%float3%"
call :float2str "%float3%" "string1"
rem echo %value1% - %value2% = %float1% - %float2% == %hex1% - %hex2% == %hex3% == %float3% == %string1%
endlocal & set "%~3=%string1%"
goto :eof
result:
Code: Select all
Sin(1.73)=0.9873535
the windows calculator return:
0,98735383970071645108567767622206
0.9873535
I'm very happy
You have done a very good work!
EDIT: We have the SIN(x)!!!!
einstein1969