add is_multiple_of for unsigned integer types · model-checking/verify-rust-std@6cabb65 (original) (raw)

`@@ -2764,6 +2764,35 @@ macro_rules! uint_impl {

`

2764

2764

`}

`

2765

2765

`}

`

2766

2766

``

``

2767

`` +

/// Returns true if self is an integer multiple of rhs, and false otherwise.

``

``

2768

`+

///

`

``

2769

`` +

/// This function is equivalent to self % rhs == 0, except that it will not panic

``

``

2770

`` +

/// for rhs == 0. Instead, 0.is_multiple_of(0) == true, and for any non-zero n,

``

``

2771

`` +

/// n.is_multiple_of(0) == false.

``

``

2772

`+

///

`

``

2773

`+

/// # Examples

`

``

2774

`+

///

`

``

2775

`+

/// Basic usage:

`

``

2776

`+

///

`

``

2777


/// ```

``

2778

`+

/// #![feature(unsigned_is_multiple_of)]

`

``

2779

`+

#[doc = concat!("assert!(6_", stringify!($SelfT), ".is_multiple_of(2));")]

`

``

2780

`+

#[doc = concat!("assert!(!5_", stringify!($SelfT), ".is_multiple_of(2));")]

`

``

2781

`+

///

`

``

2782

`+

#[doc = concat!("assert!(0_", stringify!($SelfT), ".is_multiple_of(0));")]

`

``

2783

`+

#[doc = concat!("assert!(!6_", stringify!($SelfT), ".is_multiple_of(0));")]

`

``

2784


/// ```

``

2785

`+

#[unstable(feature = "unsigned_is_multiple_of", issue = "128101")]

`

``

2786

`+

#[must_use]

`

``

2787

`+

#[inline]

`

``

2788

`+

#[rustc_inherit_overflow_checks]

`

``

2789

`+

pub const fn is_multiple_of(self, rhs: Self) -> bool {

`

``

2790

`+

match rhs {

`

``

2791

`+

0 => self == 0,

`

``

2792

`+

_ => self % rhs == 0,

`

``

2793

`+

}

`

``

2794

`+

}

`

``

2795

+

2767

2796

`` /// Returns true if and only if self == 2^k for some k.

``

2768

2797

`///

`

2769

2798

`/// # Examples

`