about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbeetrees <b@beetr.ee>2022-10-14 15:51:20 +0100
committerbeetrees <b@beetr.ee>2022-10-14 16:07:09 +0100
commitc9948f5c5f5cc49a74f04e33a1b0cf6ed6a22b93 (patch)
tree7be0deaf4717f764422d6e88985dcbba16ffebdf
parent9b0a099dfc9a97ecd10adb319396c731c4b2d169 (diff)
downloadrust-c9948f5c5f5cc49a74f04e33a1b0cf6ed6a22b93.tar.gz
rust-c9948f5c5f5cc49a74f04e33a1b0cf6ed6a22b93.zip
Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`
-rw-r--r--library/core/src/time.rs2
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/time.rs8
3 files changed, 10 insertions, 1 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index 1d0c51c3c83..7cbb477d7a3 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -1279,7 +1279,7 @@ macro_rules! try_from_secs {
         const MANT_MASK: $bits_ty = (1 << $mant_bits) - 1;
         const EXP_MASK: $bits_ty = (1 << $exp_bits) - 1;
 
-        if $secs.is_sign_negative() {
+        if $secs < 0.0 {
             return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::Negative });
         }
 
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index ca0c7a54b3e..525a495903d 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -101,6 +101,7 @@
 #![feature(provide_any)]
 #![feature(utf8_chunks)]
 #![feature(is_ascii_octdigit)]
+#![feature(duration_checked_float)]
 #![deny(unsafe_op_in_unsafe_fn)]
 
 extern crate test;
diff --git a/library/core/tests/time.rs b/library/core/tests/time.rs
index 697bf33a8b0..a05128de471 100644
--- a/library/core/tests/time.rs
+++ b/library/core/tests/time.rs
@@ -467,3 +467,11 @@ fn duration_const() {
     const SATURATING_MUL: Duration = MAX.saturating_mul(2);
     assert_eq!(SATURATING_MUL, MAX);
 }
+
+#[test]
+fn from_neg_zero() {
+    assert_eq!(Duration::try_from_secs_f32(-0.0), Ok(Duration::ZERO));
+    assert_eq!(Duration::try_from_secs_f64(-0.0), Ok(Duration::ZERO));
+    assert_eq!(Duration::from_secs_f32(-0.0), Duration::ZERO);
+    assert_eq!(Duration::from_secs_f64(-0.0), Duration::ZERO);
+}