From 224a72b55144f4c098295d947c4bd26da56c2c68 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Nov 2022 21:09:53 -0800 Subject: hash: floating: handle negative zero. * hash.c (hash_double): If the input is equal to 0.0, return 0, so that both negative and positive zero have the same hash value. --- hash.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hash.c b/hash.c index d71f0e20..7f0f0b6a 100644 --- a/hash.c +++ b/hash.c @@ -291,10 +291,12 @@ static ucnum hash_double(double n) ucnum h = 0; unsigned i; - u.d = n; + if (n != 0.0) { + u.d = n; - for (i = 0; i < sizeof u.a / sizeof u.a[0]; i++) - h += u.a[i]; + for (i = 0; i < sizeof u.a / sizeof u.a[0]; i++) + h += u.a[i]; + } return h; } -- cgit v1.2.3