Problem Description
modulus returns incorrect value. ex: -180%360 should return 180, but instead it returns -180.
Attach a Capx
https://1drv.ms/u/s!AhHSZHEulqh_gTrqjJ-vqheM0zLp
Description of Capx
on start sets text to the (-180%360)
Steps to Reproduce Bug
Observed Result
it returns -180.
Expected Result
should return 180
Affected Browsers
Operating System and Service Pack
vista sp2
Construct 2 Version ID
r227
It's not really a bug, it's just doing it how the javascript % does it. Also apparently there isn't a consensus in the computer world what % should exactly do when one of the values is negative. See here, the sign of the result varies depending on the language:
https://en.wikipedia.org/wiki/Modulo_operation
For an always positive remainder you could do one of these:
(a%b+b)%b
a-int(a/b)*b
Develop games in your browser. Powerful, performant & highly capable.
thanks! I didn't realize it was different depending on the language.
Closing as not a bug - most languages I've used treat % as allowing numbers to stay negative, but you can always just add in an abs() if you want different behavior.