Skip to content

Commit 4a6d159

Browse files
committed
redefine next_multiple_of to do no multiplication beyond what may be done in mod_floor
1 parent 41adfe5 commit 4a6d159

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
204204
/// ~~~
205205
#[inline]
206206
fn next_multiple_of(&self, other: &Self) -> Self where Self: Clone {
207-
self.div_ceil(other).mul(other.clone())
207+
let m = self.mod_floor(other);
208+
self.clone() + if m.is_zero() { Self::zero() } else { other.clone() - m }
208209
}
209210

210211
/// Rounds down to nearest multiple of argument.
@@ -218,7 +219,7 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
218219
/// ~~~
219220
#[inline]
220221
fn next_multiple_back_of(&self, other: &Self) -> Self where Self: Clone {
221-
self.div_floor(other).mul(other.clone())
222+
self.clone() - self.mod_floor(other)
222223
}
223224
}
224225

0 commit comments

Comments
 (0)