Skip to content

Commit 35c19c5

Browse files
committed
move MAX_NANOS_F64/32 to methods
1 parent e25df32 commit 35c19c5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcore/time.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
2121
const NANOS_PER_MICRO: u32 = 1_000;
2222
const MILLIS_PER_SEC: u64 = 1_000;
2323
const MICROS_PER_SEC: u64 = 1_000_000;
24-
const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
25-
const MAX_NANOS_F32: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f32;
2624

2725
/// A `Duration` type to represent a span of time, typically used for system
2826
/// timeouts.
@@ -554,6 +552,8 @@ impl Duration {
554552
#[unstable(feature = "duration_float", issue = "54361")]
555553
#[inline]
556554
pub fn from_secs_f64(secs: f64) -> Duration {
555+
const MAX_NANOS_F64: f64 =
556+
((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
557557
let nanos = secs * (NANOS_PER_SEC as f64);
558558
if !nanos.is_finite() {
559559
panic!("got non-finite value when converting float to duration");
@@ -588,6 +588,8 @@ impl Duration {
588588
#[unstable(feature = "duration_float", issue = "54361")]
589589
#[inline]
590590
pub fn from_secs_f32(secs: f32) -> Duration {
591+
const MAX_NANOS_F32: f32 =
592+
((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f32;
591593
let nanos = secs * (NANOS_PER_SEC as f32);
592594
if !nanos.is_finite() {
593595
panic!("got non-finite value when converting float to duration");

0 commit comments

Comments
 (0)