-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking Issue for exact_div
#139911
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
Comments
How do these handle overflow ( |
They return |
For the safe version this makes sense but for |
The unsafe variant would be a simple wrapper around the |
Just because the perma-unstable intrinsic works this way doesn’t mean it’s also the best option for a stable user-facing API. We also have an |
Any other behavior would be surprising. You could argue that we don't need |
I’m not here to argue about whether the functionality is needed, just point out that there’s other ways to expose it that may be better (easier to use correctly), at least for unsigned integers. Similarly , there’s no need to add unsafe |
No, there is only one unsafe precondition: An "unchecked" method panicking on some inputs would be quite surprising. |
This “single” precondition leaves a third of the work to the “(without overflow)” and isn’t even correct: a = b = 0 is UB but c = 0 satisfies b * c = a. In any case: even if there is some clever way to subsume all three conditions in a single one, that’s of little use to unsafe code authors if the generality makes it easy to overlook edge cases or difficult to connect to the concrete facts available at the call site. |
You're right, it should be a unique number |
This came up in the @rust-lang/libs-api meeting while discussing rust-lang/libs-team#570. We think that the unchecked version is valuable because it exposes the lowest-level primitive which others can build around. Only exposing higher-level wrappers can end up being harder for users to work with. However we did feel that there was little value to the panicking version, especially since it can be emulated by calling Regarding naming, in the meeting there was a preference for |
I don't think I'm on board with the checked variant dropping the
We should just keep that prefix given how strong the convention already is. The other benefit of using the Could the libs-api members who want to drop the |
It was mentioned in the meeting that we'd get pushback on this point. And looking at the docs now, with fresh eyes, I certainly see what you mean about the weight of precedent here. The problem we were wrestling with, for rust-lang/libs-team#570, was what to do about those Similarly, So the context from which Footnotes
|
@Amanieu |
If the intention is to make the check more convenient shouldn't the checked version return a If so, there's an interesting case that it might be useful to report the non-zero remainder as |
Feature gate:
#![feature(exact_div)]
This is a tracking issue for exact division methods (i.e. for division without remainder) on primitive integer types.
Public API
Steps / History
((un)checked_)exact_div
methods for integer types libs-team#337Unresolved Questions
exact_div
: Add((un)checked_)exact_div
methods for integer types libs-team#337 (comment)The text was updated successfully, but these errors were encountered: