test for nan

Jeff Epler jepler at unpythonic.net
Tue Mar 30 23:11:42 CEST 2004


If your system has isnan() then you could use a small pyrex module to
expose these functions to Python:
    cdef extern from "math.h":
        int finite_ "finite" (double value)
        int isinf_ "isinf"(double value)
        int isnan_ "isnan"(double value)

    def finite(double x):
        return finite_(x)
    def isinf(double x):
        return isinf_(x)
    def isnan(double x):
        return isnan_(x)
note that isinf/isnan/finite are not part of the ISO C or POSIX specs,
according to my manpage.  Your system may have a different, also
non-portable way of finding NaN values.

Jeff
PS pyrex is at http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/




More information about the Python-list mailing list