-
Notifications
You must be signed in to change notification settings - Fork 78
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
NaN compatibility #248
NaN compatibility #248
Conversation
which breaks basic laws about total orders.) | ||
|
||
Like jq, jaq prints `nan` and `infinite` as `null` in JSON, | ||
because JSON does not support encoding these values as numbers. |
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.
Was intentional to remove the part about null as JSON?
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.
Yes, because that section is about differences wrt jq, not about resemblances. In the same spirit, I have already removed other sections that once talked about a difference, but later became obsolete (in particular the section on recursive functions).
Thanks for having had a look at this, @wader! |
} else if left.is_nan() && right.is_nan() { | ||
// there are more than 50 shades of NaN, and which of these | ||
// you strike when you perform a calculation is not deterministic (!), | ||
// therefore `total_cmp` may yield different results for the same calculation | ||
// so we bite the bullet and handle this like in jq | ||
Ordering::Less | ||
} else { | ||
f64::total_cmp(&left, &right) |
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.
This code still allows for -NaN and +NaN comparison nondeterminism when one of the inputs is non-NaN.
Thanks to @workingjubilee for spotting this. (<#248 (comment)>)
This aligns jaq's and jq's handling of NaN (not a number), by enforcing
nan < nan
.Before this change, it could happen that operations that yielded
nan
could have introduced non-deterministic behaviour, see #243. With this PR, the non-deterministic floating-point behaviour is still there, but it should not be observable anymore.