Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 13976:5ada9fa54801 legacy-trunk
Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.
This was a misleading bug -- the true "bug" was that hash(x) gave an error
return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to
pyport.h. Rearranged code to reduce growing duplication in hashing of float and
complex numbers, pushing Trent's earlier stab at that to a logical conclusion.
Fixed exceedingly rare bug where hashing of floats could return -1 even if there
wasn't an error (didn't waste time trying to construct a test case, it was simply
obvious from the code that it *could* happen). Improved complex hash so that
hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 15 Aug 2000 03:34:48 +0000 |
| parents | 648ba4044455 |
| children | 6e2dba45c83e |
line wrap: on
line diff
--- a/Objects/floatobject.c Tue Aug 15 01:13:23 2000 +0000 +++ b/Objects/floatobject.c Tue Aug 15 03:34:48 2000 +0000 @@ -326,44 +326,7 @@ static long float_hash(PyFloatObject *v) { - double intpart, fractpart; - long x; - /* This is designed so that Python numbers with the same - value hash to the same value, otherwise comparisons - of mapping keys will turn out weird */ - -#ifdef MPW /* MPW C modf expects pointer to extended as second argument */ -{ - extended e; - fractpart = modf(v->ob_fval, &e); - intpart = e; -} -#else - fractpart = modf(v->ob_fval, &intpart); -#endif - - if (fractpart == 0.0) { - if (intpart > LONG_MAX || -intpart > LONG_MAX) { - /* Convert to long int and use its hash... */ - PyObject *w = PyLong_FromDouble(v->ob_fval); - if (w == NULL) - return -1; - x = PyObject_Hash(w); - Py_DECREF(w); - return x; - } - x = (long)intpart; - } - else { - /* Note -- if you change this code, also change the copy - in complexobject.c */ - x = _Py_HashDouble(v->ob_fval); - if (x == -1) - return -1; - } - if (x == -1) - x = -2; - return x; + return _Py_HashDouble(v->ob_fval); } static PyObject *
