#1 10 Mar 2014 05:35

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Problems with decimal point in my calculator program

I have developed a fast floating point calculator, that can compute sums, substractions, divisions, and multiplications, all with / without decimals, but I have some problems:

1.- Some division operations, decimal point sets wrongly. (Example: .03 / .5)
2.- Doesn't strip the unnecessary zeros from end of line.
3.- Some multiplication operations, decimal point sets wrongly. (Example: 25 * 1000.05)
4.- Operations with '08' and '09' digits, have bugs. ( Example: [8.08 + .08] and [9.09 + .09] )
    (This due to octal operations that recognize 'Set/a' command)

This uses AutoMacro, sets part of code as macro for use it in batch as variable, I used some parts of code from others users, making easy and fast to set a macro.

Note 1: code have several 'Rem' commands due to several tests.
Note 2: I modified a bit the code.

@Echo off
	Setlocal EnableExtensions
	Call :Flush
	Set "Game=%~0"
	Set Err=-1
	Set LF=^


	::
	Set Macros=Calc;
	For %%# in (%Macros%) Do (
		Call :AutoMacro %%#
	)
	Setlocal EnabledelayedExpansion
		For %%# in (%Macros%) Do (
		Set ^"%%#=!%%#:[LF]=^%LF%%LF%!"
	)
	Set Macros=

goto :sub
Set/p Sum1=int1:
Set/p Sum2=int2:
:Main
:: Acc = Accuracy
:: .0 = decimals .00 = cents .000 = milli
:: Test: sum -> 2 + 2.5 = 4.5
:: Set sum1=2.5
:: Set sum2=2

:: Real proccessment

:: Set sum1=2.5
:: Set sum2=2.0
:sub
for /l %%a in (1,1,100) Do (
rem calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
rem calc% 992.95 + 100.85
rem calc% 992.95 - 100.05
rem calc% 25 * 1000.05
rem calc% 1.2 / 3.5
%calc% 5.05 + .05
rem call :calc 2.2 + 2.2
rem call :calc 8.888 + 0.82000
)
::call :calc 120.523 * 2.21
::call :calc 99.5 + 100.012
pause
exit

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
Set Div.acc=100
For %T in (1;2) Do (
If "!Sum%T:~0,1!" Equ "." Set "Sum%T=0!Sum%T!"
	For /F "Tokens=1-2 Delims=;:,." %a in ("!Sum%T!") Do (
		Set Sum%T.Int=%a
		Set Sum%T.Float=%b
	)

	If Not Defined Sum%T.Float Set Sum%T.Float=0
	
	For %R in (Int;Float) Do (
		Set "Str=A!Sum%T.%R!"
		Set/a "Len=0"
		For /L %H in (4,-1,0) Do (
			Set/a "Len|=1<<%H"
			For %F in (!Len!) Do If "!Str:~%F,1!" Equ "" Set/a "Len&=~1<<%H"
		)
		Set S%T%R.Lng=!Len!
    )
)
	Echo;--- !Sum1.Int!.!Sum1.Float! _-_- !Sum2.Int!.!Sum2.Float!

	If !S1Float.Lng! Equ !S2Float.Lng! (Set RLng=!S1Int.Lng!) Else (Set RLng=1)
	Rem Floating Point Range Adjust
	If !S1Float.Lng! Gtr !S2Float.Lng! (
		Set/a "Cr.Lng=S1Float.Lng - S2Float.Lng"
		For /L %R in (1,1,!Cr.Lng!) Do Set Sum2.Float=!Sum2.Float!0
		Set/a RLng=!S1Int.Lng!
	)
	If !S2Float.Lng! Gtr !S1Float.Lng! (
		Set/a "Cr.Lng=S2Float.Lng - S1Float.Lng"
		For /L %R in (1,1,!Cr.Lng!) Do Set Sum1.Float=!Sum1.Float!0
		Set/a RLng=!S2Int.Lng!
	)
	If !S1Int.Lng! Gtr !S2Int.Lng! Set RLng=!S1Int.Lng!
	If !S2Int.Lng! Gtr !S1Int.Lng! Set RLng=!S2Int.Lng!
	Echo;--- !Sum1.Int!.!Sum1.Float! _-_- !Sum2.Int!.!Sum2.Float!
	Rem Octal error correction
	For %T in (1;2) Do (
		If "!Sum%T.Float:~0,1!" Equ "0" (
			If !Sum%T.Float:~1^,1! Lss 10 If !Sum%T.Float:~1^,1! Gtr 7 (
				Set Sum%T.Float=!Sum%T.Float:~1!
				If Not !Sum1.Int!!Sum1.Float! Gtr 100 (
					Set/a RLng-=1
				)
			)
		)
		If "!Sum%T.Int:~0,1!" Equ "0" Set Sum%T.Int=
	)
	Echo;--- !Sum1.Int!.!Sum1.Float! _-_- !Sum2.Int!.!Sum2.Float!
	If "!Mode!" Neq "/" (
		Set/a "Total=!Sum1.Int!!Sum1.Float! !mode! !Sum2.Int!!Sum2.Float!"
		If Defined Sum1.Int If Defined Sum2.Int Set/a ChkInt=!Sum1.Int! !Mode! !Sum2.Int!,ChkFloat=!Sum1.Float! !Mode! !Sum2.Float!
	) Else (
		Set/a "Total=( !Sum1.Int!!Sum1.Float! * Div.acc ) !Mode! !Sum2.Int!!Sum2.Float!"
	)
	Rem Offset correction for 'minus' operations for lss than 10
	If "!Mode!" Equ "-" (
		If !Total! Lss 10 (
		If !Sum1.Int!!Sum1.Float! Gtr !Sum2.Int!!Sum2.Float! (
			Set/a RLng-=1
		))
	)
	Rem Offset correction for '/' operations for numbers lss than 10
	If "!Mode!" Equ "/" (
		rem For /L %R in (2,1,!S1Int.Lng!) Do Set/a RLng-=1
		REm Set/a Dv=Div.acc-1
		REm If !Total! Gtr 9!Dv!  Set/a RLng+=1
		REm If !Total! Gtr 99!Dv!  Set/a RLng+=1
		REm If !Total! Gtr 999!Dv!  Set/a RLng+=1
		REm If !Total! Gtr 9999!Dv!  Set/a RLng+=1
		REm 
		REm If !Total! Lss !Dv! Set/a RLng-=1
		REm If !Total! Lss !Dv:~1! Set/a RLng-=1
		REm If !Total! Lss !Dv:~3! Set/a RLng-=1
		REm If !Total! Lss !Dv:~4! Set/a RLng-=1
		set/a "Rlng=!Div.Acc! / (Div.acc / 2) - 1"
	)
	Rem Offset corrections for '+,-,*' operations for number greater than 999
	For %T in ("" 9 99 999 9999) Do (
		rem If !ChkFloat! Gtr 999%~T Set/a RLng+=1
	)
		rem If !ChkInt! Gtr 99 Set/a RLng+=1
	Rem Result
	rem Echo;!Sum1.Int!!Sum1.Float! Gtr !Sum2.Int!!Sum2.Float!
	For %U in (!RLng!) Do Echo;!Total:~0,%U!.!Total:~%U!
