@@ -517,16 +517,16 @@ impl Mul<f64> for Duration {
517517
518518 fn mul ( self , rhs : f64 ) -> Duration {
519519 const NPS : f64 = NANOS_PER_SEC as f64 ;
520- if rhs. is_sign_negative ( ) {
521- panic ! ( "duration can not be multiplied by negative float" ) ;
522- }
523520 let nanos_f64 = rhs * ( NPS * ( self . secs as f64 ) + ( self . nanos as f64 ) ) ;
524521 if !nanos_f64. is_finite ( ) {
525522 panic ! ( "got non-finite value when multiplying duration by float" ) ;
526523 }
527524 if nanos_f64 > MAX_NANOS_F64 {
528525 panic ! ( "overflow when multiplying duration by float" ) ;
529- } ;
526+ }
527+ if nanos_f64 < 0.0 {
528+ panic ! ( "underflow when multiplying duration by float" ) ;
529+ }
530530 let nanos_u128 = nanos_f64 as u128 ;
531531 Duration {
532532 secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
@@ -541,16 +541,16 @@ impl Mul<Duration> for f64 {
541541
542542 fn mul ( self , rhs : Duration ) -> Duration {
543543 const NPS : f64 = NANOS_PER_SEC as f64 ;
544- if self . is_sign_negative ( ) {
545- panic ! ( "duration can not be multiplied by negative float" ) ;
546- }
547544 let nanos_f64 = self * ( NPS * ( rhs. secs as f64 ) + ( rhs. nanos as f64 ) ) ;
548545 if !nanos_f64. is_finite ( ) {
549546 panic ! ( "got non-finite value when multiplying float by duration" ) ;
550547 }
551548 if nanos_f64 > MAX_NANOS_F64 {
552549 panic ! ( "overflow when multiplying float by duration" ) ;
553- } ;
550+ }
551+ if nanos_f64 < 0.0 {
552+ panic ! ( "underflow when multiplying float by duration" ) ;
553+ }
554554 let nanos_u128 = nanos_f64 as u128 ;
555555 Duration {
556556 secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
@@ -588,16 +588,16 @@ impl Div<f64> for Duration {
588588
589589 fn div ( self , rhs : f64 ) -> Duration {
590590 const NPS : f64 = NANOS_PER_SEC as f64 ;
591- if rhs. is_sign_negative ( ) {
592- panic ! ( "duration can not be divided by negative float" ) ;
593- }
594591 let nanos_f64 = ( NPS * ( self . secs as f64 ) + ( self . nanos as f64 ) ) / rhs;
595592 if !nanos_f64. is_finite ( ) {
596593 panic ! ( "got non-finite value when dividing duration by float" ) ;
597594 }
598595 if nanos_f64 > MAX_NANOS_F64 {
599596 panic ! ( "overflow when dividing duration by float" ) ;
600- } ;
597+ }
598+ if nanos_f64 < 0.0 {
599+ panic ! ( "underflow when multiplying duration by float" ) ;
600+ }
601601 let nanos_u128 = nanos_f64 as u128 ;
602602 Duration {
603603 secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
0 commit comments