Jan 7, 2013

Function: LargeInt_add

My attempt to work around the 2^31-1 limit in the Command Processor. Works for me. Beta, because I can not say it will work in all cases, give it a try.
@echo off
::script written by Michal Hanebach, Jan 2013
echo  give two big integers to be added : 
set/p first=give first number : 
set/p second=give second number : 
call:LargeInt_add first second first
if "%errorlevel%"=="1" (echo  Too few parameters.) else (echo [%first%])
goto loop
set left=%% %1 %%
set left=%left: =%
call set left=%left%
set right=%% %2 %%
set right=%right: =%
call set right=%right%
if defined left (if defined right (goto lrgintadd))
set exitcode=1
goto lrgintadd_endproc
set buff=
set lastchar_l=
set lastchar_r=
if defined left (set lastchar_l=%left:~-1%)
if defined right (set lastchar_r=%right:~-1%)
if defined carry (set/a buff+=%carry%&set carry=)
if defined lastchar_l (set/a buff+=%lastchar_l%)
if defined lastchar_r (set/a buff+=%lastchar_r%)
if %buff% GTR 9 (
 set outvar=%buff:~-1%%outvar%
 set carry=%buff:~0,1%
) else (
 set outvar=%buff%%outvar%
if defined left (set left=%left:~0,-1%)
if defined right (set right=%right:~0,-1%)
if not defined left (if not defined right (set outvar=%carry%%outvar%&goto lrgintadd_opsucc))
goto lrgintadd
set exitcode=0
endlocal&set %3=%outvar%&exit/b%exitcode%

No comments:

Post a Comment