@@ -77,16 +77,20 @@ pub trait Integer: Num + PartialOrd
77
77
/// ~~~
78
78
fn lcm ( & self , other : & Self ) -> Self ;
79
79
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`.
81
85
///
82
86
/// # Examples
83
87
///
84
88
/// ~~~
85
89
/// # 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);
88
92
/// ~~~
89
- fn divides ( & self , other : & Self ) -> bool ;
93
+ fn is_multiple_of ( & self , other : & Self ) -> bool ;
90
94
91
95
/// Returns `true` if the number is even.
92
96
///
@@ -231,10 +235,14 @@ macro_rules! impl_integer_for_int {
231
235
( ( * self * * other) / self . gcd( other) ) . abs( )
232
236
}
233
237
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`.
236
244
#[ inline]
237
- fn divides ( & self , other: & $T) -> bool { * self % * other == 0 }
245
+ fn is_multiple_of ( & self , other: & $T) -> bool { * self % * other == 0 }
238
246
239
247
/// Returns `true` if the number is divisible by `2`
240
248
#[ inline]
@@ -393,21 +401,26 @@ macro_rules! impl_integer_for_uint {
393
401
n
394
402
}
395
403
396
- /// Calculates the Lowest Common Multiple (LCM) of the number and `other`
404
+ /// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
397
405
#[ inline]
398
406
fn lcm( & self , other: & $T) -> $T {
399
407
( * self * * other) / self . gcd( other)
400
408
}
401
409
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`" ]
403
412
#[ inline]
404
- fn divides( & self , other: & $T) -> bool { * self % * other == 0 }
413
+ fn divides( & self , other: & $T) -> bool { return self . is_multiple_of ( other) ; }
405
414
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`.
407
420
#[ inline]
408
421
fn is_even( & self ) -> bool { self & 1 == 0 }
409
422
410
- /// Returns `true` if the number is not divisible by `2`
423
+ /// Returns `true` if the number is not divisible by `2`.
411
424
#[ inline]
412
425
fn is_odd( & self ) -> bool { !self . is_even( ) }
413
426
}
@@ -449,10 +462,10 @@ macro_rules! impl_integer_for_uint {
449
462
}
450
463
451
464
#[ 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) ) ) ;
456
469
}
457
470
458
471
#[ test]
0 commit comments