This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -656,10 +656,10 @@ impl Duration {
656656 #[ rustc_const_stable( feature = "duration_consts_2" , since = "1.58.0" ) ]
657657 pub const fn checked_div ( self , rhs : u32 ) -> Option < Duration > {
658658 if rhs != 0 {
659- let secs = self . secs / ( rhs as u64 ) ;
660- let carry = self . secs - secs * ( rhs as u64 ) ;
661- let extra_nanos = carry * ( NANOS_PER_SEC as u64 ) / ( rhs as u64 ) ;
662- let nanos = self . nanos . 0 / rhs + ( extra_nanos as u32 ) ;
659+ let ( secs, extra_secs ) = ( self . secs / ( rhs as u64 ) , self . secs % ( rhs as u64 ) ) ;
660+ let ( mut nanos , extra_nanos ) = ( self . nanos . 0 / rhs, self . nanos . 0 % rhs ) ;
661+ nanos +=
662+ ( ( extra_secs * ( NANOS_PER_SEC as u64 ) + extra_nanos as u64 ) / ( rhs as u64 ) ) as u32 ;
663663 debug_assert ! ( nanos < NANOS_PER_SEC ) ;
664664 Some ( Duration :: new ( secs, nanos) )
665665 } else {
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ fn saturating_mul() {
170170fn div ( ) {
171171 assert_eq ! ( Duration :: new( 0 , 1 ) / 2 , Duration :: new( 0 , 0 ) ) ;
172172 assert_eq ! ( Duration :: new( 1 , 1 ) / 3 , Duration :: new( 0 , 333_333_333 ) ) ;
173+ assert_eq ! ( Duration :: new( 1 , 1 ) / 7 , Duration :: new( 0 , 142_857_143 ) ) ;
173174 assert_eq ! ( Duration :: new( 99 , 999_999_000 ) / 100 , Duration :: new( 0 , 999_999_990 ) ) ;
174175}
175176
You can’t perform that action at this time.
0 commit comments