I type this into google/wolfram alpha:
-15 % 360
and I get 345
.
when I do it in javascript I get -15
https://www.google.com/search?q=-15%20%%20360
I type this into google/wolfram alpha:
-15 % 360
and I get 345
.
when I do it in javascript I get -15
https://www.google.com/search?q=-15%20%%20360
The % (remainder) operator is not "broken" in JavaScript, even though the result may be unexpected - especially with the anticipation of a stricter mathematical modulus operation.
The behavior is well-defined in ECMAScript. See 11.5.3 Applying the % Operator:
The % [remainder] operator yields the remainder of its operands from an implied division; the left operand is the dividend and the right operand is the divisor..
.. the [floating-point] remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n − (d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive ..
In this manner it behaves in the same way as the remainder operator in Java or C# (for integer inputs).
There are arguments that it should be referred to as the remainder operator to avoid such confusion: ES5 does indeed implicitly refer to it as the "remainder operator", but the Mozilla JavaScript Reference calls it the "modulus operator".
See also Modulus operation with negatives values - weird thing?, which actually views the "brokeness" from the other angle.