@@ -856,6 +856,48 @@ impl Duration {
856856 ( self . secs as f32 ) + ( self . nanos . 0 as f32 ) / ( NANOS_PER_SEC as f32 )
857857 }
858858
859+ /// Returns the number of milliseconds contained by this `Duration` as `f64`.
860+ ///
861+ /// The returned value does include the fractional (nanosecond) part of the duration.
862+ ///
863+ /// # Examples
864+ /// ```
865+ /// #![feature(duration_millis_float)]
866+ /// use std::time::Duration;
867+ ///
868+ /// let dur = Duration::new(2, 345_678_000);
869+ /// assert_eq!(dur.as_millis_f64(), 2345.678);
870+ /// ```
871+ #[ unstable( feature = "duration_millis_float" , issue = "122451" ) ]
872+ #[ must_use]
873+ #[ inline]
874+ #[ rustc_const_unstable( feature = "duration_consts_float" , issue = "72440" ) ]
875+ pub const fn as_millis_f64 ( & self ) -> f64 {
876+ ( self . secs as f64 ) * ( MILLIS_PER_SEC as f64 )
877+ + ( self . nanos . 0 as f64 ) / ( NANOS_PER_MILLI as f64 )
878+ }
879+
880+ /// Returns the number of milliseconds contained by this `Duration` as `f32`.
881+ ///
882+ /// The returned value does include the fractional (nanosecond) part of the duration.
883+ ///
884+ /// # Examples
885+ /// ```
886+ /// #![feature(duration_millis_float)]
887+ /// use std::time::Duration;
888+ ///
889+ /// let dur = Duration::new(2, 345_678_000);
890+ /// assert_eq!(dur.as_millis_f32(), 2345.678);
891+ /// ```
892+ #[ unstable( feature = "duration_millis_float" , issue = "122451" ) ]
893+ #[ must_use]
894+ #[ inline]
895+ #[ rustc_const_unstable( feature = "duration_consts_float" , issue = "72440" ) ]
896+ pub const fn as_millis_f32 ( & self ) -> f32 {
897+ ( self . secs as f32 ) * ( MILLIS_PER_SEC as f32 )
898+ + ( self . nanos . 0 as f32 ) / ( NANOS_PER_MILLI as f32 )
899+ }
900+
859901 /// Creates a new `Duration` from the specified number of seconds represented
860902 /// as `f64`.
861903 ///
0 commit comments