@echo off :loop set/p ch= give 2 numbers one after another : for /f "tokens=1,2" %%G in ("%ch%") do (set left=%%G&set right=%%H) call:LargeInt_cmp left right if "%errorlevel%"=="0" (echo Left is greater.) if "%errorlevel%"=="1" (echo Equal to each other.) if "%errorlevel%"=="2" (echo Right is greater.) if "%errorlevel%"=="3" (echo Invalid input.) echo. goto loop :LargeInt_cmp ::returns :: :: ERRORLEVEL :: 0 = left is greater :: 1 = equal :: 2 = right is greater :: 3 = invalid input :: setlocal set v0=%% %1 %% set v0=%v0: =% call set left=%v0% set v0=%% %2 %% set v0=%v0: =% call set right=%v0% if not defined left (endlocal&&exit/b3) if not defined right (endlocal&&exit/b3) call:IsInteger left||endlocal&&exit/b3 call:IsInteger right||endlocal&&exit/b3 set left_IsNegative=false set right_IsNegative=false if "%left:~0,1%"=="-" (set left_IsNegative=true) if "%right:~0,1%"=="-" (set right_IsNegative=true) set cond_gtr=GTR set cond_lss=LSS if "%left_IsNegative%"=="true" ( if "%right_IsNegative%"=="false" ( goto right_is_greater ) ) if "%left_IsNegative%"=="false" ( if "%right_IsNegative%"=="true" ( goto left_is_greater ) ) if "%left_IsNegative%"=="true" ( if "%right_IsNegative%"=="true" ( set cond_gtr=LSS set cond_lss=GTR ) ) call:strlen %left% set sizeof_left=%errorlevel% call:strlen %right% set sizeof_right=%errorlevel% if %sizeof_left% %cond_gtr% %sizeof_right% ( :left_is_greater endlocal&exit/b0 ) if %sizeof_left% %cond_lss% %sizeof_right% ( :right_is_greater endlocal&exit/b2 ) :wigloop set left_tmp=%left:~0,1% set right_tmp=%right:~0,1% set left=%left:~1% set right=%right:~1% if %left_tmp% %cond_gtr% %right_tmp% (goto left_is_greater) if %right_tmp% %cond_gtr% %left_tmp% (goto right_is_greater) if defined left (goto wigloop) endlocal&exit/b1 :strlen setlocal set param=%1 if not defined param (set length=0&goto strlen_end) :strlen_0 set param=%param:~0,-1% set/a length+=1 if defined param (goto strlen_0) endlocal&exit/b%length% :IsInteger call:IsHex %1 10&&exit/b0||exit/b1 :IsHex setlocal set var=%% %1 %% set var=%var: =% call set var=%var% if "%2"=="10" (if "%var:~0,1%"=="-" (set var=%var:~1%)) else (if "%var:~0,2%"=="0x" (set var=%var:~2%)) set IsHex=0 set var=%var:0= % set var=%var:1= % set var=%var:2= % set var=%var:3= % set var=%var:4= % set var=%var:5= % set var=%var:6= % set var=%var:7= % set var=%var:8= % set var=%var:9= % if "%2"=="10" (goto ishex_) set var=%var:A= % set var=%var:B= % set var=%var:C= % set var=%var:D= % set var=%var:E= % set var=%var:F= % :ishex_ set var=%var: =% if defined var (set IsHex=1) endlocal&exit/b%IsHex%
Oct 12, 2013
Function: LargeInt_cmp
Compares decimal numbers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment