-
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 |
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: