Skip to content

Commit 2a96e2a

Browse files
committed
Rename Integer trait divides to is_multiple_of.
It is being changed because the previous wording was ambiguous. `a.divides(b)` implied `a % b == 0` but it sounds like the other way around. `9.divides(&3) == true` but we might read that as "does 9 divide 3?". It has been renamed to sidestep the ambiguity. Work around the change by using `is_multiple_of` instead. [breaking-change]
1 parent d114dda commit 2a96e2a

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

src/libnum/bigint.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,14 @@ impl Integer for BigUint {
514514
#[inline]
515515
fn lcm(&self, other: &BigUint) -> BigUint { ((*self * *other) / self.gcd(other)) }
516516

517-
/// Returns `true` if the number can be divided by `other` without leaving a remainder.
517+
/// Deprecated, use `is_multiple_of` instead.
518+
#[deprecated = "function renamed to `is_multiple_of`"]
518519
#[inline]
519-
fn divides(&self, other: &BigUint) -> bool { (*self % *other).is_zero() }
520+
fn divides(&self, other: &BigUint) -> bool { return self.is_multiple_of(other); }
521+
522+
/// Returns `true` if the number is a multiple of `other`.
523+
#[inline]
524+
fn is_multiple_of(&self, other: &BigUint) -> bool { (*self % *other).is_zero() }
520525

521526
/// Returns `true` if the number is divisible by `2`.
522527
#[inline]
@@ -1112,9 +1117,14 @@ impl Integer for BigInt {
11121117
BigInt::from_biguint(Plus, self.data.lcm(&other.data))
11131118
}
11141119

1115-
/// Returns `true` if the number can be divided by `other` without leaving a remainder.
1120+
/// Deprecated, use `is_multiple_of` instead.
1121+
#[deprecated = "function renamed to `is_multiple_of`"]
1122+
#[inline]
1123+
fn divides(&self, other: &BigInt) -> bool { return self.is_multiple_of(other); }
1124+
1125+
/// Returns `true` if the number is a multiple of `other`.
11161126
#[inline]
1117-
fn divides(&self, other: &BigInt) -> bool { self.data.divides(&other.data) }
1127+
fn is_multiple_of(&self, other: &BigInt) -> bool { self.data.is_multiple_of(&other.data) }
11181128

11191129
/// Returns `true` if the number is divisible by `2`.
11201130
#[inline]

src/libnum/integer.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ pub trait Integer: Num + PartialOrd
7777
/// ~~~
7878
fn lcm(&self, other: &Self) -> Self;
7979

80-
/// Returns `true` if `other` divides evenly into `self`.
80+
/// Deprecated, use `is_multiple_of` instead.
81+
#[deprecated = "function renamed to `is_multiple_of`"]
82+
fn divides(&self, other: &Self) -> bool;
83+
84+
/// Returns `true` if `other` is a multiple of `self`.
8185
///
8286
/// # Examples
8387
///
8488
/// ~~~
8589
/// # use num::Integer;
86-
/// assert_eq!(9i.divides(&3), true);
87-
/// assert_eq!(3i.divides(&9), false);
90+
/// assert_eq!(9i.is_multiple_of(&3), true);
91+
/// assert_eq!(3i.is_multiple_of(&9), false);
8892
/// ~~~
89-
fn divides(&self, other: &Self) -> bool;
93+
fn is_multiple_of(&self, other: &Self) -> bool;
9094

9195
/// Returns `true` if the number is even.
9296
///
@@ -231,10 +235,14 @@ macro_rules! impl_integer_for_int {
231235
((*self * *other) / self.gcd(other)).abs()
232236
}
233237

234-
/// Returns `true` if the number can be divided by `other` without
235-
/// leaving a remainder
238+
/// Deprecated, use `is_multiple_of` instead.
239+
#[deprecated = "function renamed to `is_multiple_of`"]
240+
#[inline]
241+
fn divides(&self, other: &$T) -> bool { return self.is_multiple_of(other); }
242+
243+
/// Returns `true` if the number is a multiple of `other`.
236244
#[inline]
237-
fn divides(&self, other: &$T) -> bool { *self % *other == 0 }
245+
fn is_multiple_of(&self, other: &$T) -> bool { *self % *other == 0 }
238246

239247
/// Returns `true` if the number is divisible by `2`
240248
#[inline]
@@ -393,21 +401,26 @@ macro_rules! impl_integer_for_uint {
393401
n
394402
}
395403

396-
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`
404+
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
397405
#[inline]
398406
fn lcm(&self, other: &$T) -> $T {
399407
(*self * *other) / self.gcd(other)
400408
}
401409

402-
/// Returns `true` if the number can be divided by `other` without leaving a remainder
410+
/// Deprecated, use `is_multiple_of` instead.
411+
#[deprecated = "function renamed to `is_multiple_of`"]
403412
#[inline]
404-
fn divides(&self, other: &$T) -> bool { *self % *other == 0 }
413+
fn divides(&self, other: &$T) -> bool { return self.is_multiple_of(other); }
405414

406-
/// Returns `true` if the number is divisible by `2`
415+
/// Returns `true` if the number is a multiple of `other`.
416+
#[inline]
417+
fn is_multiple_of(&self, other: &$T) -> bool { *self % *other == 0 }
418+
419+
/// Returns `true` if the number is divisible by `2`.
407420
#[inline]
408421
fn is_even(&self) -> bool { self & 1 == 0 }
409422

410-
/// Returns `true` if the number is not divisible by `2`
423+
/// Returns `true` if the number is not divisible by `2`.
411424
#[inline]
412425
fn is_odd(&self) -> bool { !self.is_even() }
413426
}
@@ -449,10 +462,10 @@ macro_rules! impl_integer_for_uint {
449462
}
450463

451464
#[test]
452-
fn test_divides() {
453-
assert!((6 as $T).divides(&(6 as $T)));
454-
assert!((6 as $T).divides(&(3 as $T)));
455-
assert!((6 as $T).divides(&(1 as $T)));
465+
fn test_is_multiple_of() {
466+
assert!((6 as $T).is_multiple_of(&(6 as $T)));
467+
assert!((6 as $T).is_multiple_of(&(3 as $T)));
468+
assert!((6 as $T).is_multiple_of(&(1 as $T)));
456469
}
457470

458471
#[test]

0 commit comments

Comments
 (0)