Re: Dos Batch Math Library
Posted: 11 Aug 2014 07:08
Done - post has been edited
Also, abs() of a 32bit integer is trivial to implement. Here is a version.
Also, abs() of a 32bit integer is trivial to implement. Here is a version.
Code: Select all
@echo off
:ABS InExpr [OutVar]
::
:: Compute the absolute value of expression InExpr
:: and store the result in variable OutVar.
:: Write the result to stdout if OutVar not specified.
::
:: InExpr may be a valid SET /A mathematical expression.
::
:: An error is raised if an attempt is made to get the
:: absolute value of the smallest negative integer.
::
setlocal
set /a "rtn=%~1"
set /a "rtn=%rtn:-=%" || exit /b
endlocal & if "%~2" equ "" (echo %rtn%) else set "%~2=%rtn%"
exit /b