Re: where and NAN numbers [message #42152] |
Wed, 12 January 2005 15:16 |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
maarten wrote:
> What version are you using, because in 6.1.1. the results are:
> IDL> u = [!values.f_nan, 1, 2, 3]
> IDL> print, where(u eq 3)
> 3
> IDL> print, where(u ge 3)
> 3
The result of a comparison operation between a NaN and an "ordinary"
number will depend on the platform. (At least I vaguely recall some
dicussion of this somewhere, perhaps this group or perhaps another one.)
It is not wise to rely on getting logically consistent results. For
example on IDL 6.1.1 (win32), NaN is not equal to 0 (according to the EQ
and NE operators) but it is neither larger or smaller than 0 (according
to the LT and GT operators). So, as another poster has suggested, it is
good practice to use the FINITE function to establish whether a floating
point number is finite; if it's not the results from comparison
operations will likely be misleading.
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: where and NAN numbers [message #42158 is a reply to message #42152] |
Wed, 12 January 2005 06:24  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Use finite function to pre-filter for nans.
<euskalmet07@ej-gv.es> wrote in message
news:36519195.0501120402.5de60fc0@posting.google.com...
> Hi dear IDL user,
>
> Maybe my question is too obvious, but I can�t guess the response.
>
> Having the vector:
>
> IDL> u = [!values.f_nan, 1, 2, 3]
>
> why is different the resulting vector in these following two WHERE
functions?
>
> IDL> print, where(u eq 3)
> 0 3
> % Program caused arithmetic error: Floating illegal operand
>
> IDL> print, where(u ge 3)
> 3
> % Program caused arithmetic error: Floating illegal operand
>
>
> Any response would be appreciated.
|
|
|
Re: where and NAN numbers [message #42159 is a reply to message #42158] |
Wed, 12 January 2005 04:08  |
maarten
Messages: 30 Registered: April 2002
|
Member |
|
|
What version are you using, because in 6.1.1. the results are:
IDL> u = [!values.f_nan, 1, 2, 3]
IDL> print, where(u eq 3)
3
IDL> print, where(u ge 3)
3
euskalmet07@ej-gv.es wrote:
> Hi dear IDL user,
>
> Maybe my question is too obvious, but I can�t guess the response.
>
> Having the vector:
>
> IDL> u = [!values.f_nan, 1, 2, 3]
>
> why is different the resulting vector in these following two WHERE functions?
>
> IDL> print, where(u eq 3)
> 0 3
> % Program caused arithmetic error: Floating illegal operand
>
> IDL> print, where(u ge 3)
> 3
> % Program caused arithmetic error: Floating illegal operand
>
>
> Any response would be appreciated.
|
|
|