Skip to content

Commit

Permalink
Handle comparison between NaN and non-NaN values.
Browse files Browse the repository at this point in the history
Thanks to @workingjubilee for spotting this.
(<#248 (comment)>)
  • Loading branch information
01mf02 committed Dec 23, 2024
1 parent db2d383 commit 12adaf9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions jaq-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,15 @@ fn float_cmp(left: f64, right: f64) -> Ordering {
if left == 0. && right == 0. {
// consider negative and positive 0 as equal
Ordering::Equal
} else if left.is_nan() && right.is_nan() {
} else if left.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 {
} else if right.is_nan() {
Ordering::Greater
} else
f64::total_cmp(&left, &right)
}
}

Check failure on line 905 in jaq-json/src/lib.rs

View workflow job for this annotation

GitHub Actions / build i686-unknown-linux-gnu

unexpected closing delimiter: `}`

Check failure on line 905 in jaq-json/src/lib.rs

View workflow job for this annotation

GitHub Actions / build x86_64-unknown-linux-gnu

unexpected closing delimiter: `}`
Expand Down

0 comments on commit 12adaf9

Please sign in to comment.