-
Couldn't load subscription status.
- Fork 13.9k
docs(core): clarify that signed integers use two's complement #147960
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
base: master
Are you sure you want to change the base?
docs(core): clarify that signed integers use two's complement #147960
Conversation
|
Yeah this is definitely guaranteed. I don't have a strong opinion on whether it makes sense to repeat lang-level guarantees in the libs docs.
I would argue that But I understand that currently that's not how we specify Cc @traviscross |
|
Regarding this PR specifically, even though I see that we do something a bit like this for floats, I'd prefer to not cram this bit of information into the summary line of the doc comment for the type. Putting it in the body does seem OK though. r? traviscross cc @ehuss
Are you interested in making a PR to the Reference here to more cleanly make this guarantee? Probably I'd like to see the Reference guarantee this clearly before we do it in the standard library in this case. |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
That makes sense, opened rust-lang/reference#2064 to this end. |
Description
This attempts to clarify in the std documentation how signed integers (
i8–i128andisize) are encoded. I do not mean this to introduce a new stability guarantee, but only to document an already obvious (?) property, which is already documented elsewhere (mostly).Motivation
My understanding is that signed integers are already guaranteed to be encoded in two's complement. The Reference does state this for
i8–i128(but technically does not forisize, at least not in the same place), and in documenting numeric casts and negation operators:This therefore does not seem architecture or platform-dependent. However it is also not specified explicitly in the FLS.
In addition, I could not find this in the std documentation, while this seems required to understand the behavior of shr operations and of
ascasts in particular.If this is something you think is worth documenting explicitly, the exact phrasing can likely be refined (it is currently modeled on floats'). If not, feel free to close this PR.