about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArtyom Pavlov <newpavlov@gmail.com>2024-05-15 00:38:34 +0300
committerGitHub <noreply@github.com>2024-05-15 00:38:34 +0300
commit8da41b107debc95250078049eae63e5ab3601476 (patch)
treea230dbc380e63b912f71c5d82b12a35b8f524158
parent6d223bb6a1f54eacd57e14d5fc323f97f12e5005 (diff)
downloadrust-8da41b107debc95250078049eae63e5ab3601476.tar.gz
rust-8da41b107debc95250078049eae63e5ab3601476.zip
Divide float nanoseconds instead of seconds
-rw-r--r--library/core/src/time.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index a4de3d099b3..bbeacac0510 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -1074,7 +1074,9 @@ impl Duration {
     #[inline]
     #[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
     pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
-        self.as_secs_f64() / rhs.as_secs_f64()
+        let self_nanos = (self.secs as f64) * (NANOS_PER_SEC as f64) + (self.nanos.0 as f64);
+        let rhs_nanos = (rhs.secs as f64) * (NANOS_PER_SEC as f64) + (rhs.nanos.0 as f64);
+        self_nanos / rhs_nanos
     }
 
     /// Divide `Duration` by `Duration` and return `f32`.
@@ -1093,7 +1095,9 @@ impl Duration {
     #[inline]
     #[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
     pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
-        self.as_secs_f32() / rhs.as_secs_f32()
+        let self_nanos = (self.secs as f32) * (NANOS_PER_SEC as f32) + (self.nanos.0 as f32);
+        let rhs_nanos = (rhs.secs as f32) * (NANOS_PER_SEC as f32) + (rhs.nanos.0 as f32);
+        self_nanos / rhs_nanos
     }
 }