modulo

Claude Pache claude.pache at gmail.com
Mon Sep 16 04:40:44 PDT 2013


Le 16 sept. 2013 à 11:30, raul mihaila <raul.mihaila at gmail.com> a écrit :

> Hello,
> 
> I think the definition of modulo is wrong. http://people.mozilla.org/~jorendorff/es6-draft.html#sec-5.2 
> k should be of the same sign as x not as y.

I think the definition is correct, and is more useful than the opposite convention. It is indeed the opposite convention of the one used by the remainder operator (`%` in JS), but it is not the remainder operator. (BTW, is there any chance that the modulo operator [1] will be introduced in EcmaScript, rather sooner than later?)

[1] http://wiki.ecmascript.org/doku.php?id=strawman:modulo_operator

In fact, since `x modulo y` is apparently only use with positive (and integral) `y` in the specification, the definition should be simplified, by restricting to the case where `y` is positive.

> 
> Also, shouldn't ToUint32 and ToUint16 return only positive numbers? If the argument is, for example, -3, the result will be -3 (assuming that the modulo definition is wrong). Or maybe the argument will never be negative?

Assuming the modulo definition is correct, `ToUint32` and `ToUint16` work as expected (if the argument is `-3` the result is `2^32-3`, resp. `2^16-3`.

—Claude


> 
> Raul M
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130916/2c3d00cf/attachment.html>


More information about the es-discuss mailing list