File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -52,16 +52,16 @@ Functions
5252
5353 Hash a C double number.
5454
55- * Set *\* result * to the hash and return ``1 `` if *value * is finite or is
55+ * Set *\* result * to the hash and return ``0 `` if *value * is finite or is
5656 infinity.
5757 * Set *\* result * to :data: `sys.hash_info.nan <sys.hash_info> ` (``0 ``) and
58- return ``0 `` if *value* is not-a-number (NaN).
58+ return ``1 `` if *value* is not-a-number (NaN).
5959
6060 *result* must not be ``NULL``.
6161
6262 .. note::
63- Only rely on the function return value to distinguish the " not-a-number"
64- case. *\*result* can be ``0`` if *value* is finite. For example,
63+ Only rely on the function return value to distinguish the not-a-number
64+ (NaN) case. *\*result* can be ``0`` if *value* is finite. For example,
6565 ``Py_HashDouble(0.0, &result)`` sets *\*result* to 0.
6666
6767 .. versionadded:: 3.13
Original file line number Diff line number Diff line change @@ -35,10 +35,13 @@ def test_hash_getfuncdef(self):
3535
3636 def test_hash_double (self ):
3737 # Test Py_HashDouble()
38+ #
39+ # _Py_HashDouble() is tested indirectly by test_float in test_hash()
40+ # and test_hash_nan().
3841 hash_double = _testcapi .hash_double
3942
4043 def check_number (value , expected ):
41- self .assertEqual (hash_double (value ), (1 , expected ))
44+ self .assertEqual (hash_double (value ), (0 , expected ))
4245
4346 # test some integers
4447 integers = [
@@ -74,4 +77,4 @@ def check_number(value, expected):
7477 check_number (- x , hash (- x ))
7578
7679 # test not-a-number (NaN)
77- self .assertEqual (hash_double (float ('nan' )), (0 , sys .hash_info .nan ))
80+ self .assertEqual (hash_double (float ('nan' )), (1 , sys .hash_info .nan ))
Original file line number Diff line number Diff line change @@ -95,12 +95,12 @@ Py_HashDouble(double v, Py_hash_t *result)
9595 if (!Py_IS_FINITE (v )) {
9696 if (Py_IS_INFINITY (v )) {
9797 * result = (v > 0 ? _PyHASH_INF : - _PyHASH_INF );
98- return 1 ;
98+ return 0 ;
9999 }
100100 else {
101101 assert (Py_IS_NAN (v ));
102102 * result = _PyHASH_NAN ;
103- return 0 ;
103+ return 1 ;
104104 }
105105 }
106106
@@ -134,7 +134,7 @@ Py_HashDouble(double v, Py_hash_t *result)
134134 if (x == (Py_uhash_t )- 1 )
135135 x = (Py_uhash_t )- 2 ;
136136 * result = (Py_hash_t )x ;
137- return 1 ;
137+ return 0 ;
138138}
139139
140140Py_hash_t
@@ -143,7 +143,7 @@ _Py_HashDouble(PyObject *obj, double v)
143143 assert (obj != NULL );
144144
145145 Py_hash_t hash ;
146- if (Py_HashDouble (v , & hash ) == 0 ) {
146+ if (Py_HashDouble (v , & hash ) == 1 ) {
147147 hash = _Py_HashPointer (obj );
148148 }
149149 return hash ;
You can’t perform that action at this time.
0 commit comments