Skip to content

Commit 06af3a6

Browse files
authored
add debug asserts
1 parent 26f8594 commit 06af3a6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/core/src/time.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,10 @@ macro_rules! try_from_secs {
12901290

12911291
// note that neither `f32`, nor `f64` can represent
12921292
// 0.999_999_999_5 exactly, so the nanos part
1293-
// never will be equal to 10^9.
1294-
(0, nanos + add_ns as u32)
1293+
// never will be equal to NANOS_PER_SEC
1294+
let nanos = nanos + add_ns as u32;
1295+
debug_assert!(nanos < NANOS_PER_SEC);
1296+
(0, nanos)
12951297
} else if exp < $mant_bits {
12961298
let secs = u64::from(mant >> ($mant_bits - exp));
12971299
let t = <$double_ty>::from((mant << exp) & MANT_MASK);
@@ -1308,8 +1310,10 @@ macro_rules! try_from_secs {
13081310
let add_ns = !(rem_msb || (is_even && is_tie));
13091311

13101312
// neither `f32`, nor `f64` can represent x.999_999_999_5 exactly,
1311-
// so the nanos part never will be equal to 10^9
1312-
(secs, nanos + add_ns as u32)
1313+
// so the nanos part never will be equal to NANOS_PER_SEC
1314+
let nanos = nanos + add_ns as u32;
1315+
debug_assert!(nanos < NANOS_PER_SEC);
1316+
(secs, nanos)
13131317
} else if exp < 64 {
13141318
// the input has no fractional part
13151319
let secs = u64::from(mant) << (exp - $mant_bits);

0 commit comments

Comments
 (0)