rust-lang / rust-lang/rust

Tracking Issue for `Duration::as_millis_{f64,f32}`

Open
#122,451 1 comment 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the public API and the linked implementation PR first, then read the feature-lifecycle stabilization guide referenced by the issue. The remaining work is the final comment period and a stabilization PR; the unresolved question about floating-point division versus multiplication by a reciprocal also needs resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.