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?
If you want true modulo, than you can use this:
set a=-90
set b=7
set /a (a%b+b)%b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With