@@ -30,6 +30,7 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
3030const NANOS_PER_MICRO : u32 = 1_000 ;
3131const MILLIS_PER_SEC : u64 = 1_000 ;
3232const MICROS_PER_SEC : u64 = 1_000_000 ;
33+ const MAX_NANOS_F64 : f64 = ( ( u64:: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 ;
3334
3435/// A `Duration` type to represent a span of time, typically used for system
3536/// timeouts.
@@ -523,7 +524,7 @@ impl Mul<f64> for Duration {
523524 if !nanos_f64. is_finite ( ) {
524525 panic ! ( "got non-finite value when multiplying duration by float" ) ;
525526 }
526- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
527+ if nanos_f64 > MAX_NANOS_F64 {
527528 panic ! ( "overflow when multiplying duration by float" ) ;
528529 } ;
529530 let nanos_u128 = nanos_f64 as u128 ;
@@ -547,7 +548,7 @@ impl Mul<Duration> for f64 {
547548 if !nanos_f64. is_finite ( ) {
548549 panic ! ( "got non-finite value when multiplying float by duration" ) ;
549550 }
550- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
551+ if nanos_f64 > MAX_NANOS_F64 {
551552 panic ! ( "overflow when multiplying float by duration" ) ;
552553 } ;
553554 let nanos_u128 = nanos_f64 as u128 ;
@@ -594,7 +595,7 @@ impl Div<f64> for Duration {
594595 if !nanos_f64. is_finite ( ) {
595596 panic ! ( "got non-finite value when dividing duration by float" ) ;
596597 }
597- if nanos_f64 > ( ( u64 :: MAX as u128 ) * ( NANOS_PER_SEC as u128 ) ) as f64 {
598+ if nanos_f64 > MAX_NANOS_F64 {
598599 panic ! ( "overflow when dividing duration by float" ) ;
599600 } ;
600601 let nanos_u128 = nanos_f64 as u128 ;
0 commit comments