Repository: serde-rs/json (language: rust)

Issue:
Preserve sign on negative zero f32
`-0` is parsed as `0` for `f32` type.

Is it intentional? I know that this is an edge case, but this is somewhat important for my use case, because it technically two different values.

rustc 1.54.0, serde_json v1.0.67


Discussion / hints:

Fix patch:
diff --git a/src/de.rs b/src/de.rs
index 7cc9f9b8e..a2f34b908 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -434,8 +434,8 @@ impl<'de, R: Read<'de>> Deserializer<R> {
                 } else {
                     let neg = (significand as i64).wrapping_neg();
 
-                    // Convert into a float if we underflow.
-                    if neg > 0 {
+                    // Convert into a float if we underflow, or on `-0`.
+                    if neg >= 0 {
                         ParserNumber::F64(-(significand as f64))
                     } else {
                         ParserNumber::I64(neg)


Test patch:
diff --git a/tests/test.rs b/tests/test.rs
index 9fdf26cc7..d6a0e81c1 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -805,6 +805,7 @@ fn test_parse_u64() {
 #[test]
 fn test_parse_negative_zero() {
     for negative_zero in &[
+        "-0",
         "-0.0",
         "-0e2",
         "-0.0e2",