File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,9 @@ impl Integer for BigUint {
283
283
/// Returns `true` if the number is a multiple of `other`.
284
284
#[ inline]
285
285
fn is_multiple_of ( & self , other : & BigUint ) -> bool {
286
+ if other. is_zero ( ) {
287
+ return self . is_zero ( ) ;
288
+ }
286
289
( self % other) . is_zero ( )
287
290
}
288
291
Original file line number Diff line number Diff line change @@ -1036,6 +1036,18 @@ fn test_lcm() {
1036
1036
check ( 11 , 5 , 55 ) ;
1037
1037
}
1038
1038
1039
+ #[ test]
1040
+ fn test_is_multiple_of ( ) {
1041
+ assert ! ( BigInt :: from( 0 ) . is_multiple_of( & BigInt :: from( 0 ) ) ) ;
1042
+ assert ! ( BigInt :: from( 6 ) . is_multiple_of( & BigInt :: from( 6 ) ) ) ;
1043
+ assert ! ( BigInt :: from( 6 ) . is_multiple_of( & BigInt :: from( 3 ) ) ) ;
1044
+ assert ! ( BigInt :: from( 6 ) . is_multiple_of( & BigInt :: from( 1 ) ) ) ;
1045
+
1046
+ assert ! ( !BigInt :: from( 42 ) . is_multiple_of( & BigInt :: from( 5 ) ) ) ;
1047
+ assert ! ( !BigInt :: from( 5 ) . is_multiple_of( & BigInt :: from( 3 ) ) ) ;
1048
+ assert ! ( !BigInt :: from( 42 ) . is_multiple_of( & BigInt :: from( 0 ) ) ) ;
1049
+ }
1050
+
1039
1051
#[ test]
1040
1052
fn test_next_multiple_of ( ) {
1041
1053
assert_eq ! (
Original file line number Diff line number Diff line change @@ -1085,6 +1085,18 @@ fn test_lcm() {
1085
1085
check ( 99 , 17 , 1683 ) ;
1086
1086
}
1087
1087
1088
+ #[ test]
1089
+ fn test_is_multiple_of ( ) {
1090
+ assert ! ( BigUint :: from( 0u32 ) . is_multiple_of( & BigUint :: from( 0u32 ) ) ) ;
1091
+ assert ! ( BigUint :: from( 6u32 ) . is_multiple_of( & BigUint :: from( 6u32 ) ) ) ;
1092
+ assert ! ( BigUint :: from( 6u32 ) . is_multiple_of( & BigUint :: from( 3u32 ) ) ) ;
1093
+ assert ! ( BigUint :: from( 6u32 ) . is_multiple_of( & BigUint :: from( 1u32 ) ) ) ;
1094
+
1095
+ assert ! ( !BigUint :: from( 42u32 ) . is_multiple_of( & BigUint :: from( 5u32 ) ) ) ;
1096
+ assert ! ( !BigUint :: from( 5u32 ) . is_multiple_of( & BigUint :: from( 3u32 ) ) ) ;
1097
+ assert ! ( !BigUint :: from( 42u32 ) . is_multiple_of( & BigUint :: from( 0u32 ) ) ) ;
1098
+ }
1099
+
1088
1100
#[ test]
1089
1101
fn test_next_multiple_of ( ) {
1090
1102
assert_eq ! (
You can’t perform that action at this time.
0 commit comments