avoid undefined behavior in hashing inexacts

Casting a negative floating-point number to an unsigned integer
is not ok. Corece to a signed integer, first.

Thanks to John Regehr for help.
This commit is contained in:
Matthew Flatt 2015-09-18 09:25:26 -06:00
parent b7bcd4f687
commit 0b9cda5018

View File

@ -1117,7 +1117,7 @@ XFORM_NONGCING static uintptr_t dbl_hash_val(double d)
d = frexp(d, &e);
}
return ((uintptr_t)(d * (1 << 30))) + e;
return ((uintptr_t)(intptr_t)(d * (1 << 30))) + (uintptr_t)e;
}
XFORM_NONGCING static uintptr_t dbl_hash2_val(double d)