whatwg/infra

Define remainder (and/or modulo)

domenic opened this issue · 2 comments

What is the issue with the Infra Standard?

whatwg/streams#1145 wants to use the equivalent of JavaScript's % operator. This is surprisingly subtle because of the difference between modulo and remainder. See discussion in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder .

I suggest the terminology "the [remainder after dividing] |dividend| by |divisor|".

I also suggest that we add a clear note about how this maps to some language's % operator (JavaScript, C, C++) but mismatches others (Python, Perl).

There might also be some subtlety here about rounding toward 0 vs. not?

We should probably delegate the actual definition to https://tc39.es/ecma262/#sec-numeric-types-number-remainder , although I guess ideally we'd figure out #87 first.

/cc @MattiasBuelens

annevk commented

See also https://encoding.spec.whatwg.org/#terminology for some (potentially different) precedent.

whatwg/streams#1145 wants to use the equivalent of JavaScript's % operator. This is surprisingly subtle because of the difference between modulo and remainder.

For Streams, the difference doesn't matter, since we only ever have positive dividends and divisors. From a quick look at Encoding, I think the same applies there.