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

Basic arithmetic without overflow-checks undocumented #1729

Open
orlp opened this issue Feb 4, 2025 · 4 comments
Open

Basic arithmetic without overflow-checks undocumented #1729

orlp opened this issue Feb 4, 2025 · 4 comments

Comments

@orlp
Copy link

orlp commented Feb 4, 2025

It is documented what the semantics are of basic arithmetic when overflow-checks is turned on: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow.

However as far as I can see it is nowhere actually specified what arithmetic is supposed to do when overflow-checks is turned off, or whether this is subject to change, hardware specifics, etc.

@mattheww
Copy link
Contributor

mattheww commented Feb 4, 2025

It's mentioned on the "Behavior not considered unsafe" page:

In the case of implicitly-wrapped overflow, implementations must provide well-defined (even if still considered erroneous) results by using two’s complement overflow conventions.

But I think it would be better if the "Operator expressions" page said this.

@orlp
Copy link
Author

orlp commented Feb 4, 2025

@mattheww That does not cover the shift operations.

@mattheww
Copy link
Contributor

mattheww commented Feb 4, 2025

I suspect that the sentence "Remember that signed integers are always represented using two's complement." was intended to convey this information (partly because I can't see what else it's doing there).

But I don't think that's a good way of saying it. It would be better to be more direct.

@mattheww
Copy link
Contributor

mattheww commented Feb 4, 2025

#949 is supposed to track unfinished business of this sort.

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

No branches or pull requests

2 participants