Complex NaN from Cython

296 views
Skip to first unread message

Yosef

unread,
Nov 4, 2009, 5:14:28 AM11/4/09
to cython-users
Hi there'

I'm writing a function getting complex arguments and need to check
whether the complex argument is NaN. I could import isnan from NumPy,
but that would force a C->Python->C path for the arguments and cancel
most of the advantage of using Cython.

I was hoping there would be an importable C definition of complex
NaN, but I don't see any such definition in NumPy, or Cython
documentation or in complex.h.

Is there a better way to do it?

Thanks,
Yosef.

Robert Bradshaw

unread,
Nov 4, 2009, 5:21:23 AM11/4/09
to cython...@googlegroups.com

One option is to do "isnan(z.real) or isnan(z.imag)"

- Robert


Dag Sverre Seljebotn

unread,
Nov 4, 2009, 5:28:59 AM11/4/09
to cython...@googlegroups.com

...where "isnan" is imported from math.h:

cdef extern from "math.h":
bint isnan(double x)

cdef inline bint isnanc(double complex x):
return isnan(x.real) or isnan(x.imag)

Dag Sverre

Yosef

unread,
Nov 5, 2009, 2:05:24 AM11/5/09
to cython-users
That does the trick.

Thanks,
yosef.

On 4 נובמבר, 12:28, "Dag Sverre Seljebotn"
Reply all
Reply to author
Forward
0 new messages