ZENOTME commented on code in PR #406:
URL: https://github.com/apache/iceberg-rust/pull/406#discussion_r1643673503
##########
crates/iceberg/src/spec/values.rs:
##########
@@ -2334,9 +2453,20 @@ mod _serde {
},
RawLiteralEnum::Float(v) => match ty {
Type::Primitive(PrimitiveType::Float) =>
Ok(Some(Literal::float(v))),
+ Type::Primitive(PrimitiveType::Double) => {
+ Ok(Some(Literal::double(f64::from(v))))
+ }
_ => Err(invalid_err("float")),
},
RawLiteralEnum::Double(v) => match ty {
+ Type::Primitive(PrimitiveType::Float) => {
+ let v = v as f32;
+ // Return error if the value has lost precision
+ if v as f64 != f64::from(v) {
Review Comment:
> These are special values, see
https://doc.rust-lang.org/std/primitive.f64.html#associatedconstant.NAN we can
check and convert them directly:
https://doc.rust-lang.org/std/primitive.f32.html#associatedconstant.NAN
If a f64 can convert to f32 losslessly, for `(v1)f64 -> (v2)f32 -> (v3)f64`,
bit pattern of v1 and v3 will be same. I think this rule matches all values, no
matter whether it's Nan, -0, or normal value, so that we can avoid branch here.🤔
--
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]