How to assign NaN values for cdef floats and other cython types

1,837 views
Skip to first unread message

pytrade

unread,
May 25, 2011, 3:45:04 PM5/25/11
to cython-users
Is there something equivalent to np.nan in cython that I can assign to
cython variables?

Robert Bradshaw

unread,
May 25, 2011, 4:08:50 PM5/25/11
to cython...@googlegroups.com
On Wed, May 25, 2011 at 12:45 PM, pytrade <vinj...@gmail.com> wrote:
> Is there something equivalent to np.nan in cython that I can assign to
> cython variables?

You could always use np.nan itself, or float("nan"). If you need it a
lot, save it to a local or global.

- Robert

pytrade

unread,
May 25, 2011, 4:23:06 PM5/25/11
to cython-users
I mean how do I assign NaN's to a cdef'ed variables. Are you
suggesting the following:

cdef float NAN
NAN = float("NaN")



On May 25, 4:08 pm, Robert Bradshaw <rober...@math.washington.edu>
wrote:

Robert Bradshaw

unread,
May 25, 2011, 4:29:19 PM5/25/11
to cython...@googlegroups.com
On Wed, May 25, 2011 at 1:23 PM, pytrade <vinj...@gmail.com> wrote:
> I mean how do I assign NaN's to a cdef'ed variables. Are you
> suggesting the following:
>
> cdef float NAN
> NAN = float("NaN")

Yes, though you can put it all on one line if you want. Note that in
C, float != double. As far as I know, there's no good cross-platform
way to get NaNs in C.

- Robert

Davoud Taghawi-Nejad

unread,
Dec 17, 2015, 1:43:49 PM12/17/15
to cython-users
wouldn't

cdef double NAN
NAN = float("NaN")

as a C double is a python float?

Chris Barker - NOAA Federal

unread,
Dec 17, 2015, 8:57:05 PM12/17/15
to cython...@googlegroups.com

 As far as I know, there's no good cross-platform

way to get NaNs in C.

Couldn't you specify the bit pattern? Unless you care about non-ieee754 platforms.

Or do an operation that results in a NaN -- I'd have to experiment to find one ....

CHB



- Robert

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages