Skip to content

Tracking Issue for int_roundings #88581

Description

@jhpratt

View all comments

Feature gate: #![feature(int_roundings)]

This is a tracking issue for the div_floor, div_ceil, next_multiple_of, and checked_multiple_of methods on all integer types.

Public API

impl {integer} {
    #[unstable]
    pub const fn div_floor(self, rhs: Self) -> Self;
}

impl {signed integer} {
    #[unstable]
    pub const fn div_ceil(self, rhs: Self) -> Self;

    #[unstable]
    pub const fn next_multiple_of(self, rhs: Self) -> Self;

    #[unstable]
    pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
}

impl {unsigned integer} {
    #[stable(since = "1.73.0")]
    pub const fn div_ceil(self, rhs: Self) -> Self;

    #[stable(since = "1.73.0")]
    pub const fn next_multiple_of(self, rhs: Self) -> Self;

    #[stable(since = "1.73.0")]
    pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
}

Steps / History

Unresolved Questions

  • None yet.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Sep 2, 2021
  2. added a commit that references this issue on Sep 2, 2021
  3. added a commit that references this issue on Sep 2, 2021
  4. fourbytes commented on Sep 3, 2021

    @fourbytes

    Just updated to the latest nightly, looks like this feature breaks the num-bigint crate.

    error[E0658]: use of unstable library feature 'int_roundings'
    error[E0658]: use of unstable library feature 'int_roundings'
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint.rs:398:45
        |
    398 |                 let root_scale = extra_bits.div_ceil(&n64);
        |                                             ^^^^^^^^
        |
        = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
        = help: add `#![feature(int_roundings)]` to the crate attributes to enable
    
    error[E0308]: mismatched types
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint.rs:398:54
        |
    398 |                 let root_scale = extra_bits.div_ceil(&n64);
        |                                                      ^^^^ expected `u64`, found `&u64`
        |
    help: consider removing the borrow
        |
    398 -                 let root_scale = extra_bits.div_ceil(&n64);
    398 +                 let root_scale = extra_bits.div_ceil(n64);
        |
    
    error[E0658]: use of unstable library feature 'int_roundings'
      --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:70:10
       |
    70 |         .div_ceil(&big_digit::BITS.into())
       |          ^^^^^^^^
       |
       = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
       = help: add `#![feature(int_roundings)]` to the crate attributes to enable
    
    error[E0308]: mismatched types
      --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:70:19
       |
    70 |         .div_ceil(&big_digit::BITS.into())
       |                   ^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found reference
       |
       = note:   expected type `u64`
               found reference `&_`
    help: consider removing the borrow
       |
    70 -         .div_ceil(&big_digit::BITS.into())
    70 +         .div_ceil(big_digit::BITS.into())
       |
    
    error[E0658]: use of unstable library feature 'int_roundings'
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:585:10
        |
    585 |         .div_ceil(&u64::from(bits))
        |          ^^^^^^^^
        |
        = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
        = help: add `#![feature(int_roundings)]` to the crate attributes to enable
    
    error[E0308]: mismatched types
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:585:19
        |
    585 |         .div_ceil(&u64::from(bits))
        |                   ^^^^^^^^^^^^^^^^ expected `u64`, found `&u64`
        |
    help: consider removing the borrow
        |
    585 -         .div_ceil(&u64::from(bits))
    585 +         .div_ceil(u64::from(bits))
        |
    
    error[E0658]: use of unstable library feature 'int_roundings'
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:613:10
        |
    613 |         .div_ceil(&u64::from(bits))
        |          ^^^^^^^^
        |
        = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
        = help: add `#![feature(int_roundings)]` to the crate attributes to enable
    
    error[E0308]: mismatched types
       --> /home/fourbytes/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.4.1/src/biguint/convert.rs:613:19
        |
    613 |         .div_ceil(&u64::from(bits))
        |                   ^^^^^^^^^^^^^^^^ expected `u64`, found `&u64`
        |
    help: consider removing the borrow
        |
    613 -         .div_ceil(&u64::from(bits))
    613 +         .div_ceil(u64::from(bits))
        |
    
    Some errors have detailed explanations: E0308, E0658.
    For more information about an error, try `rustc --explain E0308`.
    error: could not compile `num-bigint` due to 8 previous errors
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    
  5. jhpratt commented on Sep 3, 2021

    @jhpratt
    MemberAuthor

    That is considered acceptable breakage. Per RFC 1105, adding an inherent impl is a minor change.

  6. added 2 commits that reference this issue on Sep 3, 2021
  7. added a commit that references this issue on Sep 3, 2021
  8. 210 remaining items

  9. added a commit that references this issue on Sep 8, 2024
  10. thaliaarchi commented on Nov 23, 2024

    @thaliaarchi
    Contributor

    I am interested in this being fleshed out, so I surveyed the methods. The following division/remainder methods are not implemented. For ceiling and floored rounding, there is no rem_* analogues to div_* and none of the versions that control overflow and wrapping. Additionally, there is no Euclidean saturating division or any saturating remainders.

    I maintain a document tracking rounding of division and modulo across languages, which may be a useful reference.

  11. nxsaken commented on Jul 4, 2025

    @nxsaken
    Contributor

    Is there something that keeps this feature from being stabilized?

  12. orlp commented on Jul 4, 2025

    @orlp
    Contributor

    @nxsaken I for one would strongly recommend we implement rem_floor and rem_ceil as counterparts to the divs. Especially because rem_floor is the remainder you almost always want.

  13. cuviper commented on Jul 4, 2025

    @cuviper
    Member

    The signed methods are still unstable too.

  14. Gnurou commented on Aug 3, 2025

    @Gnurou
    Contributor

    While prev_multiple_of can be emulated on signed types by passing a negative parameter, that option is not available for unsigned types. Having this method would be useful for e.g. value alignment and is also good API symmetry IMHO.

  15. ronnodas commented on Aug 4, 2025

    @ronnodas
    Contributor

    While prev_multiple_of can be emulated on signed types by passing a negative parameter, that option is not available for unsigned types. Having this method would be useful for e.g. value alignment and is also good API symmetry IMHO.

    Consider unsigned_abs(), as in a.prev_multiple_of(b.unsigned_abs())

  16. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions