-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
🐛 zv: Allow f32::NAN to be decoded too #1148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Is this WIP? I don't see any fixes in the PR.
Should be a Fixes, Did I mess up and assign it only as an Issue: ref rather than Fixes ref? Meh. I'll rewrite the commit msg and force push if you don't have any other review comments. |
338ca32
to
447eac5
Compare
I'm not referring to the wording. I don't see any code changes except addition of an assertion and a test case. Please check your changes. Perhaps you forgot to commit something? |
That assert change is really all there is to it, as it treated NAN values as "too big" to transform, causing an panic when de-serializing an NAN value. Try it yourself with the assert change reverted and you'll see the test-case fails. |
Why not error out instead? I don't think assert is a solution. |
Cause the the code already used assert's and I didn't feel that a drive-by bug fix should change the behaviour that much. |
It's not a behaviour change IMO. asserts are for invariants that must always hold. Clearly, that is not the case here. |
Wrapped up that change and folded the function into the deserializer.
The asserts in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we're talking. :)
As per those guidelines, please add an emoji prefix to the commits/PR title. You can just c&p it from here. |
The range check would fail on NAN, INFINITY and NEG_INFINITY even if they are completely valid things to decode. This does not promise that an encoded NAN will be bit-wise identical as the decoded NAN, but if signalling NAN is used that precisely the user can have a handful of more interesting problems. As the decoding of an invalid f64=>f32 shouldn't be a panic, but a proper error, it means that f64_to_be can better be folded into the code in the deserialiser. Since this is floating point, we may also have fun rounding errors as an f64 may be too _small_ to be represented in an f32 and we may thus have precision loss as well, that seems annoying to deal with so hopefully whomever notices that in the future will have a good time. As I looked at the code, it seems usize => u32/u8 will have the same "crash the program" kind of conversions in them as well. Fixes: dbus2#1145
fbb6e0c
to
aac2ac9
Compare
Emojis added, commits squashed. If there are more changes, you're welcome to do them. |
The range check would fail on NAN, INFINITY and NEG_INFINITY even if they are completely valid things to decode.
This does not promise that an encoded NAN will be bit-wise identical as the decoded NAN, but if signalling NAN is used that precisely the user can have a handful of more interesting problems.
Fixes #1145.