From a7ceda6b2869fe6c19199936e6f1eeeac3902526 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 21 Apr 2023 16:51:52 +0300 Subject: [PATCH] fix float NaN comparison --- src/core/stuff.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/stuff.h b/src/core/stuff.h index 62307411..e682d358 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -243,9 +243,17 @@ void noop_visit(Value* x); #endif #define CMP(W,X) ({ AUTO wt = (W); AUTO xt = (X); (wt>xt?1:0)-(wtx) - !(w>=x); // slightly better codegen from being able to reuse the same compare instruction + #else + return (w>x) - (wx, 0 if w≡x; 0==compare(NaN,NaN) - if (isNum(w) & isNum(x)) return CMP(o2fG(w), o2fG(x)); +static i32 compare(B w, B x) { // doesn't consume; -1 if wx, 0 if w≡x + if (isNum(w) & isNum(x)) return compareFloat(o2fG(w), o2fG(x)); if (isC32(w) & isC32(x)) return CMP(o2cG(w), o2cG(x)); return compareF(w, x); }