summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-11-20 21:09:53 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-11-20 21:09:53 -0800
commit0242cf2e537bc1faad5c4650e6e06e4eac6b6d23 (patch)
treee11e715bafd90a5197a95cbc5098a2ebc681064b
parenta5686c55fe54f537315ad4f1515525758e6b9973 (diff)
downloadtxr-0242cf2e537bc1faad5c4650e6e06e4eac6b6d23.tar.gz
txr-0242cf2e537bc1faad5c4650e6e06e4eac6b6d23.tar.bz2
txr-0242cf2e537bc1faad5c4650e6e06e4eac6b6d23.zip
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.
-rw-r--r--hash.c8
1 files 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;
}