mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Introduced a Py_IS_NAN macro, which probably works on the major platforms
today. pyconfig.h can override it if not, and can also override Py_IS_INFINITY now. Py_IS_NAN and Py_IS_INFINITY are overridden now for Microsoft compilers, using efficient MS-specific spellings.
This commit is contained in:
parent
307fa78107
commit
862f0593d8
3 changed files with 26 additions and 3 deletions
|
|
@ -219,14 +219,29 @@ extern "C" {
|
||||||
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
|
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Py_IS_NAN(X)
|
||||||
|
* Return 1 if float or double arg is a NaN, else 0.
|
||||||
|
* Caution:
|
||||||
|
* X is evaluated more than once.
|
||||||
|
* This may not work on all platforms. Each platform has *some*
|
||||||
|
* way to spell this, though -- override in pyconfig.h if you have
|
||||||
|
* a platform where it doesn't work.
|
||||||
|
*/
|
||||||
|
#ifndef Py_IS_NAN
|
||||||
|
#define Py_IS_NAN(X) ((X) != (X))
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Py_IS_INFINITY(X)
|
/* Py_IS_INFINITY(X)
|
||||||
* Return 1 if float or double arg is an infinity, else 0.
|
* Return 1 if float or double arg is an infinity, else 0.
|
||||||
* Caution:
|
* Caution:
|
||||||
* X is evaluated more than once.
|
* X is evaluated more than once.
|
||||||
* This implementation may set the underflow flag if |X| is very small;
|
* This implementation may set the underflow flag if |X| is very small;
|
||||||
* it really can't be implemented correctly (& easily) before C99.
|
* it really can't be implemented correctly (& easily) before C99.
|
||||||
|
* Override in pyconfig.h if you have a better spelling on your platform.
|
||||||
*/
|
*/
|
||||||
|
#ifndef Py_IS_INFINITY
|
||||||
#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
|
#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
|
||||||
|
#endif
|
||||||
|
|
||||||
/* HUGE_VAL is supposed to expand to a positive double infinity. Python
|
/* HUGE_VAL is supposed to expand to a positive double infinity. Python
|
||||||
* uses Py_HUGE_VAL instead because some platforms are broken in this
|
* uses Py_HUGE_VAL instead because some platforms are broken in this
|
||||||
|
|
@ -257,12 +272,12 @@ extern "C" {
|
||||||
* Some platforms have better way to spell this, so expect some #ifdef'ery.
|
* Some platforms have better way to spell this, so expect some #ifdef'ery.
|
||||||
*
|
*
|
||||||
* OpenBSD uses 'isinf()' because a compiler bug on that platform causes
|
* OpenBSD uses 'isinf()' because a compiler bug on that platform causes
|
||||||
* the longer macro version to be mis-compiled. This isn't optimal, and
|
* the longer macro version to be mis-compiled. This isn't optimal, and
|
||||||
* should be removed once a newer compiler is available on that platform.
|
* should be removed once a newer compiler is available on that platform.
|
||||||
* The system that had the failure was running OpenBSD 3.2 on Intel, with
|
* The system that had the failure was running OpenBSD 3.2 on Intel, with
|
||||||
* gcc 2.95.3.
|
* gcc 2.95.3.
|
||||||
*
|
*
|
||||||
* According to Tim's checkin, the FreeBSD systems use isinf() to work
|
* According to Tim's checkin, the FreeBSD systems use isinf() to work
|
||||||
* around a FPE bug on that platform.
|
* around a FPE bug on that platform.
|
||||||
*/
|
*/
|
||||||
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,11 @@ Library
|
||||||
Build
|
Build
|
||||||
-----
|
-----
|
||||||
|
|
||||||
...
|
- pyport.h now defines a Py_IS_NAN macro. It works as-is when the
|
||||||
|
platform C computes true for ``x != x`` if and only if X is a NaN.
|
||||||
|
Other platforms can override the default definition with a platform-
|
||||||
|
specific spelling in that platform's pyconfig.h. You can also override
|
||||||
|
pyport.h's default Py_IS_INFINITY definition now.
|
||||||
|
|
||||||
C API
|
C API
|
||||||
-----
|
-----
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,10 @@ MS_CORE_DLL.
|
||||||
typedef int pid_t;
|
typedef int pid_t;
|
||||||
#define hypot _hypot
|
#define hypot _hypot
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
#define Py_IS_NAN _isnan
|
||||||
|
#define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X))
|
||||||
|
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
/* define some ANSI types that are not defined in earlier Win headers */
|
/* define some ANSI types that are not defined in earlier Win headers */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue