NaN problem in integer arrays [message #86206] |
Thu, 17 October 2013 08:44  |
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 #86214 is a reply to message #86206] |
Thu, 17 October 2013 13:51  |
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
|
|
|