Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMD set /a, modulus, and negative numbers

Is CMD unable to evaluate the modulus of negative numbers using set /a?

90 % 7 correctly equates to 6 in batch, however -90 % 7 gives -6 instead of 1.

I thought that it might have been evaluating -(90 % 7), but this doesn't seem to be the case as (-90) % 7 also gives -6.

h:\uprof>set /a -90%7
-6
h:\uprof>set /a (-90)%7
-6

So - is this a limitation of CMDs set /a Modulus operator?

like image 871
unclemeat Avatar asked Jan 12 '15 01:01

unclemeat


1 Answers

If you want true modulo, than you can use this:

set a=-90
set b=7
set /a (a%b+b)%b
like image 127
user4003407 Avatar answered Sep 20 '22 18:09

user4003407