Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for Duration::as_millis_{f64,f32} #122451

Open
3 of 6 tasks
declanvk opened this issue Mar 13, 2024 · 0 comments
Open
3 of 6 tasks

Tracking Issue for Duration::as_millis_{f64,f32} #122451

declanvk opened this issue Mar 13, 2024 · 0 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@declanvk
Copy link
Contributor

declanvk commented Mar 13, 2024

Feature gate: #![feature(duration_millis_float)]

This is a tracking issue for

  • Duration::as_millis_f64
  • Duration::as_millis_f32

Public API

impl Duration {
    /// Returns the number of milliseconds contained by this `Duration` as `f64`.
    ///
    /// The returned value does include the fractional (nanosecond) part of the duration.
    ///
    /// # Examples
    /// ```
    /// use std::time::Duration;
    ///
    /// let dur = Duration::new(2, 67_890_000);
    /// assert_eq!(dur.as_millis_f64(), 2678.9);
    /// ```
    pub fn as_millis_f64(self);

    /// Returns the number of milliseconds contained by this `Duration` as `f32`.
    ///
    /// The returned value does include the fractional (nanosecond) part of the duration.
    ///
    /// # Examples
    /// ```
    /// use std::time::Duration;
    ///
    /// let dur = Duration::new(2, 67_890_000);
    /// assert_eq!(dur.as_millis_f32(), 2678.9);
    /// ```
    pub fn as_millis_f32(self);
}

Steps / History

Unresolved Questions

  • The implementation is using floating-point division; would we be ok with changing it to multiplication-by-reciprocal at the cost of a ½ULP but being faster? as_secs_f32 uses division, so maybe not.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@declanvk declanvk added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 13, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 14, 2024
…, r=scottmcm

Implement `Duration::as_millis_{f64,f32}`

Implementation of rust-lang#122451.

Linked const-unstability to rust-lang#72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 15, 2024
Rollup merge of rust-lang#122479 - GrigorenkoPV:duration_millis_float, r=scottmcm

Implement `Duration::as_millis_{f64,f32}`

Implementation of rust-lang#122451.

Linked const-unstability to rust-lang#72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant