@@ -30,6 +30,7 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
30
30
const NANOS_PER_MICRO : u32 = 1_000 ;
31
31
const MILLIS_PER_SEC : u64 = 1_000 ;
32
32
const MICROS_PER_SEC : u64 = 1_000_000 ;
33
+ const MAX_NANOS_F64 : f64 = ( ( u64:: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 ;
33
34
34
35
/// A `Duration` type to represent a span of time, typically used for system
35
36
/// timeouts.
@@ -523,7 +524,7 @@ impl Mul<f64> for Duration {
523
524
if !nanos_f64. is_finite ( ) {
524
525
panic ! ( "got non-finite value when multiplying duration by float" ) ;
525
526
}
526
- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
527
+ if nanos_f64 > MAX_NANOS_F64 {
527
528
panic ! ( "overflow when multiplying duration by float" ) ;
528
529
} ;
529
530
let nanos_u128 = nanos_f64 as u128 ;
@@ -547,7 +548,7 @@ impl Mul<Duration> for f64 {
547
548
if !nanos_f64. is_finite ( ) {
548
549
panic ! ( "got non-finite value when multiplying float by duration" ) ;
549
550
}
550
- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
551
+ if nanos_f64 > MAX_NANOS_F64 {
551
552
panic ! ( "overflow when multiplying float by duration" ) ;
552
553
} ;
553
554
let nanos_u128 = nanos_f64 as u128 ;
@@ -594,7 +595,7 @@ impl Div<f64> for Duration {
594
595
if !nanos_f64. is_finite ( ) {
595
596
panic ! ( "got non-finite value when dividing duration by float" ) ;
596
597
}
597
- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
598
+ if nanos_f64 > MAX_NANOS_F64 {
598
599
panic ! ( "overflow when dividing duration by float" ) ;
599
600
} ;
600
601
let nanos_u128 = nanos_f64 as u128 ;
0 commit comments