diff options
-rw-r--r-- | lib.c | 5 | ||||
-rw-r--r-- | tests/custom/04_bugs/30_nan_strict_equality | 14 | ||||
-rw-r--r-- | types.c | 2 |
3 files changed, 20 insertions, 1 deletions
@@ -2921,6 +2921,11 @@ uc_uniq_ucv_equal(const void *k1, const void *k2) if (!ucv_is_scalar(uv1) && !ucv_is_scalar(uv2)) return (uv1 == uv2); + /* for the sake of array item uniqueness, treat two NaNs as equal */ + if (ucv_type(uv1) == UC_DOUBLE && ucv_type(uv2) == UC_DOUBLE && + isnan(ucv_double_get(uv1)) && isnan(ucv_double_get(uv2))) + return true; + return ucv_is_equal(uv1, uv2); } diff --git a/tests/custom/04_bugs/30_nan_strict_equality b/tests/custom/04_bugs/30_nan_strict_equality new file mode 100644 index 0000000..4ec32e2 --- /dev/null +++ b/tests/custom/04_bugs/30_nan_strict_equality @@ -0,0 +1,14 @@ +When comparing `nan` with `nan` for strict equality or inequality, the +VM incorrectly treated the result as `true` or `false` respectively. + +-- Testcase -- +{{ NaN === NaN }} +{{ NaN !== NaN }} +{{ uniq([NaN, NaN]) }} +-- End -- + +-- Expect stdout -- +false +true +[ "NaN" ] +-- End -- @@ -1764,7 +1764,7 @@ ucv_is_equal(uc_value_t *uv1, uc_value_t *uv2) if (t1 != t2) return false; - if (uv1 == uv2) + if (t1 != UC_DOUBLE && uv1 == uv2) return true; switch (t1) { |