comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » NaN problem in integer arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
NaN problem in integer arrays [message #86206] Thu, 17 October 2013 08:44 Go to next message
galaxytraveler42 is currently offline  galaxytraveler42
Messages: 5
Registered: October 2013
Junior Member
I use NaN's a lot in my arrays in place of missing or bad data points, but I have problems with it everytime my arrays are integer.

An example of a test program:
x=[0,1,2,0]
s=where(x EQ 0,count)
if count gt 0 then x(s)=!Values.F_NAN
help, X

> X INT = Array[4]

print, X
> % Stop encountered: test.pro
> % Program caused arithmetic error: Floating illegal operand



And if I change it to a long array:
x=long(x)
then I get:
> X LONG = Array[4]
> -2147483648 1 2 -2147483648
> % Program caused arithmetic error: Floating illegal operand



But if I do this with a floating array.
x=[0.,1.,2.,0.]
Then it works just fine
> X FLOAT = Array[4]
> NaN 1.00000 2.00000 NaN



I can see that other people have had troubles with this and explained it as a windows compiler errors, but I have a mac computer.
http://www.idlcoyote.com/math_tips/nans.html


Do anyone know if there is a solution for this?
Re: NaN problem in integer arrays [message #86207 is a reply to message #86206] Thu, 17 October 2013 08:50 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Galaxytraveler writes:

> I use NaN's a lot in my arrays in place of missing or bad data points,
> but I have problems with it everytime my arrays are integer.

Yes, there are only two types of NaNs in IDL. !Values.F_NaN
is the floating point NaN (that is what the F means) and !Values.D_NaN
is a double precision floating point NaN (that is what the D means).
There is no integer or long or byte value that can be used as a NaN.

Bottom line, if you are going to use NaNs, you will need to use them in
floating point or double precision arrays. No way around it. :-)

> I can see that other people have had troubles with this and explained
it as a windows compiler errors, but I have a mac computer.
> http://www.idlcoyote.com/math_tips/nans.html

That's funny! :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: NaN problem in integer arrays [message #86214 is a reply to message #86206] Thu, 17 October 2013 13:51 Go to previous message
Kenneth Bowman is currently offline  Kenneth Bowman
Messages: 86
Registered: November 2006
Member
On 2013-10-17 15:44:46 +0000, Galaxytraveler said:

> I use NaN's a lot in my arrays in place of missing or bad data points,
> but I have problems with it everytime my arrays are integer.

NaNs are identified by a special bit pattern in the IEEE floating point
standard (http://en.wikipedia.org/wiki/IEEE_floating_point). There is
no such thing as NaN for integer data types. If you need to implement
a similar concept for integers, you have to choose a specific integer
value to represent, for example, missing data, and then you have to
assume all responsibility for checking for that value.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Interactively crop an image with NG
Next Topic: Test if a linux command is available with Spawn

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:07:42 PDT 2025

Total time taken to generate the page: 0.00409 seconds