@@ -517,16 +517,16 @@ impl Mul<f64> for Duration {
517
517
518
518
fn mul ( self , rhs : f64 ) -> Duration {
519
519
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
- }
523
520
let nanos_f64 = rhs * ( NPS * ( self . secs as f64 ) + ( self . nanos as f64 ) ) ;
524
521
if !nanos_f64. is_finite ( ) {
525
522
panic ! ( "got non-finite value when multiplying duration by float" ) ;
526
523
}
527
524
if nanos_f64 > MAX_NANOS_F64 {
528
525
panic ! ( "overflow when multiplying duration by float" ) ;
529
- } ;
526
+ }
527
+ if nanos_f64 < 0.0 {
528
+ panic ! ( "underflow when multiplying duration by float" ) ;
529
+ }
530
530
let nanos_u128 = nanos_f64 as u128 ;
531
531
Duration {
532
532
secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
@@ -541,16 +541,16 @@ impl Mul<Duration> for f64 {
541
541
542
542
fn mul ( self , rhs : Duration ) -> Duration {
543
543
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
- }
547
544
let nanos_f64 = self * ( NPS * ( rhs. secs as f64 ) + ( rhs. nanos as f64 ) ) ;
548
545
if !nanos_f64. is_finite ( ) {
549
546
panic ! ( "got non-finite value when multiplying float by duration" ) ;
550
547
}
551
548
if nanos_f64 > MAX_NANOS_F64 {
552
549
panic ! ( "overflow when multiplying float by duration" ) ;
553
- } ;
550
+ }
551
+ if nanos_f64 < 0.0 {
552
+ panic ! ( "underflow when multiplying float by duration" ) ;
553
+ }
554
554
let nanos_u128 = nanos_f64 as u128 ;
555
555
Duration {
556
556
secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
@@ -588,16 +588,16 @@ impl Div<f64> for Duration {
588
588
589
589
fn div ( self , rhs : f64 ) -> Duration {
590
590
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
- }
594
591
let nanos_f64 = ( NPS * ( self . secs as f64 ) + ( self . nanos as f64 ) ) / rhs;
595
592
if !nanos_f64. is_finite ( ) {
596
593
panic ! ( "got non-finite value when dividing duration by float" ) ;
597
594
}
598
595
if nanos_f64 > MAX_NANOS_F64 {
599
596
panic ! ( "overflow when dividing duration by float" ) ;
600
- } ;
597
+ }
598
+ if nanos_f64 < 0.0 {
599
+ panic ! ( "underflow when multiplying duration by float" ) ;
600
+ }
601
601
let nanos_u128 = nanos_f64 as u128 ;
602
602
Duration {
603
603
secs : ( nanos_u128 / ( NANOS_PER_SEC as u128 ) ) as u64 ,
0 commit comments