[Numpy-discussion] isinf raises in inf

Charles R Harris charlesr.harris at gmail.com
Fri Jul 16 09:12:20 EDT 2010


On Fri, Jul 16, 2010 at 2:27 AM, Pauli Virtanen <pav at iki.fi> wrote:

> Thu, 15 Jul 2010 19:09:15 -0600, Charles R Harris wrote:
> [clip]
> > PS, of course we should fix the macro also. Since the bit values of +/-
> > infinity are known we should be able to define them as constants using a
> > couple of ifdefs and unions.
>
> We already do that, NPY_INFINITY and -NPY_INFINITY.
>
> [clip]
> > int
> > (isinf)(double x)
> > {
> >     if ((-1.0 < x) && (x < 1.0))    /* x is small, and thus finite */
> >     return (0);
> >     else if ((x + x) == x)        /* only true if x == Infinity */
> >     return (1);
> >     else              /* must be finite (normal or subnormal), or NaN */
> >     return (0);
> > }
>
> This function can generate overflows, for example for
>
>        x = 0.6 * np.finfo(np.float64).max
>
>
Yep, but the test still works correctly. Unless overflow can somehow be
flagged to raise an error. Beebe is usually pretty careful...

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100716/82001f82/attachment.html>


More information about the NumPy-Discussion mailing list