From d7ea122cf7ff93588f8571fae84ad4091704bf08 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 4 Mar 2022 19:49:39 -0600 Subject: [PATCH] Fix #928 - Fix hashing of negative 0. --- src/core/value.c | 1 + test/suite0011.janet | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/core/value.c b/src/core/value.c index a29c48d0..e742e364 100644 --- a/src/core/value.c +++ b/src/core/value.c @@ -322,6 +322,7 @@ int32_t janet_hash(Janet x) { uint64_t u; } as; as.d = janet_unwrap_number(x); + as.d = as.d == 0 ? 0 : as.d; /* normalize negative 0 */ uint32_t lo = (uint32_t)(as.u & 0xFFFFFFFF); uint32_t hi = (uint32_t)(as.u >> 32); uint32_t hilo = (hi ^ lo) * 2654435769u; diff --git a/test/suite0011.janet b/test/suite0011.janet index 3f23aed0..a4d40495 100644 --- a/test/suite0011.janet +++ b/test/suite0011.janet @@ -48,5 +48,7 @@ (assert (= (test) '(1 ())) "issue #919") +(assert (= (hash 0) (hash (* -1 0))) "hash -0 same as hash 0") + (end-suite)