diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-11-20 21:09:53 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-11-20 21:09:53 -0800 |
commit | 0242cf2e537bc1faad5c4650e6e06e4eac6b6d23 (patch) | |
tree | e11e715bafd90a5197a95cbc5098a2ebc681064b | |
parent | a5686c55fe54f537315ad4f1515525758e6b9973 (diff) | |
download | txr-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.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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; } |