Closed
Description
use std::time::Duration;
fn main() {
let dur = Duration::from_secs_f64(0.000042);
assert_eq!(dur, Duration::new(0, 42000));
}
The above assertion succeeds on Rust standard library versions prior to 1.60.0. On 1.60.0 it fails with:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `41.999µs`,
right: `42µs`', src/main.rs:6:5
The exact mathematical value represented by 0.000042_f64 is:
0.0000419999999999999976759042230600726952616241760551929473876953125
which is about 41999.999999999998ns. This is astronomically closer to 42000ns than to 41999ns. I believe the correct behavior for from_secs_f64
would be to produce 42000ns as before, not truncate to 41999ns.
Mentioning @newpavlov @nagisa since #90247 seems related and is in the right commit range. The PR summary mentions that the PR would be performing truncation instead of rounding but I don't see that this decision was ever discussed by the library API team. (Mentioning @rust-lang/libs-api to comment on desired behavior.)