Skip to content

Commit d7ea122

Browse files
committed
Fix #928 - Fix hashing of negative 0.
1 parent 56ba1d9 commit d7ea122

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/core/value.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int32_t janet_hash(Janet x) {
322322
uint64_t u;
323323
} as;
324324
as.d = janet_unwrap_number(x);
325+
as.d = as.d == 0 ? 0 : as.d; /* normalize negative 0 */
325326
uint32_t lo = (uint32_t)(as.u & 0xFFFFFFFF);
326327
uint32_t hi = (uint32_t)(as.u >> 32);
327328
uint32_t hilo = (hi ^ lo) * 2654435769u;

test/suite0011.janet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@
4848

4949
(assert (= (test) '(1 ())) "issue #919")
5050

51+
(assert (= (hash 0) (hash (* -1 0))) "hash -0 same as hash 0")
52+
5153
(end-suite)
5254

0 commit comments

Comments
 (0)