mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Use a more robust infinity check in _Py_HashDouble.
This fixes a test_decimal failure on FreeBSD 8.0. (modf apparently doesn't follow C99 Annex F on FreeBSD.)
This commit is contained in:
parent
0c08009708
commit
5e0c2748fb
2 changed files with 12 additions and 3 deletions
|
@ -1025,15 +1025,15 @@ _Py_HashDouble(double v)
|
|||
* of mapping keys will turn out weird.
|
||||
*/
|
||||
|
||||
if (Py_IS_INFINITY(v))
|
||||
/* can't convert to long int -- arbitrary */
|
||||
v = v < 0 ? -271828.0 : 314159.0;
|
||||
fractpart = modf(v, &intpart);
|
||||
if (fractpart == 0.0) {
|
||||
/* This must return the same hash as an equal int or long. */
|
||||
if (intpart > LONG_MAX/2 || -intpart > LONG_MAX/2) {
|
||||
/* Convert to long and use its hash. */
|
||||
PyObject *plong; /* converted to Python long */
|
||||
if (Py_IS_INFINITY(intpart))
|
||||
/* can't convert to long int -- arbitrary */
|
||||
v = v < 0 ? -271828.0 : 314159.0;
|
||||
plong = PyLong_FromDouble(v);
|
||||
if (plong == NULL)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue