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
Integer division/remainder rounding behavior should be documented #26845
Comments
http://doc.rust-lang.org/reference.html#behavior-not-considered-unsafe talks about 'overflow' and mentions wrapping, but you're right that we can surface this better. |
This is about rounding, not wrapping. We use LLVM's |
This resolves #26845. I'm not entirely satisfied with the placement of the rounding discussion in the docs for the `Div` and `Rem` traits, but I couldn't come up with anywhere better to put it. Suggestions are welcome. I didn't add any discussion of rounding to the `checked_div` (or rem) or `wrapping_div` documentation because those seem to make it pretty clear that they do the same thing as `Div`.
This should also leave a warning, because integer / integer is not always desired and happens by accident. Just a thought if anyone is reading this. |
Using Google I can find lots of old arguments over how integer division should work in Rust, but I cannot find anything in the reference, the API docs for the integer types, or the API docs for the
Div
trait that says what was actually decided. (And the documentation seems to imply that/
,checked_div
, andwrapping_div
may not all do the same thing.) This is further confused by the integer type documentation apparently sometimes using/
to refer to integer division and sometimes to mathematical division. (I can't come up with out any other reasonable interpretation offloor(self / other)
in thewrapping_div
documentation.) It would be nice if this were clearly documented somewhere, since this varies between languages and is one of the main confusions with integer arithmetic.The text was updated successfully, but these errors were encountered: