Open
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
- ACP: Add
as_millis_{f64,f32}
helper functions forDuration
libs-team#349 - Implementation: Implement
Duration::as_millis_{f64,f32}
#122479 - Related lint: Add lint which checks that duration conversion aren't losing precision rust-clippy#12539
- Final comment period (FCP)1
- Stabilization PR
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.