Skip to content
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

Open
3 tasks done
folkertdev opened this issue Jul 23, 2024 · 5 comments
Open
3 tasks done

Tracking Issue for unsigned_is_multiple_of #128101

folkertdev opened this issue Jul 23, 2024 · 5 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Comments

@folkertdev
Copy link
Contributor

folkertdev commented Jul 23, 2024

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

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

fn is_multiple_of(lhs: u64, rhs: u64) -> bool {
    match rhs {
        // prevent division by zero
        0 => lhs == 0,
        _ => lhs % rhs == 0,
    }
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@folkertdev folkertdev added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 23, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 28, 2024
…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`.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 28, 2024
…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`.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 28, 2024
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`.
@diondokter
Copy link
Contributor

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())
    );
}

@joshtriplett
Copy link
Member

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

@rfcbot
Copy link

rfcbot commented Jan 16, 2025

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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 16, 2025
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Feb 11, 2025
@rfcbot
Copy link

rfcbot commented Feb 11, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 21, 2025
@rfcbot
Copy link

rfcbot commented Feb 21, 2025

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.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 22, 2025
…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,
    }
}
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 22, 2025
…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,
    }
}
```
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 23, 2025
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,
    }
}
```
RalfJung pushed a commit to RalfJung/miri that referenced this issue Feb 24, 2025
…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,
    }
}
```
github-merge-queue bot pushed a commit to rust-lang/rust-analyzer that referenced this issue Feb 24, 2025
…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,
    }
}
```
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
…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,
    }
}
```
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
…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,
    }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

No branches or pull requests

4 participants