mirror of
https://github.com/python/cpython
synced 2026-09-29 09:40:29 +03:00
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.
This commit is contained in:
parent
7aced17437
commit
39dce29365
5 changed files with 83 additions and 101 deletions
|
|
@ -103,7 +103,7 @@ extern "C" {
|
|||
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
|
||||
#endif
|
||||
|
||||
/* Py_FORCE_EXPANSION
|
||||
/* Py_FORCE_EXPANSION(X)
|
||||
* "Simply" returns its argument. However, macro expansions within the
|
||||
* argument are evaluated. This unfortunate trickery is needed to get
|
||||
* token-pasting to work as desired in some cases.
|
||||
|
|
@ -123,6 +123,14 @@ extern "C" {
|
|||
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
|
||||
#endif
|
||||
|
||||
/* Py_IS_INFINITY(X)
|
||||
* Return 1 if float or double arg is an infinity, else 0.
|
||||
* Caution:
|
||||
* X is evaluated more than once.
|
||||
* This implementation may set the underflow flag if |X| is very small;
|
||||
* it really can't be implemented correctly (& easily) before C99.
|
||||
*/
|
||||
#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
|
||||
|
||||
/**************************************************************************
|
||||
Prototypes that are missing from the standard include files on some systems
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue