summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hash.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index 34247e64..e5f00ecf 100644
--- a/hash.c
+++ b/hash.c
@@ -181,14 +181,17 @@ static u32_t hash_buf(const mem_t *ptr, ucnum size, u32_t seed)
static ucnum hash_double(double n)
{
+ union hack {
+ volatile double d;
+ volatile ucnum a[sizeof (double) / sizeof (ucnum)];
+ } u;
ucnum h = 0;
+ int i;
- mem_t *p = coerce(mem_t *, &n), *q = p + sizeof(double);
+ u.d = n;
- while (p < q) {
- h = h << 8 | h >> (8 * sizeof h - 1);
- h += *p++;
- }
+ for (i = 0; i < sizeof u.a / sizeof u.a[0]; i++)
+ h += u.a[i];
return h;
}