Skip to content

std::time::Duration::from_secs_f64 behavior changed in 1.63.0 #100480

Closed
@youknowone

Description

@youknowone

Though the PR describes the change is related to improve its truncation better, the changed behavior is rounding up which was down before.

EDIT: The upper changes and issue related to 1.60. It is not related to this issue.

I want to check if this is expected change or regression.

Code

I tried this code:

use std::time::Duration;

fn main() {
    let f: f64 = 1.0020030005;
    let d = Duration::from_secs_f64(f);
    println!("{d:?}");
}

I expected to see this happen: explanation
Until 1.62.1,

1.002003s

Instead, this happened: explanation
In 1.63.0,

1.002003001s

Version it worked on

It most recently worked on: Until 1.62.1

Version with regression

rustc --version --verbose:

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions