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
52
52
53
53
Hash a C double number.
54
54
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
56
56
infinity.
57
57
* 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).
59
59
60
60
*result* must not be ``NULL``.
61
61
62
62
.. 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,
65
65
``Py_HashDouble(0.0, &result)`` sets *\*result* to 0.
66
66
67
67
.. versionadded:: 3.13
Original file line number Diff line number Diff line change @@ -35,10 +35,13 @@ def test_hash_getfuncdef(self):
35
35
36
36
def test_hash_double (self ):
37
37
# Test Py_HashDouble()
38
+ #
8000
39
+ # _Py_HashDouble() is tested indirectly by test_float in test_hash()
40
+ # and test_hash_nan().
38
41
hash_double = _testcapi .hash_double
39
42
40
43
def check_number (value , expected ):
41
- self .assertEqual (hash_double (value ), (1 , expected ))
44
+ self .assertEqual (hash_double (value ), (0 , expected ))
42
45
43
46
# test some integers
44
47
integers = [
@@ -74,4 +77,4 @@ def check_number(value, expected):
74
77
check_number (- x , hash (- x ))
75
78
76
79
# 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)
95
95
if (!Py_IS_FINITE (v )) {
96
96
if (Py_IS_INFINITY (v )) {
97
97
* result = (v > 0 ? _PyHASH_INF : - _PyHASH_INF );
98
- return 1 ;
98
+ return 0 ;
99
99
}
100
100
else {
101
101
assert (Py_IS_NAN (v ));
102
102
* result = _PyHASH_NAN ;
103
- return 0 ;
103
+ return 1 ;
104
104
}
105
105
}
106
106
@@ -134,7 +134,7 @@ Py_HashDouble(double v, Py_hash_t *result)
134
134
if (x == (Py_uhash_t )- 1 )
135
135
x = (Py_uhash_t )- 2 ;
136
136
* result = (Py_hash_t )x ;
137
- return 1 ;
137
+ return 0 ;
138
138
}
139
139
140
140
Py_hash_t
@@ -143,7 +143,7 @@ _Py_HashDouble(PyObject *obj, double v)
143
143
assert (obj != NULL );
144
144
145
145
Py_hash_t hash ;
146
- if (Py_HashDouble (v , & hash ) == 0 ) {
146
+ if (Py_HashDouble (v , & hash ) == 1 ) {
147
147
hash = _Py_HashPointer (obj );
148
148
}
149
149
return hash ;
You can’t perform that action at this time.
0 commit comments