Código optimizado
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
:_addx
setlocal enabledelayedexpansion
set "f_s=_%~1" & set "s_s=_%~2" & set "add_str="
set/a cnt=1,car=0
:__loop.a
set "n_1=!f_s:~-%cnt%,1!"
set "n_2=!s_s:~-%cnt%,1!"
if "%n_1%%n_2%" EQU "__" goto :_endadd
if "%n_1%" EQU "_" set/a n_1=0
if "%n_2%" EQU "_" set/a n_2=0
set/a add=%n_1%+%n_2%+%car%,car=0,cnt+=1
if %add% GEQ 10 (
set/a car=1
if "!f_s:~-%cnt%,1!!s_s:~-%cnt%,1!" NEQ "__" (
set "add=%add:~-1%"
))
set "add_str=%add%%add_str%"
goto :__loop.a
:_endadd
call :_filset "%add_str%" "add_str"
endlocal & set "%~3=%add_str%" & exit /b
:_subx
setlocal enabledelayedexpansion
if "%~1" EQU "%~2" set "sub_str=0" & goto :_endsub
call :_filset "%~1" "t_1" & call :_filset "%~2" "t_2"
call :_hst "%t_1%" "%t_2%"
if "%hst%" EQU "%t_2%" set "min=_%~2" & set "sbs=_%~1" & set "s_g=-"
if "%hst%" EQU "%t_1%" set "min=_%~1" & set "sbs=_%~2"
set "sub_str=" & set/a cnt=1,c_s=0,car=0
:__loop.b
set "n_1=!min:~-%cnt%,1!"
set "n_2=!sbs:~-%cnt%,1!"
if "%n_1%%n_2%" EQU "__" goto :_endsub
if "%n_2%" EQU "_" set/a n_2=0
if "%car%" EQU "1" set/a n_2+=1,car=0
if %n_1% LSS %n_2% set/a c_s=10,car=1
set/a sub=%n_1%-%n_2%+%c_s%
set "sub_str=%sub%%sub_str%"
set/a cnt+=1,c_s=0
goto :__loop.b
:_endsub
call :_filset "%sub_str%" "sub_str"
endlocal & set "%~3=%s_g%%sub_str%" & exit /b
:_filset
for /f "tokens=* delims=0" %%_ in ("%~1") do set "%~2=%%_"
if not defined %~2 set/a "%~2=0"
exit /b
:_hst
setlocal enabledelayedexpansion
call :_strlen "%~1" & set/a n[0]=!errorlevel!
call :_strlen "%~2" & set/a n[1]=!errorlevel!
if %n[0]% EQU %n[1]% set "s_0=%~1" & set "s_1=%~2" & goto :_endhst
set/a hst=0,nhst=1
if %n[1]% GTR !n[%hst%]! set/a hst=1,nhst=0
set/a l_0=!n[%hst%]!-!n[%nhst%]!
shift/0 & call set "s_0=%%~%hst%" & call set "s_1=%%~%nhst%"
for /l %%_ in (1,1,%l_0%) do call set "s_1=0!s_1!"
:_endhst
for /f %%_ in ('"(echo:%s_0%&echo:%s_1%)|sort"') do set "hst=%%_"
endlocal & set "hst=%hst%" & exit /b
:_strlen
setlocal
set/a cnt=0
for /f "tokens=* eol=" %%_ in (
'"cmd /u /c echo:%~1|more"'
) do set/a cnt+=1
endlocal & exit /b %cnt%
call :_addx "sum1" "sum2" "variable_almacén"
call :_subx "min" "sbs" "variable_almacén"
@Echo Off
more/c<nul
echo: 125504500255796221456988250471037
echo:- 47662554011498822047690014
echo:-------------------------------------
call :_subx "125504500255796221456988250471037" "47662554011498822047690014" "rslt"
echo: %rslt%
pause>nul & exit
call :_calc add|sub "operación" "variable"
echo. %variable%
@echo off
echo ingrese primer numero
set /p "a="
echo ingrese segundo numero
set /p "b="
call :_calc sub "%a%-%b%" "adt"
echo. Resultado de la resta: %adt%
pause > nul
exit
@Echo Off
more/c<nul
call :_calc sub "12.72-8.189605-1.0025" "adt"
call :_calc add "%adt%+521.27+5" "adt"
echo: 12.72 - 8.189605 - 1.0025 + 521.27 + 5 = %adt%
pause 1>nul
exit
:_calc
setlocal enabledelayedexpansion
if "%~1" EQU "add" set "sym=+"
if "%~1" EQU "sub" set "sym=-"
set "add_str=%~2"
set "add_str=!add_str:%sym%= !"
set/a hst=0,cnt=0,add=0
for %%_ in (%add_str%) do (
set/a dec[!cnt!]=0
for /f "tokens=2 delims=." %%. in ("%%_") do (
call :_strlen "%%."
set/a dec[!cnt!]=!errorlevel!
if !errorlevel! GTR !hst! set/a hst=!errorlevel!
)
set/a cnt+=1
)
set/a cnt=0
if "%sym%" EQU "-" for %%_ in (%add_str:.=%) do (
set/a pow=%hst%-%dec[0]%,n_b=%%_
for /l %%. in (1,1,!pow!) do set "n_b=!n_b!0"
set/a add+=!n_b!*2
goto :__op
)
:__op
for %%_ in (%add_str:.=%) do (
call set/a pow=%hst%-%%dec[!cnt!]%%,n_b=%%_
for /l %%. in (1,1,!pow!) do set "n_b=!n_b!0"
set/a add%sym%=!n_b!,cnt+=1
)
set "res=!add:~0,-%hst%!.!add:~-%hst%!"
if %hst% EQU 0 set "res=%res:~1%"
endlocal & set "%~3=%res%" & exit /b
:_strlen
setlocal
set/a cnt=0
for /f "tokens=* eol=" %%_ in (
'"cmd /u /c echo:%~1|more"'
) do set/a cnt+=1
endlocal & exit /b %cnt%
:calc
(Echo.%~2=%~1&&Echo.Wscript.StdOut.Write %~2) 1>%temp%\calc.vbs
for /f %%A in ('cscript //nologo %temp%\calc.vbs') do (set "%~2=%%A")
GoTo:EoF
@echo off
call:calc "5.1+5.1" "rslt"
Echo.%rslt%
pause 1>nul&exit/b
:calc
(Echo.%~2=%~1&&Echo.Wscript.StdOut.Write %~2) 1>%temp%\calc.vbs
for /f %%A in ('cscript //nologo %temp%\calc.vbs') do (set "%~2=%%A")
GoTo:EoF