Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1.1 binary reader support for floats #756

Merged
merged 4 commits into from
May 10, 2024

Conversation

nirosys
Copy link
Contributor

@nirosys nirosys commented May 1, 2024

Issue #, if available: #662

Description of changes:
Add support for floats to the 1.1 binary raw reader.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@nirosys nirosys marked this pull request as ready for review May 1, 2024 22:38
@nirosys nirosys requested a review from zslayton May 6, 2024 19:47
src/lazy/binary/raw/v1_1/value.rs Show resolved Hide resolved
Comment on lines 304 to 378
macro_rules! assert_closely_eq {
($x:expr, $y:expr, $d:expr) => {
let (a, b) = ($x, $y);
if ((a - b).abs() >= $d) {
panic!(
"float not close enough to expected value: left: {}, right: {}",
a, b
);
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For serialization/deserialization, I don't think we should be considering any epsilon value. A round trip of a float value should result in a value that is equivalent to the original value, and (for non-NaN values) I that means we should expect actual equality of the actual and expected values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. If roundtripping from f64 -> f32 -> f64 results in a different value, then f32 isn't a valid encoding of that value. You can use IonEq::ion_eq to compare floats with the expected NaN handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea, thank you for calling this out. I had originally intended to round-trip "friendly" float literals and use this so I wasn't using the true float value for comparison. I didn't go that route, and forgot to remove this.

@nirosys nirosys force-pushed the rgiliam/1_1_binary_reader_floats branch 2 times, most recently from 30771a9 to 0f301c8 Compare May 8, 2024 00:26
@@ -109,6 +110,8 @@ impl Header {
use LengthType::*;
match (self.ion_type_code, self.length_code) {
(OpcodeType::Boolean, 0xE..=0xF) => InOpcode(0),
(OpcodeType::Float, 0xA) => InOpcode(0),
(OpcodeType::Float, 0xB..=0xD) => InOpcode(1 << (self.length_code - 0xA)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 << (self.length_code - 0xA)

Nice!

src/lazy/binary/raw/v1_1/value.rs Outdated Show resolved Hide resolved
@nirosys nirosys force-pushed the rgiliam/1_1_binary_reader_floats branch from 0f301c8 to 9c9166d Compare May 10, 2024 21:38
@nirosys nirosys force-pushed the rgiliam/1_1_binary_reader_floats branch from 9c9166d to 91b37d7 Compare May 10, 2024 23:05
@nirosys nirosys merged commit ba7718d into amazon-ion:main May 10, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants