Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bf3ca98

Browse files
authoredMay 25, 2024
Rollup merge of rust-lang#124667 - newpavlov:stabilize_div_duration, r=jhpratt
Stabilize `div_duration` Closes rust-lang#63139
2 parents 4af28c4 + 48a835b commit bf3ca98

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
 

‎core/src/time.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1084,40 +1084,42 @@ impl Duration {
10841084
///
10851085
/// # Examples
10861086
/// ```
1087-
/// #![feature(div_duration)]
10881087
/// use std::time::Duration;
10891088
///
10901089
/// let dur1 = Duration::new(2, 700_000_000);
10911090
/// let dur2 = Duration::new(5, 400_000_000);
10921091
/// assert_eq!(dur1.div_duration_f64(dur2), 0.5);
10931092
/// ```
1094-
#[unstable(feature = "div_duration", issue = "63139")]
1093+
#[stable(feature = "div_duration", since = "CURRENT_RUSTC_VERSION")]
10951094
#[must_use = "this returns the result of the operation, \
10961095
without modifying the original"]
10971096
#[inline]
10981097
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
10991098
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
1100-
self.as_secs_f64() / rhs.as_secs_f64()
1099+
let self_nanos = (self.secs as f64) * (NANOS_PER_SEC as f64) + (self.nanos.0 as f64);
1100+
let rhs_nanos = (rhs.secs as f64) * (NANOS_PER_SEC as f64) + (rhs.nanos.0 as f64);
1101+
self_nanos / rhs_nanos
11011102
}
11021103

11031104
/// Divide `Duration` by `Duration` and return `f32`.
11041105
///
11051106
/// # Examples
11061107
/// ```
1107-
/// #![feature(div_duration)]
11081108
/// use std::time::Duration;
11091109
///
11101110
/// let dur1 = Duration::new(2, 700_000_000);
11111111
/// let dur2 = Duration::new(5, 400_000_000);
11121112
/// assert_eq!(dur1.div_duration_f32(dur2), 0.5);
11131113
/// ```
1114-
#[unstable(feature = "div_duration", issue = "63139")]
1114+
#[stable(feature = "div_duration", since = "CURRENT_RUSTC_VERSION")]
11151115
#[must_use = "this returns the result of the operation, \
11161116
without modifying the original"]
11171117
#[inline]
11181118
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
11191119
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
1120-
self.as_secs_f32() / rhs.as_secs_f32()
1120+
let self_nanos = (self.secs as f32) * (NANOS_PER_SEC as f32) + (self.nanos.0 as f32);
1121+
let rhs_nanos = (rhs.secs as f32) * (NANOS_PER_SEC as f32) + (rhs.nanos.0 as f32);
1122+
self_nanos / rhs_nanos
11211123
}
11221124
}
11231125

‎core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(core_private_bignum)]
3030
#![feature(core_private_diy_float)]
3131
#![feature(dec2flt)]
32-
#![feature(div_duration)]
3332
#![feature(duration_abs_diff)]
3433
#![feature(duration_consts_float)]
3534
#![feature(duration_constants)]

0 commit comments

Comments
 (0)
Please sign in to comment.