</Function=Calc>
	
:Flush
	For /f "Tokens=1 Delims==" %%a in ('Set') Do (
	If /i "%%a" Neq "Comspec" (
	If /i "%%a" Neq "Tmp" (
	If /i "%%a" Neq "Userprofile" (
	IF /i "%%a" Neq "SystemRoot" (
	Set "%%a="))))
	)
	Set "Path=%comspec:~0,-8%;%SystemRoot%;%Comspec:~0,-8%\Wbem"
	Goto :Eof

:: -> AutoMacro helps you to set variables with functions then be ready to use <- ::

:AutoMacro
	Set "Start="
	set "Tm=%Tmp%\Tmp.dat"
	Set "End="
	Set "%~1="
	For /F "Tokens=1,3 Delims=>|:" %%a in ('Findstr /N /B "</*Function=%~1" "%Game%"') Do (
		If Not Defined Start (
			Set Start=%%a
			Set Type=%%b
		) Else (
			Set End=%%a
		)
	)
	If %Type% Equ 1 (
		<Nul Set/p=([LF]>>"%Tm%"
	)
	If %Type% Equ 2 (
		<Nul Set/p=For %%` in (0;1^) Do If %%` Equ 1 (For /F "Tokens=1-9" %%1 in ("!Argv!"^) Do ([LF]>>"%Tm%"
	)
	Set/a Start+=2
	For /F "Tokens=1* Skip=%Start% Delims=[]" %%a in ('Find /N /V "" "%Game%"') do (
		If %%a Geq %End% Goto :End
		<Nul Set/p=%%b[LF]>>"%Tm%"
	)
:End
	If %Type% Equ 1 (
		<Nul Set/p=^)>>"%Tm%"
	)
	If %Type% Equ 2 (
		<Nul Set/p=^)^) Else Set Argv=>>"%Tm%"
	)

	(
	For /F "Delims=" %%a in ('Type "%Tm%"') Do Set "%~1=%%a"
	) >Nul 2>&1 || Goto :ErrMacro
	Del "%Tm%">Nul 2>&1
	Set Tm=& Set Start=& Set End=
	Goto :Eof
:ErrMacro
	Set/a Start-=2
	For %%a in (
	"Macro Setup Failure from line:"
	"	Start: '%Start%'"
	"	End:   '%End%'"
	"	Expected '%~1' macro with size less than 8KB {8010B} (8100 Letters)"
	) Do Echo;%%~a
	Pause>Nul
	Exit

Anyone can help me? Any help are grateful!

Last edited by Honguito98 (10 Mar 2014 19:49)


.::{Honguito98}::.

Offline

#2 18 Mar 2014 00:04

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi honguito!

Very nice work.

I don't know if this help you. http.//www.dostips.com/forum/viewtopic.php?p=29201#p29201


einstein1969

Offline

#3 19 Mar 2014 21:51

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito98!

I have merged my code but i don't know if is good.

This is not optimized and not tested.

@Echo off
	Setlocal EnableExtensions
	Call :Flush
	Set "Game=%~0"
	Set Err=-1
	Set LF=^


	::
	Set Macros=Calc;
	For %%# in (%Macros%) Do (
		Call :AutoMacro %%#
	)
	Setlocal EnabledelayedExpansion
		For %%# in (%Macros%) Do (
		Set ^"%%#=!%%#:[LF]=^%LF%%LF%!"
	)
	Set Macros=

goto :sub
Set/p Sum1=int1:
Set/p Sum2=int2:
:Main
:: Acc = Accuracy
:: .0 = decimals .00 = cents .000 = milli
:: Test: sum -> 2 + 2.5 = 4.5
:: Set sum1=2.5
:: Set sum2=2

:: Real proccessment

:: Set sum1=2.5
:: Set sum2=2.0
:sub
for /l %%a in (1,1,1) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%calc% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
rem call :calc 2.2 + 2.2
rem call :calc 8.888 + 0.82000
)
::call :calc 120.523 * 2.21
::call :calc 99.5 + 100.012
pause
exit /b

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
echo !sum1!!mode!!sum2!
Set Div.acc=100
set prec=2
For %T in (1;2) Do (

	rem add initial zero if operand start with "." OK

	If "!Sum%T:~0,1!" Equ "." Set "Sum%T=0!Sum%T!"


	rem separe integer part and float part. OK

	For /F "Tokens=1-2 Delims=;:,." %a in ("!Sum%T!") Do (
		Set Sum%T.Int=%a
		Set Sum%T.Float=%b
	)


	rem if there isn't float part set float to zero. ie there isn't ".," in operand

	If Not Defined Sum%T.Float Set Sum%T.Float=0


	rem temp value
	rem add initial zero

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set f%T=0000000000%~f%~g%~h%~i

	rem add final zeros.
	For %P in (!prec!) do (
		set i%T=!f%T:*.=!0!f%T:~0,%P!
		set i_%T=!f%T:*.=!0!f%T:~0,%P! & rem for debug
		set i=!f%T:*.=!
        	For %I in (!i!) do if not "%I" == "!f%T!" (
			set ii%T=!f%T:.%I=!!i%T:~0,1!!i%T:~1,%P! & rem for debug
			set i%T=!f%T:.%I=!!i%T:~0,1!!i%T:~1,%P!
		)
	)

	rem round + remove initial zeros
	for /f "tokens=* delims=0" %z in ("!i%T!") do (
			set /a "i%T=(%z+5)/10"
			set /a "iii%T=(%z+5)/10" & rem for debug
	)
)
	rem now the operand is well written

	Echo;--- !Sum1.Int!.!Sum1.Float! _-_- !Sum2.Int!.!Sum2.Float!

	rem debug:
	rem echo f1:!f1! f2:!f2! 
	rem echo i_1:!i_1! i_2:!i_2!
	rem echo ii1:!ii1! ii2:!ii2!
	rem echo iii1:!iii1! iii2:!iii2!

	rem echo i1:!i1! i2:!i2!

	rem do operations
	if "!Mode!" equ "/" (set /a Total=!i1!*!Div.acc!/!i2!
	) else (if "!Mode!" equ "*" (set /a Total=!i1!*!i2!/!Div.acc!) else set /a Total=!i1!!Mode!!i2!)

	rem echo !Total!

	set i=!Total!
	
	For %P in (!prec!) do set nnn=!f1:~0,%P!

	set mul=1!nnn!
	set /a "f1=i/mul"

	set /a "f2=i % mul"
	set f2=!nnn!!f2!
	For %P in (!prec!) do set f2=!f2:~-%P!
	set Total=!f1!.!f2!
	
	echo;!Total!
