# modulo

Claude Pache claude.pache at gmail.com
Mon Sep 16 06:27:01 PDT 2013

```Le 16 sept. 2013 à 15:12, raul mihaila <raul.mihaila at gmail.com> a écrit :

> But if the definition of modulo is correct, then isn't ToInt32 wrong? http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.1.5
> Here, -3 is transformed into 3.

If one follows carefully the algorithm, one has:
* step 4: `int == -3`;
* step 5: `int32bit == 2^32 - 3`;
* step 6 (since `int32bit` ≥ 2^31`): return `int32bit - 2^32 == -3`.
(Note that at no step there is a direct sign change like `-3` into `3` or vice versa; but the value shifts by multiples of `2^32` in order to go into the right interval.)

—Claude

>
> Raul M
>
>
> On Mon, Sep 16, 2013 at 2:40 PM, Claude Pache <claude.pache at gmail.com> wrote:
>
> 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/c31fd00f/attachment.html>
```