From 12adaf9e1e5728a8e089a1a8c92d3f10d4d709a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=A4rber?= <01mf02@gmail.com> Date: Mon, 23 Dec 2024 11:17:06 +0100 Subject: [PATCH] Handle comparison between NaN and non-NaN values. Thanks to @workingjubilee for spotting this. () --- jaq-json/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jaq-json/src/lib.rs b/jaq-json/src/lib.rs index 863eb7de..6cad0f9f 100644 --- a/jaq-json/src/lib.rs +++ b/jaq-json/src/lib.rs @@ -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) } }