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 48a835b

Browse files
authoredMay 14, 2024
Divide float nanoseconds instead of seconds
1 parent 0342284 commit 48a835b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎core/src/time.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,9 @@ impl Duration {
10741074
#[inline]
10751075
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
10761076
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
1077-
self.as_secs_f64() / rhs.as_secs_f64()
1077+
let self_nanos = (self.secs as f64) * (NANOS_PER_SEC as f64) + (self.nanos.0 as f64);
1078+
let rhs_nanos = (rhs.secs as f64) * (NANOS_PER_SEC as f64) + (rhs.nanos.0 as f64);
1079+
self_nanos / rhs_nanos
10781080
}
10791081

10801082
/// Divide `Duration` by `Duration` and return `f32`.
@@ -1093,7 +1095,9 @@ impl Duration {
10931095
#[inline]
10941096
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
10951097
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
1096-
self.as_secs_f32() / rhs.as_secs_f32()
1098+
let self_nanos = (self.secs as f32) * (NANOS_PER_SEC as f32) + (self.nanos.0 as f32);
1099+
let rhs_nanos = (rhs.secs as f32) * (NANOS_PER_SEC as f32) + (rhs.nanos.0 as f32);
1100+
self_nanos / rhs_nanos
10971101
}
10981102
}
10991103

0 commit comments

Comments
 (0)
Failed to load comments.