-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tracking Issue for unsigned_is_multiple_of
#128101
Comments
…e-of, r=Amanieu add `is_multiple_of` for unsigned integer types tracking issue: rust-lang#128101 This adds the `.is_multiple_of` method on unsigned integers. Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise. This function is equivalent to `self % rhs == 0`, except that it will not panic for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`, `n.is_multiple_of(0) == false`.
…e-of, r=Amanieu add `is_multiple_of` for unsigned integer types tracking issue: rust-lang#128101 This adds the `.is_multiple_of` method on unsigned integers. Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise. This function is equivalent to `self % rhs == 0`, except that it will not panic for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`, `n.is_multiple_of(0) == false`.
Rollup merge of rust-lang#128103 - folkertdev:unsigned-int-is-multiple-of, r=Amanieu add `is_multiple_of` for unsigned integer types tracking issue: rust-lang#128101 This adds the `.is_multiple_of` method on unsigned integers. Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise. This function is equivalent to `self % rhs == 0`, except that it will not panic for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`, `n.is_multiple_of(0) == false`.
I'd love to have this stable at some point. It's not a must have, but it makes code much nicer to read. In my case right now, I need to check if the hardware busses have dividers that are a multiple of the main bus. You judge what's better to read and conveys more meaning: let apb_dividers = [config.apb1_divider, config.apb2_divider, config.apb3_divider, config.apb4_divider];
for apb_divider in apb_dividers {
assert!(
apb_divider.div_value() % config.core_clock_prescaler.div_value()
== 0
);
} Or let apb_dividers = [config.apb1_divider, config.apb2_divider, config.apb3_divider, config.apb4_divider];
for apb_divider in apb_dividers {
assert!(
apb_divider.div_value()
.is_multiple_of(config.core_clock_prescaler.div_value())
);
} |
This has been implemented for a while, it's simple and straightforward, it's useful, people want it, and there are no known issues with it. Shall we stabilize it? @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
…ultiple-of, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang#128101 fcp completed in: rust-lang#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
…ultiple-of, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang#128101 fcp completed in: rust-lang#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
Rollup merge of rust-lang#137383 - folkertdev:stabilize-unsigned-is-multiple-of, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang#128101 fcp completed in: rust-lang#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
…f, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang/rust#128101 fcp completed in: rust-lang/rust#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
…f, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang/rust#128101 fcp completed in: rust-lang/rust#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
…ultiple-of, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang#128101 fcp completed in: rust-lang#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
…ultiple-of, r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: rust-lang#128101 fcp completed in: rust-lang#128101 (comment) ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
Feature gate:
#![feature(unsigned_is_multiple_of)]
ACP: rust-lang/libs-team#404
This is a tracking issue for the
.is_multiple_of
method on unsigned integers.Returns
true
ifself
is an integer multiple ofrhs
, and false otherwise.This function is equivalent to
self % rhs == 0
, except that it will not panic forrhs == 0
. Instead,0.is_multiple_of(0) == true
, and for any non-zeron
,n.is_multiple_of(0) == false
.If you have a real usecase for this function on signed integer types, let us know! That was not included for simplicity, but if a usecase comes up, adding it will be considered.
Public API
A version of this for all the unsigned types
Steps / History
is_multiple_of
for unsigned integer types #128103unsigned_is_multiple_of
#137383Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: