@@ -227,9 +227,9 @@ impl Integer for $T {
227
227
228
228
/// Unsigned integer modulo operation. Returns the same result as `rem` (`%`).
229
229
#[ inline]
230
- fn mod_floor( & self , other: & $T) -> $T { * self / * other }
230
+ fn mod_floor( & self , other: & $T) -> $T { * self % * other }
231
231
232
- /// Calculates `div_floor` and `modulo_floor ` simultaneously
232
+ /// Calculates `div_floor` and `mod_floor ` simultaneously
233
233
#[ inline]
234
234
fn div_mod_floor( & self , other: & $T) -> ( $T, $T) {
235
235
( * self / * other, * self % * other)
@@ -458,6 +458,19 @@ mod tests {
458
458
assert_eq!( ( 3 as $T) . clamp( & ( 2 as $T) , & ( 4 as $T) ) , 3 as $T) ;
459
459
}
460
460
461
+ #[ test]
462
+ fn test_div_mod_floor( ) {
463
+ assert_eq!( ( 10 as $T) . div_floor( & ( 3 as $T) ) , 3 as $T) ;
464
+ assert_eq!( ( 10 as $T) . mod_floor( & ( 3 as $T) ) , 1 as $T) ;
465
+ assert_eq!( ( 10 as $T) . div_mod_floor( & ( 3 as $T) ) , ( 3 as $T, 1 as $T) ) ;
466
+ assert_eq!( ( 5 as $T) . div_floor( & ( 5 as $T) ) , 1 as $T) ;
467
+ assert_eq!( ( 5 as $T) . mod_floor( & ( 5 as $T) ) , 0 as $T) ;
468
+ assert_eq!( ( 5 as $T) . div_mod_floor( & ( 5 as $T) ) , ( 1 as $T, 0 as $T) ) ;
469
+ assert_eq!( ( 3 as $T) . div_floor( & ( 7 as $T) ) , 0 as $T) ;
470
+ assert_eq!( ( 3 as $T) . mod_floor( & ( 7 as $T) ) , 3 as $T) ;
471
+ assert_eq!( ( 3 as $T) . div_mod_floor( & ( 7 as $T) ) , ( 0 as $T, 3 as $T) ) ;
472
+ }
473
+
461
474
#[ test]
462
475
fn test_gcd( ) {
463
476
assert_eq!( ( 10 as $T) . gcd( & 2 ) , 2 as $T) ;
0 commit comments