You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Rust reference 8.2.4, the table explains only that the % operator performs "remainder".
I write video games and I spend a lot of time performing the modulo operation on negative numbers. I get very easily confused about what, and I don't feel I clearly understand from reading 8.2.4 what Rust % would do if one or both operands were negative.
Maybe there are people out there for whom the use of "remainder" rather than "modulo", combined with "Integer division rounds towards zero", would be unambiguous, but I am not one :(
"Expected behavior": It would be nice to have at least a line of text indicating how we should interpret "remainder", in particular in the case of negative operands. It would be even better if the "examples" block with the assert_eqs included some different negative-number examples for %.
I asked about this on Twitter and it was pointed out to me the stdlib entry for numbers is much more explicit. I don't know exactly what your rules are for which things need to be included in the Reference and which should be deferred to the stdlib.
The text was updated successfully, but these errors were encountered:
mcclure
changed the title
I wish it were a little clearer what % does on negative numbers
I wish it were clearer what % does on negative numbers
Mar 12, 2021
notriddle
added a commit
to notriddle/reference
that referenced
this issue
Jul 13, 2021
In Rust reference 8.2.4, the table explains only that the % operator performs "remainder".
I write video games and I spend a lot of time performing the modulo operation on negative numbers. I get very easily confused about what, and I don't feel I clearly understand from reading 8.2.4 what Rust % would do if one or both operands were negative.
Maybe there are people out there for whom the use of "remainder" rather than "modulo", combined with "Integer division rounds towards zero", would be unambiguous, but I am not one :(
"Expected behavior": It would be nice to have at least a line of text indicating how we should interpret "remainder", in particular in the case of negative operands. It would be even better if the "examples" block with the assert_eqs included some different negative-number examples for %.
I asked about this on Twitter and it was pointed out to me the stdlib entry for numbers is much more explicit. I don't know exactly what your rules are for which things need to be included in the Reference and which should be deferred to the stdlib.
The text was updated successfully, but these errors were encountered: