CMD set /a, modulus, and negative numbers
If you want true modulo, than you can use this:
set a=-90
set b=7
set /a (a%b+b)%b
The %
in CMD much like in other microsoft environments is a remainder function - not a true modulo operation. The remainder is accurate here to return -6 for your examples. Using mod
in Excel is a true modulo which does return your expected 1.
Although it's written for C#, the article below has a great breakdown of the difference: http://blogs.msdn.com/b/ericlippert/archive/2011/12/05/what-s-the-difference-remainder-vs-modulus.aspx
As Jason W said, %
isn't a modulo operator. But if you want -b mod N, maybe this can help:
@echo off
set /a num1=7
set /a num2=-90
:add
if %num2% LSS 0 set /a num2+=num1&goto add
echo/%num2%
pause