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
Feature gate:
#![feature(unsigned_is_multiple_of)]ACP: rust-lang/libs-team#404
This is a tracking issue for the
.is_multiple_ofmethod on unsigned integers.Returns
trueifselfis 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_offor unsigned integer types #128103unsigned_is_multiple_of#137383Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