[Python-checkins] r79805 - in python/branches/py3k: Lib/test/test_float.py Objects/object.c
mark.dickinson
python-checkins at python.org
Mon Apr 5 20:09:40 CEST 2010
Author: mark.dickinson
Date: Mon Apr 5 20:09:39 2010
New Revision: 79805
Log:
Merged revisions 79804 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79804 | mark.dickinson | 2010-04-05 19:07:51 +0100 (Mon, 05 Apr 2010) | 5 lines
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.)
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_float.py
python/branches/py3k/Objects/object.c
Modified: python/branches/py3k/Lib/test/test_float.py
==============================================================================
--- python/branches/py3k/Lib/test/test_float.py (original)
+++ python/branches/py3k/Lib/test/test_float.py Mon Apr 5 20:09:39 2010
@@ -914,6 +914,15 @@
self.assertFalse(NAN.is_inf())
self.assertFalse((0.).is_inf())
+ def test_hash_inf(self):
+ # the actual values here should be regarded as an
+ # implementation detail, but they need to be
+ # identical to those used in the Decimal module.
+ self.assertEqual(hash(float('inf')), 314159)
+ self.assertEqual(hash(float('-inf')), -271828)
+ self.assertEqual(hash(float('nan')), 0)
+
+
fromHex = float.fromhex
toHex = float.hex
class HexFloatTestCase(unittest.TestCase):
Modified: python/branches/py3k/Objects/object.c
==============================================================================
--- python/branches/py3k/Objects/object.c (original)
+++ python/branches/py3k/Objects/object.c Mon Apr 5 20:09:39 2010
@@ -656,15 +656,15 @@
* 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;
More information about the Python-checkins
mailing list