We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
next_multiple_of
mod_floor
1 parent 41adfe5 commit 4a6d159Copy full SHA for 4a6d159
1 file changed
src/lib.rs
@@ -204,7 +204,8 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
204
/// ~~~
205
#[inline]
206
fn next_multiple_of(&self, other: &Self) -> Self where Self: Clone {
207
- self.div_ceil(other).mul(other.clone())
+ let m = self.mod_floor(other);
208
+ self.clone() + if m.is_zero() { Self::zero() } else { other.clone() - m }
209
}
210
211
/// Rounds down to nearest multiple of argument.
@@ -218,7 +219,7 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
218
219
220
221
fn next_multiple_back_of(&self, other: &Self) -> Self where Self: Clone {
- self.div_floor(other).mul(other.clone())
222
+ self.clone() - self.mod_floor(other)
223
224
225
0 commit comments