</Function=Calc>
	
:Flush
	For /f "Tokens=1 Delims==" %%a in ('Set') Do (
	If /i "%%a" Neq "Comspec" (
	If /i "%%a" Neq "Tmp" (
	If /i "%%a" Neq "Userprofile" (
	IF /i "%%a" Neq "SystemRoot" (
	Set "%%a="))))
	)
	Set "Path=%comspec:~0,-8%;%SystemRoot%;%Comspec:~0,-8%\Wbem"
	Goto :Eof

:: -> AutoMacro helps you to set variables with functions then be ready to use <- ::

:AutoMacro
	Set "Start="
	set "Tm=%Tmp%\Tmp.dat"
	Set "End="
	Set "%~1="
	For /F "Tokens=1,3 Delims=>|:" %%a in ('Findstr /N /B "</*Function=%~1" "%Game%"') Do (
		If Not Defined Start (
			Set Start=%%a
			Set Type=%%b
		) Else (
			Set End=%%a
		)
	)
	If %Type% Equ 1 (
		<Nul Set/p=([LF]>>"%Tm%"
	)
	If %Type% Equ 2 (
		<Nul Set/p=For %%` in (0;1^) Do If %%` Equ 1 (For /F "Tokens=1-9" %%1 in ("!Argv!"^) Do ([LF]>>"%Tm%"
	)
	Set/a Start+=2
	For /F "Tokens=1* Skip=%Start% Delims=[]" %%a in ('Find /N /V "" "%Game%"') do (
		If %%a Geq %End% Goto :End
		<Nul Set/p=%%b[LF]>>"%Tm%"
	)
:End
	If %Type% Equ 1 (
		<Nul Set/p=^)>>"%Tm%"
	)
	If %Type% Equ 2 (
		<Nul Set/p=^)^) Else Set Argv=>>"%Tm%"
	)

	(
	For /F "Delims=" %%a in ('Type "%Tm%"') Do Set "%~1=%%a"
	) >Nul 2>&1 || Goto :ErrMacro
	Del "%Tm%">Nul 2>&1
	Set Tm=& Set Start=& Set End=
	Goto :Eof
:ErrMacro
	Set/a Start-=2
	For %%a in (
	"Macro Setup Failure from line:"
	"	Start: '%Start%'"
	"	End:   '%End%'"
	"	Expected '%~1' macro with size less than 8KB {8010B} (8100 Letters)"
	) Do Echo;%%~a
	Pause>Nul
	Exit


exit/B

Result:

30439.291+20918.322
--- 30439.291 _-_- 20918.322
51357.61
992.95+100.85
--- 992.95 _-_- 100.85
1093.80
992.95-100.05
--- 992.95 _-_- 100.05
892.90
25*1000.05
--- 25.0 _-_- 1000.05
25001.25
1.2/3.5
--- 1.2 _-_- 3.5
0.34
5.05+.05
--- 5.05 _-_- 0.05
5.10
.03/.5
--- 0.03 _-_- 0.5
0.06
09/08
--- 09.0 _-_- 08.0
1.12

I have leave some your code (the initial part that separe flot e int) that not operate but could be usable for optimizing.

einstein1969

Offline

#4 22 Mar 2014 06:34

ImATootsieRollPOP
New Member
Registered: 15 Mar 2014
Posts: 4

Re: Problems with decimal point in my calculator program

Hey Honguito98, I don't think this has to be this complicated. (Sorry if I'm not very good at what you guys are doing.)
I think you could just use this script, though I'm not sure it would work with decimals.





@Echo off
set Answer=0
cls

:calc
set /p problem=Please enter the full math problem:
set /a problem=%problem%
set answer=%problem%
goto answer

:answer
cls
echo Your answer is: %answer%
echo.
pause
goto calc






Like I said, Sorry if that doesn't meet up with what you usually do, or doesn't support decimals. I'm still not a pro with coding like you guys do.

Hope it helped.

Regards,
Andrew

Offline

#5 24 Mar 2014 07:01

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: Problems with decimal point in my calculator program

Thanks for the feedback.

@einstein1969
Your modified code works!! But is bit slower, I think that the floating point support is very slow. But all these optimizations, I think that this calculator is faster!

@Andrew
The point for do a calculator in batch with floating point support is make some basical calculations, as well as use it tiny batch games, for example, calculate a complex coordinate or scores.
Also this is a example code for integrate a fast floating point calculator in batch, via macro.
Use variables as macros, speed up to 40-80% the execution, but set a big macro, the performance may be reduced to 10-30%


.::{Honguito98}::.

Offline

#6 24 Mar 2014 16:34

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito,

you are right. it's slow.

My code actually deals with real numbers in the FIXED point but it is adaptable to work in near FLOAT (which is your initial approach).
But it was not clear to me how it worked. For example how you calculated the variable RLng. Why you use this variable?

However, I did some performance tests, though still does not work all the better.

But if you agree I would like to finish your idea. Which is fantastic. I like its simplicity.

I have tested the code above:

set N_OPS=100

set t0=%time%

for /l %%a in (1,1,%N_OPS%) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%calc% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
%calc% 8.08 + .08
%calc% 9.09 + .09
) >nul

for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_OPS%*10000/a"

echo Elapsed:%a% centiseconds - Flops:%FLOPS:~0,-1%.%FLOPS:~-1%

on my monocore the Flops(floating point per second) are about 200:

Elapsed:490 centiseconds - Flops:204.0

now the light version (firts attempt of optimizing):

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
<nul set/p "=!sum1! !mode! !sum2! ="
rem precision/accurancy
set prec=2
For %P in (!prec!) do (
    For %T in (1;2) Do (

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set Sum%T=0000000000%~f%~g%~h%~i

	set i%T=!Sum%T:*.=!0!Sum%T:~0,%P!
        For %I in ("!Sum%T:*.=!") do if not "%~I" == "!Sum%T!" set i%T=!Sum%T:.%~I=!!i%T:~0,1!!i%T:~1,%P!

	for /f "tokens=* delims=0" %z in ("!i%T!") do set /a "i%T=(%z+5)/10"
        rem if not defined i%T set i%T=0
    )
		set Div.acc=1!Sum1:~0,%P!

		if "!Mode!" equ "/" (
			set /a Total=!i1!*!Div.acc!/!i2!
		) else (
		 if "!Mode!" equ "*" (
			set /a Total=!i1!*!i2!/!Div.acc!
		 ) else set /a Total=!i1!!Mode!!i2!
		)

		set /a "Int=Total/Div.acc, Float=Total % Div.acc"
		set Float=!Sum1:~0,%P!!Float!
		set Float=!Float:~-%P!
)
	echo; !Int!.!Float!
</Function=Calc>

