ZENOTME commented on code in PR #406:
URL: https://github.com/apache/iceberg-rust/pull/406#discussion_r1642947050
##########
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:
> Surely in almost all cases precision will be lost unless the last 29 bits
of the f64's fraction are all zeroes (which is about 1 in half a billion), as
this comparison will be bitwise?
I think the check here is to deal with the case that serialize f32 to f64
and deserialize back to f32. In this case, there is no precision loss.
For the case loss precision, which means that the deserializer want to
deserialize a f64 to f32. I think this means something wrong happen. 🤔
> Should we have special checks for NaN / -Inf / +Inf (possibly -0.0 also?)
I agree with this.
--
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]