spicysharkco commented on code in PR #3476:
URL: https://github.com/apache/iceberg-rust/pull/3476#discussion_r4355430876


##########
crates/iceberg/src/spec/values/tests.rs:
##########
@@ -187,6 +187,53 @@ fn json_double() {
     );
 }
 
+const FLOAT_VALUES: [f32; 6] = [
+    100.1,
+    123.456,
+    -123.456,
+    f32::MAX,
+    f32::MIN,
+    f32::from_bits(1),
+];
+
+#[test]
+fn raw_literal_json_number_to_float() {
+    for value in FLOAT_VALUES {
+        let raw: RawLiteral = 
serde_json::from_str(&format!("{value:e}")).unwrap();
+
+        assert_eq!(
+            raw.try_into(&Primitive(PrimitiveType::Float)).unwrap(),
+            Some(Literal::float(value))
+        );
+    }
+}
+
+#[test]
+fn raw_literal_avro_double_to_float() {
+    for value in FLOAT_VALUES {
+        for double in [f64::from(value), 
format!("{value:e}").parse().unwrap()] {
+            let raw: RawLiteral = 
apache_avro::from_value(&Value::Double(double)).unwrap();
+
+            assert_eq!(
+                raw.try_into(&Primitive(PrimitiveType::Float)).unwrap(),
+                Some(Literal::float(value))
+            );
+        }
+    }
+}
+
+#[test]
+fn raw_literal_double_without_exact_float_narrows_to_nearest() {

Review Comment:
   Added in 45af223: 
`raw_literal_avro_non_finite_and_negative_zero_double_to_float`, right after 
this test. It goes through Avro `Value::Double`, since JSON can't hold NaN or 
infinity. NaN stays NaN, both infinities keep their sign, and `-0.0` keeps its 
sign bit. It compares bits, because `OrderedFloat` treats `-0.0` and `0.0` as 
equal. It passes on main as well, and fails if the arm rejects non-finite input 
or drops the sign of zero.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to