Skip to content

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

Open
@declanvk

Description

@declanvk

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 const 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 const 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions