SET /A overflow
Posted: 07 Apr 2014 14:38
Hi to all,
There is a method for detect "programmatically" an overflow for simple expressions?
for example:
This is the complete code:
einstein1969
There is a method for detect "programmatically" an overflow for simple expressions?
for example:
Code: Select all
set /a T=A*B
This is the complete code:
Code: Select all
@echo off & setlocal
rem Tested on windows 7 32bit
rem Tested on positive numbers
:start
Call :input A
Call :input B
Echo(
Echo Calculating %A%*%B%
set /a T=%A%*%B%
Echo Result: %T%
exit /b
:input
rem MAX 2147483647
set "Retry=& pause & goto :input"
set "Out=echo Number exceeds 2147483647 %Retry%"
set Num=
set /p "Num=Insert an integer number>"
if not defined Num set Num=%random%%random% & call echo Random number %%Num%%
(if errorlevel %Num% call ) >nul 2>&1||(Echo Not valid number! %Retry%)
if %Num% geq 2147483647 if not "%Num%"=="2147483647" %Out%
rem if there are other errors...
set /a %1=%Num% 2>nul
if %errorlevel% equ 1073750992 %Out%
set /a %1=Num
exit /b
einstein1969