From 99b5c72283b73a199e8b7d8a79f40b9c85c8a76b Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sat, 13 Jun 2009 22:48:55 +0200 Subject: [PATCH] Long doubles have extra, unused bits which should not be used for hashing --- src/c/hash.d | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/c/hash.d b/src/c/hash.d index 98d5febf0..0739c470e 100644 --- a/src/c/hash.d +++ b/src/c/hash.d @@ -59,7 +59,10 @@ _hash_eql(cl_hashkey h, cl_object x) return hash_string(h, (unsigned char*)&df(x), sizeof(df(x))); #ifdef ECL_LONG_FLOAT case t_longfloat: { - long double d = ecl_long_float(x); + /* We coerce to double because long double has extra bits + * that give rise to different hash key and are not + * meaningful */ + double d = ecl_long_float(x); return hash_string(h, (unsigned char*)&d, sizeof(d)); } #endif @@ -135,7 +138,10 @@ _hash_equal(int depth, cl_hashkey h, cl_object x) } # ifdef ECL_LONG_FLOAT case t_longfloat: { - long double f = ecl_long_float(x); + /* We coerce to double because long double has extra bits + * that give rise to different hash key and are not + * meaningful */ + double f = ecl_long_float(x); if (f == 0.0) f = 0.0; return hash_string(h, (unsigned char*)&f, sizeof(f)); }