Carpet

Carpet

2M Downloads

% acts as a remainder operator and not a modulo operator

rv3r opened this issue ยท 3 comments

commented

The % operator, according to the docs, return the modulus of a number. However, given that the example -9 % 4 => -1 is shown in the docs, it appears to be acting as a remainder operator similar to what it does in Java. This is confirmed by in-game testing.

I can think of three possible ways to amend this.

  1. (easiest) Rename it to 'remainder operator' in the docs.
  2. (more work to fix, but my preference) Make it function like a modulus operator: -9 % 4 => 3
  3. (worst option) Have two separate operators, one for remainder and the other for modulus
commented

I am in favour of no. 2 as well. Will change the semantics, but I doubt if Java's reminder has any use for anybody.

commented

Yeah i agree, never needed remainder functionality, so for cases where i needed modulos and negative values matter, i always had to do something like mod(x,y) -> (x%y+y)%y to make it work as modulos

commented