]> granicus.if.org Git - python/commitdiff
Added a new macro, Py_IS_FINITE(X). On windows there is an intrinsic for this and...
authorKristján Valur Jónsson <kristjan@ccpgames.com>
Thu, 25 May 2006 15:53:30 +0000 (15:53 +0000)
committerKristján Valur Jónsson <kristjan@ccpgames.com>
Thu, 25 May 2006 15:53:30 +0000 (15:53 +0000)
Include/pyport.h
Objects/floatobject.c
PC/pyconfig.h

index df44be698b069b0e0cd4158e754564bd14edbe5b..66726e8a43500079b90c078e6a5ad06c67dd2860 100644 (file)
@@ -295,6 +295,15 @@ extern "C" {
 #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
 #endif
 
+/* Py_IS_INFINITY(X)
+ * Return 1 if float or double arg is an infinity, else 0.
+ * This some archicetcures (windows) have intrisics for this, so a special
+ * macro for this particular test is useful
+ */
+#ifndef Py_IS_FINITE
+#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
+#endif
+
 /* HUGE_VAL is supposed to expand to a positive double infinity.  Python
  * uses Py_HUGE_VAL instead because some platforms are broken in this
  * respect.  We used to embed code in pyport.h to try to worm around that,
index 7650ae6934f133b563887ada657610cc738dfadd..fa090846692867ff442a2b52f9899fe55617fab2 100644 (file)
@@ -384,7 +384,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
        if (PyFloat_Check(w))
                j = PyFloat_AS_DOUBLE(w);
 
-       else if (Py_IS_INFINITY(i) || Py_IS_NAN(i)) {
+       else if (!Py_IS_FINITE(i)) {
                if (PyInt_Check(w) || PyLong_Check(w))
                        /* If i is an infinity, its magnitude exceeds any
                         * finite integer, so it doesn't matter which int we
@@ -802,10 +802,7 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
                 * bug; we let that slide in math.pow() (which currently
                 * reflects all platform accidents), but not for Python's **.
                 */
-                if (iv == -1.0 && !Py_IS_INFINITY(iw) && iw == iw) {
-                       /* XXX the "iw == iw" was to weed out NaNs.  This
-                        * XXX doesn't actually work on all platforms.
-                        */
+                if (iv == -1.0 && Py_IS_FINITE(iw)) {
                        /* Return 1 if iw is even, -1 if iw is odd; there's
                         * no guarantee that any C integral type is big
                         * enough to hold iw, so we have to check this
index a9c1613807b24101d3d7463c3cdc7075b69dc6ad..cb42131d4f06a05efa49a54f5aa6cfd7c3cdc5be 100644 (file)
@@ -162,6 +162,7 @@ typedef int pid_t;
 #include <float.h>
 #define Py_IS_NAN _isnan
 #define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X))
+#define Py_IS_FINITE(X) _finite(X)
 
 #endif /* _MSC_VER */