tested 200 OPs (cycles of 10 OPS) (set N_OPS=200), the result is about 450 Flops. (220%)

Elapsed:439 centiseconds - Flops:455.0

EDIT: sorry, i don't have multiply for 10. the FLOPS are 200 and 450 respectively. I have correct above.

einstein1969

Last edited by einstein1969 (24 Mar 2014 18:13)

Offline

#7 24 Mar 2014 18:37

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: Problems with decimal point in my calculator program

RLng variable contains a certain number for split the result from an unique result variable.
On my laptop, with 4 cores, the results are:

Without print results on screen, and don't redirect to NUL.

Elapsed:102 centiseconds - Flops:627.4

Now, print result on screen and redirect to NUL (your code):

Elapsed:119 centiseconds - Flops:537.8

Tested with 64 and 1024 Ops, I get the same results.


.::{Honguito98}::.

Offline

#8 25 Mar 2014 15:04

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Honguito98 wrote:

RLng variable contains a certain number for split the result from an unique result variable.
On my laptop, with 4 cores, the results are:

Without print results on screen, and don't redirect to NUL.

Elapsed:102 centiseconds - Flops:627.4

Now, print result on screen and redirect to NUL (your code):

Elapsed:119 centiseconds - Flops:537.8

Tested with 64 and 1024 Ops, I get the same results.

Your machine is faster than mine big_smile

I have seen your game! Fabulous! But the last do not work on my monocore old laptop sad

I also believe that this FP engine is more faster than using an external cscript/exe/dll. I see that often uses the dll. You could do some tests and see how many times per second loads a dll?

I also did some testing and I found two functional problems:

1) with minus operation for examples "%calc% 14797.109 - 15213.132"

i have patched this.

2) with multiply operation. examples "%calc% 3151.277 * 567.607"

i'm studing for a patch... Should be resolved in part by the Karatsuba's method.

I have changed this part of code.

	For /F "Delims=" %%a in ('Type "%Tm%"') Do Set "%~1=%%a"
	) >Nul 2>&1 || Goto :ErrMacro
	Del "%Tm%">Nul 2>&1

	rem Changed: add set Type=

	Set Tm=& Set Start=& Set End=&set Type=
	Goto :Eof

i don't know if is good. Await your feedback!

Then the macro patched for minus operations

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
set prec=2
For %P in (!prec!) do (

    For %T in (1;2) Do (

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set Sum%T=0000000000%~f%~g%~h%~i

	set i%T=!Sum%T:*.=!0!Sum%T:~0,%P!
        For %I in ("!Sum%T:*.=!") do if not "%~I" == "!Sum%T!" set i%T=!Sum%T:.%~I=!!i%T:~0,1!!i%T:~1,%P!
	
	for /f "tokens=* delims=0" %z in ("!i%T!") do set /a "i%T=(%z+5)/10"

    )
		set Div.acc=1!Sum1:~0,%P!

		if "!Mode!" equ "/" (
			set /a Total=!i1!*!Div.acc!/!i2!
		) else (
		 if "!Mode!" equ "*" (
			set /a Total=!i1!*!i2!/!Div.acc!
		 ) else set /a Total=!i1!!Mode!!i2!
		)
		
		If !total! geq 0 (
			set /a "Int=Total/Div.acc, Float=Total % Div.acc"
		) else  set /a "Int=Total/Div.acc, Float=-(Total % Div.acc)"

		set Float=!Sum1:~0,%P!!Float!
		set Float=!Float:~-%P!
)
!DBG!echo;%1 %2 %3 : !Int!.!Float!
</Function=Calc>

and have adding a variable DBG (debug) for testing and this is the code changed from label ":sub"

:sub
Rem Some functional Tests:

set "DBG=" & rem debug var

%calc% 0 + 0
%calc% . + 1
%calc% . + .
%calc% 1 + 0
%calc% .03 / .5
%calc% 2.2 + 2.2
%calc% 8.888 + 0.82000
%calc% 120.523 * 2.21
%calc% 99.5 + 100.012
%calc% 14797.109 - 15213.132

%calc% 25586.17 * 13697.27
%calc% 3151.277 * 567.607

%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% !random!.!Random:~0,3! - !random!.!Random:~0,3!
%calc% !random!.!Random:~0,3! * !random!.!Random:~0,3!
%calc% !random!.!Random:~0,3! / !random!.!Random:~0,3!

pause

Rem Performance Tests:

set "DBG=rem "

set N_CYCLES=300
set t0=!time!

for /l %%a in (1,1,!N_CYCLES!) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%calc% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
%calc% 8.08 + .08
%calc% 9.09 + .09
)

for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_CYCLES%*10*1000/a"

echo Elapsed:%a% centiseconds - Flops:%FLOPS:~0,-1%.%FLOPS:~-1%


Rem With BURST MODE

::BURST MODE ON
(setlocal & for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="

set "DBG=rem "

set t0=!time!

for /l %%a in (1,1,%N_CYCLES%) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%calc% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
%calc% 8.08 + .08
%calc% 9.09 + .09
)


for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_CYCLES%*10*1000/a"

echo [BURST MODE] Elapsed:!a! centiseconds - Flops:!FLOPS:~0,-1!.!FLOPS:~-1!

endlocal)
::BURST MODE OFF

pause
exit /b

how you see have changed the variable N_OPS in cycles. Every cycle/loop there are 10 FP ops.
And have added a BURST MODE operation that will be good during the optimization of the performance
But now is already good.

my result:

0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.523 * 2.21 : 266.34
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59
3151.277 * 567.607 : 70711.12
30105.103 + 1901.152 : 32006.25
17334.123 - 17737.324 : -403.20
31474.253 * 20945.240 : -41759.86
1955.228 / 3125.317 : 0.62
Premere un tasto per continuare . . .
Elapsed:550 centiseconds - Flops:545.4
[BURST MODE] Elapsed:481 centiseconds - Flops:623.7
Premere un tasto per continuare . . .

can you post functional & performance results? thanks.


einstein1969

Last edited by einstein1969 (25 Mar 2014 15:54)

Offline

#9 25 Mar 2014 16:52

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: Problems with decimal point in my calculator program

I don't have accuracy information about how time takes to complete 'x' op's with a executable
But I know more or less how time takes:

Via cscript:

For /L %%# in (1,1,100) do (
for /f "Delims=" %%a in ('cscript.exe //nologo calc.vbs') Do set Res=%%a
)

Each initialization of cscript takes ~50 to 70 milliseconds
Now multiply this by 100 times: 50 * 100 = 5000 milliseconds = 5 seconds

Now, by via dll/exe (these dll files are renamed from exe file, doesn't have 'magic'), depends very much the
performance to source code:
Each init takes ~30 to 40 milliseconds
Multiply 30 by 100 is equal to 3000 milliseconds = 3 secs.

And via 'calc' function
Each init takes ~5 to 15 ms.
Multiply 5 by 300 FP op's takes 1500 ms = 1.5 secs !!!

The 'calc' function is aprox 75% more faster than cscript!
And 50% more faster than call to exe/dll program!!!
(time calculated respect to time, not Fp op's)


I think that set Type to 'nul' value isn't necessary.
My result are:

Presione una tecla para continuar . . .
0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.523 * 2.21 : 266.34
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59
3151.277 * 567.607 : 70711.12
4756.144 + 27841.940 : 32598.08
27182.210 - 11883.252 : 15298.96
6561.125 * 20095.163 : -8538.85
28823.283 / 9868.318 : 2.92
Presione una tecla para continuar . . .
Elapsed:461 centiseconds - Flops:650.7
[BURST MODE] Elapsed:427 centiseconds - Flops:702.5
Presione una tecla para continuar . . .

.::{Honguito98}::.

Offline

#10 25 Mar 2014 17:05

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

ImATootsieRollPOP wrote:

Hey Honguito98, I don't think this has to be this complicated. (Sorry if I'm not very good at what you guys are doing.)
I think you could just use this script, though I'm not sure it would work with decimals.





@Echo off
set Answer=0
cls

:calc
set /p problem=Please enter the full math problem:
set /a problem=%problem%
set answer=%problem%
goto answer

:answer
cls
echo Your answer is: %answer%
echo.
pause
goto calc






Like I said, Sorry if that doesn't meet up with what you usually do, or doesn't support decimals. I'm still not a pro with coding like you guys do.

Hope it helped.

Regards,
Andrew

Thanks Andrew for your solution. For integer number this work very well and is very simple!

You will not believe but it might come in handy for this project that is a bit more complex.

I'll explain why:

This project transforms all real numbers to integers and for the operations of addition and subtraction performs almost the same code that you have posted.

try this:

@Echo off
set Answer=0
cls

:calc
set /p problem=Please enter the full math problem:
set /a problem=%problem:.=%
set answer=%problem%
goto answer

:answer
cls
echo Your answer is: %answer:~0,-1%.%answer:~-1%
echo.
pause
goto calc

and try this problem :

3.4+5.7-2.2

einstein1969

Offline

#11 25 Mar 2014 23:11

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito98!

Thanks for the previus information about timing!!! I appreciate.

I have implemented the karatsuba's multiply. I have not done deep testing. I have not optimized for performance.

For now will print old result and new [KARATSUBA] result for multiply operations.

The max value before are about 99,99 * 99,99.

Now work with every value from 0 to " 32768.99 " or even more.

The karatsuba for now work with precision of 2 decimal digit. The Rounding not work well, but for INPUT with precision of 2 digit the rounding isn't abilitated because work on third digit after the comma.

ie For multiply operations use yyyyyy.xx format for prec=2 or yyyyy.zzz for prec=3 (i have not tested prec=3)

This is the new code:

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
set prec=2
For %P in (!prec!) do (

    For %T in (1;2) Do (

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set Sum%T=0000000000%~f%~g%~h%~i

	set i%T=!Sum%T:*.=!0!Sum%T:~0,%P!

        For %I in ("!Sum%T:*.=!") do if not "%~I" == "!Sum%T!" set i%T=!Sum%T:.%~I=!!i%T:~0,1!!i%T:~1,%P!

	for /f "tokens=* delims=0" %z in ("!i%T!") do set /a "i%T=(%z+5)/10"

    )
		set Div.acc=1!Sum1:~0,%P!

		if "!Mode!" equ "/" (
			set /a Total=!i1!*!Div.acc!/!i2!
		) else (
		 if "!Mode!" equ "*" (
			set /a Total=!i1!*!i2!/!Div.acc!

			rem Karatsuba: work with only 2 decimal for now. Need functional test. No Round!
			set /a "ac=(!i1:~0,-4!+0)*(!i2:~0,-4!+0), bd=!i1:~-4!*!i2:~-4!, KFloat=(10000/Div.acc*((!i1:~0,-4!+!i1:~-4!)*(!i2:~0,-4!+!i2:~-4!)-ac-bd)+bd/Div.acc) % Div.acc"
			set /a "KInt=100000000/Div.acc/Div.acc*ac+10000/Div.acc/Div.acc*(((!i1:~0,-4!+0)+!i1:~-4!)*((!i2:~0,-4!+0)+!i2:~-4!)-ac-bd)+bd/Div.acc/Div.acc"
			If !KInt! lss 0 set /a KFloat=-KFloat
			set KFloat=!Sum1:~0,%P!!KFloat!
			set KFloat=!KFloat:~-%P!

		 ) else set /a Total=!i1!!Mode!!i2!
		)

		If !total! geq 0 (
			set /a "Int=Total/Div.acc, Float=Total % Div.acc"
		) else  set /a "Int=Total/Div.acc, Float=-(Total % Div.acc)"

		set Float=!Sum1:~0,%P!!Float!
		set Float=!Float:~-%P!

)

if "!Mode!" equ "*" (!DBG!echo;%1 %2 %3 : !Int!.!Float!  [KARATSUBA] : !KInt!.!KFloat!
) else !DBG!echo;%1 %2 %3 : !Int!.!Float!
</Function=Calc>

and have changed and added some functional test in the beginning:

:sub
Rem Some functional Tests:

set "DBG=" & rem debug var

%calc% 0 + 0
%calc% . + 1
%calc% . + .
%calc% 1 + 0
%calc% .03 / .5
%calc% 2.2 + 2.2
%calc% 8.888 + 0.82000
%calc% 120.52 * 2.21
%calc% 99.5 + 100.012
%calc% 14797.109 - 15213.132

%calc% 25586.17 * 13697.27
%calc% 3151.27 * 567.60

%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% !random!.!Random:~0,3! - !random!.!Random:~0,3!
%calc% !random!.!Random:~0,2! * !random!.!Random:~0,2!
%calc% !random!.!Random:~0,3! / !random!.!Random:~0,3!

%calc% 999.99 * 999.99
%calc% 13 * 14.00
%calc% 32768.99 * 32768.99

pause

result:

0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.52 * 2.21 : 266.34  [KARATSUBA] : 266.34
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59  [KARATSUBA] : 350460678.75
3151.27 * 567.60 : 70673.93  [KARATSUBA] : 1788660.85
220.160 + 18710.258 : 18930.42
2641.267 - 30378.233 : -27736.96
9659.13 * 1303.75 : 137685.57  [KARATSUBA] : 12581306.59
29125.317 / 27256.223 : 1.06
999.99 * 999.99 : 140986.54  [KARATSUBA] : 999980.00
13 * 14.00 : 182.00  [KARATSUBA] : 182.00
32768.99 * 32768.99 : 64881.62  [KARATSUBA] : 1073806705.62
Premere un tasto per continuare . . .
Elapsed:711 centiseconds - Flops:421.9
[BURST MODE] Elapsed:612 centiseconds - Flops:490.1
Premere un tasto per continuare . . .

It would be necessary to test extensively and eventually make a part that compares with values calculated using the cscript for example.

Also, we should try as deal with negative numbers.

EDIT: I have posted a parzial code. I have correct!

einstein1969

Last edited by einstein1969 (26 Mar 2014 00:08)

Offline

#12 27 Mar 2014 16:52

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: Problems with decimal point in my calculator program

Well, speeds seems slowdowns, but now we can multiply numbers with more than 32-bit of precission!.
I think that this slowdonw is only caused when is multiplied a number greater than... for example: 999.99 by 999.99

Edit: for get more speed, why not add an conditional, if !i1! geq 99999 if !i2! gtr 21399 do the Karatsuba algorithm.

Edit 2: fails the multilpication: %calc% 999.99 * 200.99, fails on Karatsuba algorithm:

0 + 0 : 0.00
Número no válido . Las constantes numéricas son decimales(17),
hexadecimales (0x11), u octales (021).
Número no válido . Las constantes numéricas son decimales(17),
hexadecimales (0x11), u octales (021).
999.99 * 200.99 : 200987.99  [KARATSUBA] : .00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.52 * 2.21 : 266.34  [KARATSUBA] : 266.34
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59  [KARATSUBA] : 350460678.75
3151.27 * 567.60 : 70673.93  [KARATSUBA] : 1788660.85
16333.138 + 31913.204 : 48246.34
14095.876 - 29912.806 : -15816.93
23410.19 * 20989.18 : 16433.08  [KARATSUBA] : 491360691.74
24979.316 / 11447.165 : 2.18
999.99 * 999.99 : 140986.54  [KARATSUBA] : 999980.00
13 * 14.00 : 182.00  [KARATSUBA] : 182.00
32768.99 * 32768.99 : 64881.62  [KARATSUBA] : 1073806705.62
Presione una tecla para continuar . . .

My speed test:

0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.52 * 2.21 : 266.34  [KARATSUBA] : 266.34
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59  [KARATSUBA] : 350460678.75
3151.27 * 567.60 : 70673.93  [KARATSUBA] : 1788660.85
12417.438 + 10276.439 : 22693.88
456.192 - 867.116 : -410.93
17885.17 * 1720.31 : -155727.72  [KARATSUBA] : 30768036.80
22547.172 / 10661.313 : 2.11
999.99 * 999.99 : 140986.54  [KARATSUBA] : 999980.00
13 * 14.00 : 182.00  [KARATSUBA] : 182.00
32768.99 * 32768.99 : 64881.62  [KARATSUBA] : 1073806705.62
Presione una tecla para continuar . . .
Elapsed:614 centiseconds - Flops:488.5
[BURST MODE] Elapsed:559 centiseconds - Flops:536.6
Presione una tecla para continuar . . .

I get surprised with these modifications! I think with this, maybe is possible make a batch game that uses basic '3D' graphics!!! big_smile


.::{Honguito98}::.

Offline

#13 28 Mar 2014 03:12

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito98!

I have done some test with IF but the speed do not change!

I have tested with your condition and with this always false condition:

If 1==0 (
karatsuba
...
)

but the speed is the same. ??????

Seem that the lenght of the macro (number of char and not operation done) slowdown . Even in Burstmode!

I think that there is some work to do on the mechanism of the macro. But i don't know how this work.

But .... I have found a solution for the moment. The speed is little better of last.

I have create another macro. I have nominate KAR (Calc.kar or Calc_kar seem do not work). I prefer Math.calc; Math.Kar; Math.xxx; etc. It is possible?

I have patched the last problem of karatsuba.

The new macros:

<Function=Calc|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
set prec=2
For %P in (!prec!) do (

    For %T in (1;2) Do (

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set Sum%T=0000000000%~f%~g%~h%~i

	set i%T=!Sum%T:*.=!0!Sum%T:~0,%P!
        For %I in ("!Sum%T:*.=!") do if not "%~I" == "!Sum%T!" set i%T=!Sum%T:.%~I=!!i%T:~0,1!!i%T:~1,%P!
	
	for /f "tokens=* delims=0" %z in ("!i%T!") do set /a "i%T=(%z+5)/10"

    )
	set Div.acc=1!Sum1:~0,%P!

	if "!Mode!" equ "/" (
		set /a Total=!i1!*!Div.acc!/!i2!
	) else (
	 if "!Mode!" equ "*" (
		set /a Total=!i1!*!i2!/!Div.acc!
	 ) else set /a Total=!i1!!Mode!!i2!
	)
		
	If !total! geq 0 (
		set /a "Int=Total/Div.acc, Float=Total % Div.acc"
	) else  set /a "Int=Total/Div.acc, Float=-(Total % Div.acc)"

	set Float=!Sum1:~0,%P!!Float!
	set Float=!Float:~-%P!
)
!DBG!echo;%1 %2 %3 : !Int!.!Float!
</Function=Calc>

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
::  P=precision , number of digit after decimal point
::  DA=Div.acc  , contain a number that is 100 for prec=2 ora 1000 for prec=3 etc.
::		  ex division accurancy.
::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
<Function=Kar|2>
set Sum1=%1
set Mode=%2
set Sum2=%3
set P=2
For %P in (!P!) do (

    For %T in (1;2) Do (

	for /f tokens^=1-4^ delims^=+^"^  %f in ("!Sum%T!") do set Sum%T=0000000000%~f%~g%~h%~i

	set i%T=!Sum%T:*.=!0!Sum%T:~0,%P!

        For %I in ("!Sum%T:*.=!") do if not "%~I" == "!Sum%T!" set i%T=!Sum%T:.%~I=!!i%T:~0,1!!i%T:~1,%P!

	for /f "tokens=* delims=0" %z in ("!i%T!") do set /a "i%T=(%z+5)/10"

    )

    set DA=1!Sum1:~0,%P!

    set /a "a=(!i1:~0,-4!+0), b=1!i1:~-4!-(11!i1:~-4!-1!i1:~-4!)/10, c=(!i2:~0,-4!+0), d=1!i2:~-4!-(11!i2:~-4!-1!i2:~-4!)/10, KFloat=(10000/DA*((a+b)*(c+d)-a*c-b*d)+b*d/DA) % DA, KInt=100000000/DA/DA*a*c+10000/DA/DA*((a+b)*(c+d)-a*c-b*d)+b*d/DA/DA"
    If !KInt! lss 0 set /a KFloat=-KFloat
    set KFloat=!Sum1:~0,%P!!KFloat!
    set KFloat=!KFloat:~-%P!
)
!DBG!echo;%1 %2 %3 : !KInt!.!KFloat!			[KAR.]
</Function=Kar>

Then the "bootstrap" of the automacro

	Set Macros=Calc;Kar;

I like your work on automacro!!!!!

then i have added some functional test on karatsuba and a performance test on only karatsuba
This is the code changed from label :sub

:sub

Rem Some functional Tests:

set "DBG=" & rem debug var

%calc% 999.99 * 200.99
%kar% 999.99 * 200.99

%calc% 0 + 0
%calc% . + 1
%calc% . + .
%calc% 1 + 0
%calc% .03 / .5
%calc% 2.2 + 2.2
%calc% 8.888 + 0.82000
%calc% 120.52 * 2.21
%kar% 120.52 * 2.21
%calc% 99.5 + 100.012
%calc% 14797.109 - 15213.132

%calc% 25586.17 * 13697.27
%kar% 25586.17 * 13697.27
%calc% 3151.27 * 567.60
%kar% 3151.27 * 567.60

%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% !random!.!Random:~0,3! - !random!.!Random:~0,3!
%calc% !random!.!Random:~0,2! * !random!.!Random:~0,2!
%kar% !random!.!Random:~0,2! * !random!.!Random:~0,2!
%calc% !random!.!Random:~0,3! / !random!.!Random:~0,3!

%calc% 999.99 * 999.99
%kar% 999.99 * 999.99
%calc% 13 * 14.00
%kar% 13 * 14.00
%calc% 32768.99 * 32768.99
%kar% 32768.99 * 32768.99

%kar% !random!.!Random:~0,2! * !random!.!Random:~0,2!
%kar% 992.95 * 100.85
%kar% 992.95 * 100.05
%kar% 25 * 1000.05
%kar% 16789.2 * 3.5
%kar% 5.05 * .05
%kar% .03 * .5
%kar% 09 * 08080
%kar% 8.08 * .08
%kar% 9.09 * .09

pause

Rem Performance Tests:

set "DBG=rem "

set N_CYCLES=300
set t0=!time!

for /l %%a in (1,1,!N_CYCLES!) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%kar% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
%calc% 8.08 + .08
%calc% 9.09 + .09
)

for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_CYCLES%*10*1000/a"

echo Elapsed:%a% centiseconds - Flops:%FLOPS:~0,-1%.%FLOPS:~-1%

Rem Test Karatsuba only

set t0=!time!

for /l %%a in (1,1,!N_CYCLES!) Do (
%kar% !random!.!Random:~0,2! * !random!.!Random:~0,2!
%kar% 992.95 * 100.85
%kar% 992.95 * 100.05
%kar% 25 * 1000.05
%kar% 16789.2 * 3.5
%kar% 5.05 * .05
%kar% .03 * .5
%kar% 09 * 08080
%kar% 8.08 * .08
%kar% 9.09 * .09
)

for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_CYCLES%*10*1000/a"

echo Elapsed:%a% centiseconds - Flops:%FLOPS:~0,-1%.%FLOPS:~-1% [KAR.]

Rem With BURST MODE

::BURST MODE ON
(setlocal & for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="

set "DBG=rem "

set t0=!time!

for /l %%a in (1,1,%N_CYCLES%) Do (
%calc% !random!.!Random:~0,3! + !random!.!Random:~0,3!
%calc% 992.95 + 100.85
%calc% 992.95 - 100.05
%kar% 25 * 1000.05
%calc% 1.2 / 3.5
%calc% 5.05 + .05
%calc% .03 / .5
%calc% 09 / 08
%calc% 8.08 + .08
%calc% 9.09 + .09
)

rem set

for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, FLOPS=%N_CYCLES%*10*1000/a"

echo Elapsed:!a! centiseconds - Flops:!FLOPS:~0,-1!.!FLOPS:~-1! [BURST MODE]

endlocal)
::BURST MODE OFF

This is the result:

999.99 * 200.99 : 200987.99
999.99 * 200.99 : 200987.99                     [KAR.]
0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.52 * 2.21 : 266.34
120.52 * 2.21 : 266.34                  [KAR.]
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59
25586.17 * 13697.27 : 350460678.75                      [KAR.]
3151.27 * 567.60 : 70673.93
3151.27 * 567.60 : 1788660.85                   [KAR.]
12082.185 + 20749.282 : 32831.47
5305.318 - 29429.236 : -24123.92
4201.14 * 27637.19 : 143587.40
30885.71 * 18469.12 : 570431884.27                      [KAR.]
20964.478 / 1099.912 : 19.06
999.99 * 999.99 : 140986.54
999.99 * 999.99 : 999980.00                     [KAR.]
13 * 14.00 : 182.00
13 * 14.00 : 182.00                     [KAR.]
32768.99 * 32768.99 : 64881.62
32768.99 * 32768.99 : 1073806705.62                     [KAR.]
30898.29 * 10235.16 : 316248941.87                      [KAR.]
992.95 * 100.85 : 100139.00                     [KAR.]
992.95 * 100.05 : 99344.64                      [KAR.]
25 * 1000.05 : 25001.25                 [KAR.]
16789.2 * 3.5 : 58762.20                        [KAR.]
5.05 * .05 : 0.25                       [KAR.]
.03 * .5 : 0.01                 [KAR.]
09 * 08080 : 72720.00                   [KAR.]
8.08 * .08 : 0.64                       [KAR.]
9.09 * .09 : 0.81                       [KAR.]
Premere un tasto per continuare . . .
Elapsed:603 centiseconds - Flops:497.5
Elapsed:572 centiseconds - Flops:524.4 [KAR.]
Elapsed:486 centiseconds - Flops:617.2 [BURST MODE]

The karabutsa is more speedy of the other!!!!
The Burstmode speed is high!

I'll let you surprise ...

Guess what is it?

@echo off

set /a "x=4000, g0=2*10+1, z0=g0=(g0+x/g0)/2, z1=g0=g0*(g0*g0+3*x)/((3*g0*g0+x)), g0=g0*(g0*g0+3*x)/((3*g0*g0+x)), g1=g0*(g0*g0+3*x*1)*100/((3*g0*g0+x*1))"

echo %g1%

play with this smile

einstein1969

Last edited by einstein1969 (28 Mar 2014 03:22)

Offline

#14 28 Mar 2014 17:11

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: Problems with decimal point in my calculator program

AutoMacro: I think that these names of variables or functions that includes fails with FindStr, which this be 'confused' and the dot is taken as wildcard.

The calc is more speedy!
My tests are:

Presione una tecla para continuar . . .
999.99 * 200.99 : 200987.99
999.99 * 200.99 : 200987.99                     [KAR.]
0 + 0 : 0.00
. + 1 : 1.00
. + . : 0.00
1 + 0 : 1.00
.03 / .5 : 0.06
2.2 + 2.2 : 4.40
8.888 + 0.82000 : 9.71
120.52 * 2.21 : 266.34
120.52 * 2.21 : 266.34                  [KAR.]
99.5 + 100.012 : 199.51
14797.109 - 15213.132 : -416.02
25586.17 * 13697.27 : -8652.59
25586.17 * 13697.27 : 350460678.75                      [KAR.]
3151.27 * 567.60 : 70673.93
3151.27 * 567.60 : 1788660.85                   [KAR.]
6375.137 + 20219.117 : 26594.26
25202.240 - 8435.614 : 16766.63
15818.16 * 25288.28 : 152603.90
25832.76 * 9045.70 : 233675397.13                       [KAR.]
2962.684 / 21445.107 : 0.13
999.99 * 999.99 : 140986.54
999.99 * 999.99 : 999980.00                     [KAR.]
13 * 14.00 : 182.00
13 * 14.00 : 182.00                     [KAR.]
32768.99 * 32768.99 : 64881.62
32768.99 * 32768.99 : 1073806705.62                     [KAR.]
17527.31 * 30028.28 : 526314972.32                      [KAR.]
992.95 * 100.85 : 100139.00                     [KAR.]
992.95 * 100.05 : 99344.64                      [KAR.]
25 * 1000.05 : 25001.25                 [KAR.]
16789.2 * 3.5 : 58762.20                        [KAR.]
5.05 * .05 : 0.25                       [KAR.]
.03 * .5 : 0.01                 [KAR.]
09 * 08080 : 72720.00                   [KAR.]
8.08 * .08 : 0.64                       [KAR.]
9.09 * .09 : 0.81                       [KAR.]
Presione una tecla para continuar . . .
Elapsed:477 centiseconds - Flops:628.9
Elapsed:442 centiseconds - Flops:678.7 [KAR.]
Elapsed:425 centiseconds - Flops:705.8 [BURST MODE]
Presione una tecla para continuar . . .

I trying to find a way to increase the speed modify a little AutoMacro, and this make an automatic search of functions.

And the last code: I don't know, I bad for maths, I think that is an algorithm for get a result of something, like get the cosine of x number.


.::{Honguito98}::.

Offline

#15 31 Mar 2014 20:56

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito!

I have reading your algos and i see that is very good. It separates the int and float parts and might be more accurate than previous.

I'm arrived at this part and is not clear how RLNG is calculated. The conditions that choose the contents are a bit confusing for me.

	If !S1Float.Lng! Equ !S2Float.Lng! (Set RLng=!S1Int.Lng!) Else (Set RLng=1)

	Rem Floating Point Range Adjust
	If !S1Float.Lng! Gtr !S2Float.Lng! (
		Set/a "Cr.Lng=S1Float.Lng - S2Float.Lng"
		For /L %R in (1,1,!Cr.Lng!) Do Set Sum2.Float=!Sum2.Float!0
		Set/a RLng=!S1Int.Lng!
	)
	If !S2Float.Lng! Gtr !S1Float.Lng! (
		Set/a "Cr.Lng=S2Float.Lng - S1Float.Lng"
		For /L %R in (1,1,!Cr.Lng!) Do Set Sum1.Float=!Sum1.Float!0
		Set/a RLng=!S2Int.Lng!
	)

	If !S1Int.Lng! Gtr !S2Int.Lng! Set RLng=!S1Int.Lng!
	If !S2Int.Lng! Gtr !S1Int.Lng! Set RLng=!S2Int.Lng!

If you could clarify this part fix the rest better!

Ps. the previous code is not sin(x) or cos(x) but SQRT(x). I have worked for sin and cos. You can found in this thread.

Sqrt(40.00) = 6.324 :

set /a "x=4000, g0=2*10+1, z0=g0=(g0+x/g0)/2, z1=g0=g0*(g0*g0+3*x)/((3*g0*g0+x)), g0=g0*(g0*g0+3*x)/((3*g0*g0+x)), g1=g0*(g0*g0+3*x*1)*100/((3*g0*g0+x*1))"
6324

einstein1969

Last edited by einstein1969 (31 Mar 2014 21:32)

Offline

#16 31 Mar 2014 22:01

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: Problems with decimal point in my calculator program

Hi Honguito98,

for sin and cos this code is very fast alternative if you want get a circle/elliptical and square path:

A demo that work with no accelerators:

@echo off&setlocal EnableDelayedExpansion

set /a cols=140, lines=54
cls

pushd "%temp%"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
For /L %%c in (1,1,%cols%) do set "str_findstr=!str_findstr!L"
For /L %%l in (1,1,%cols%) do <nul set /p .=%BS%> "!str_findstr:~0,%%l!"
set Col=123456789abcdef

rem this parameter control the eccentrip and rotational speed. Use 2^x=2, 4 ,8 etc
set /a "e=10000/4" & rem 1.0000/4

rem start point
set /a y=20, x=40

rem center point
set /a offsetx=70, offsety=25

for /L %%i in (1,1,10000) do (
 mode %cols%,%lines%
 set /a "x=x-e*y/10000, y=y+e*x/10000, cx=x+offsetx, cy=y/2+offsety, e=10000/(4+%%i/100), color=(x^y) %% 15"
 For /L %%y in (1,1,!cy!) do echo(
 <nul set /p "=%BS%  " 
 for %%N in (!cx!) do for %%c in (!color!) do call :ColorText_bg_BS !col:~%%c,1! %%N
)

popd
goto :eof

:ColorText_bg_BS bg_color len [/n]
(
  set /a "len=%2-1"
  if %1 equ 0 (set fg=1) else set fg=%1
  if !len! geq 1 for %%. in (!len!) do  findstr /v /a:%1!fg! /R "^$" "!str_findstr:~0,%%.!" nul
  if /i "%~3"=="/n" echo(
goto :eof
)

EDIT: This show the x path better:

@echo off&setlocal EnableDelayedExpansion

set /a cols=150, lines=60
cls
mode %cols%,%lines%

pushd "%temp%"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
For /L %%c in (1,1,%cols%) do set "str_findstr=!str_findstr!L"
For /L %%l in (1,1,%cols%) do <nul set /p .=%BS%> "!str_findstr:~0,%%l!"
set Col=123456789abcdef


rem this parameter control the eccentrip and rotational speed. Use 2^x=2, 4 ,8 etc
set /a ecc=2

rem start point
set /a y=20, x=40

rem center point
set /a offsetx=70, offsety=25

for /L %%i in (1,1,10000) do (
 if %%i gtr !step! (set /a "color=(color+1) %% 15, step+=200" & for %%c in (!color!) do color !col:~%%c,1!0 )
 set /a "x=x-e*y/10000, y=y+e*x/10000, cx=x+offsetx, cy=y/2+offsety, e=10000/(ecc+%%i/100)"
 echo(
 for %%x in (!cx!) do findstr /v /a:10 /R "^$" "!str_findstr:~0,%%x!" nul
 )
)

popd
goto :eof

einstein1969

Last edited by einstein1969 (01 Apr 2014 01:35)

Offline

Board footer

Powered by FluxBB