Page 1 of 1
Getting past the 32bit limit
Posted: 26 May 2011 23:02
by Cleptography
Sure this has been asked and explained so I apologize if I am rehashing an old subject. I'm just curious if it has been done or is possible to work with values past the 32-bits of precision.
Code: Select all
@echo off
setlocal
REM This works
set /a val=1000000000+1000000000
echo.%val%
REM Does not work exceeds the 32bit limit
set /a val=10000000000+1000000000
echo.%val%
REM 10000000000
REM + 1000000000
REM --------------
REM 11000000000
Re: Getting past the 32bit limit
Posted: 27 May 2011 05:48
by orange_batch
calc.vbs:
Code: Select all
wscript.echo eval(wscript.arguments(1))
and...
Code: Select all
cscript calc.vbs //nologo "2147483648^2"
Or you can split DOS's 32-bit numbers depending on what you're working with. Mileage varies with the digit you choose to split at. This is faster than the vbscript but has less range:
Code: Select all
set number=987654321
set step=000%number:~-4%
set /a low=1%step:~-4%-10000,high=%number:~,-4%+0
First you pad on one less zero than the number of digits you split at (allows for numbers lower than 1000 when splitting at 4).
Then for
low you put a one before that number truncated (to remove the excess padding) and subtract 10000. This prevents DOS from thinking it's an octal due to the leading zeros.
For
high you add +0 on the end in case
number isn't longer than 4 digits in the first place, to prevent an error.
The math from there is some simpler logic. You can accumulate large numbers simply too, by running this as a function and changing low= and high= to low+= and high+=.