Fastest sin(x) in dos batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Fastest sin(x) in dos batch

#46 Post by einstein1969 » 31 Mar 2023 13:49

I'm not an expert in macro...

try this

Code: Select all

@echo off

setlocal enableDelayedExpansion

(Set \n=^^^
%= \n escaped linefeed for macro definition. Do not modify =%
%= Do not modify =%)

set sin=for %%# in (1 2) do if %%#==2 (						%\n%
		for /f "tokens=1 delims=, " %%1 in ("^!args^!") do ( 		%\n%
			set /a "$result=($a=((%%1*31416/180)%%62832) + (((%%1*31416/180)%%62832)>>31&62832) , $b=($a-15708^^$a-47124)>>31 ,$a=(-$a&$b)+($a&~$b)+(31416&$b)+(-62832&(47123-$a>>31)), $a-$a*$a/1875*$a/320000+$a*$a/1875*$a/15625*$a/16000*$a/2560000-$a*$a/1875*$a/15360*$a/15625*$a/15625*$a/16000*$a/44800000 )" %\n%
)) else set args= 

%sin% 45
echo sin(45)=0.%$result%

pause

IcarusLives
Posts: 161
Joined: 17 Jan 2016 23:55

Re: Fastest sin(x) in dos batch

#47 Post by IcarusLives » 31 Mar 2023 15:56

Oh haha! I'm sorry, I was refering to aacini's method. Your sin(x) works perfectly the way you posted it the first time, my apologies for the miscommunication. I'm just a little puzzled with the solution aacini posted. Does it only support up to 85 degrees? I'm still learning and trying to understand trigonometry..

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Fastest sin(x) in dos batch

#48 Post by einstein1969 » 31 Mar 2023 16:02

Supports any grade/degree

Post Reply