ECMAScript does not currently have a modulo operator. Instead, it has a remainder operator
%. The result of remainder takes the sign of the dividend, not the divisor, so it does not have the nice limit-and-force-to-the-positive characteristics of modulo. Programs that use remainder in place of modulo are probably in error.
So it proposed that a modulo operator
mod be added. The result of modulo takes the sign of the divisor, not the dividend.
mod keyword is contextual, and backward-compatible only if productions in which it occurs have
here] immediately to the left of
We may want
div too, for integer division. We could even consider
divmod, returning a tuple:
alert(12 divmod 5) // #[2, 2]
— Brendan Eich 2011/02/16 05:15
I like that a lot. Assuming the grammar works out, I think it wins. There are other infix operators that could be added on a similar basis, like
— Douglas Crockford 2011/02/16 23:44
I will write this up later today. The
max cases seem better done via the existing and variadic
Math.max functions than infix operators (e.g.,
0), but we can hash that out elsewhere.
— Brendan Eich 2011/02/28 21:29