Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I wish it were clearer what % does on negative numbers #978

Closed
mcclure opened this issue Mar 12, 2021 · 0 comments · Fixed by #1073
Closed

I wish it were clearer what % does on negative numbers #978

mcclure opened this issue Mar 12, 2021 · 0 comments · Fixed by #1073

Comments

@mcclure
Copy link
Contributor

mcclure commented Mar 12, 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.

@mcclure 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant