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

Home » Public Forums » archive » Re: Setting values to NaN
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
Re: Setting values to NaN [message #39915] Fri, 25 June 2004 13:17 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
b_gom@hotmail.com (Brad Gom) writes:
> To expand on this a little, does anyone know how to set the value of a
> variable to NaN from within a DLM?

You would do it the way you normally do it in C. This typically
depends on your math/C library.

For glibc+math.h, I think the value is NAN.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Setting values to NaN [message #39922 is a reply to message #39915] Fri, 25 June 2004 11:38 Go to previous messageGo to next message
b_gom is currently offline  b_gom
Messages: 105
Registered: April 2003
Senior Member
To expand on this a little, does anyone know how to set the value of a
variable to NaN from within a DLM?

Thanks

Brad
Re: Setting values to NaN [message #39925 is a reply to message #39922] Fri, 25 June 2004 09:34 Go to previous messageGo to next message
Matt Feinstein is currently offline  Matt Feinstein
Messages: 33
Registered: July 2002
Member
On Fri, 25 Jun 2004 11:50:34 -0400, Paul Van Delst
<paul.vandelst@noaa.gov> wrote:

> How would you define a bit pattern for an invalid integer that's not a valid integer?, as
> opposed to some user-set value (like -99 or or -32767 or -2147483647L etc.) ?

I guess the 'right' answer is to use a data structure (or, to be
buzzword-compliant, an object) with an internal valid/invalid flag.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
Re: Setting values to NaN [message #39926 is a reply to message #39925] Fri, 25 June 2004 09:30 Go to previous messageGo to next message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
>> OK I spotted it. F_NAN and D_NAN apply to floats.
>>
>> So is there an alternative I can use with integers?
>
>
> How would you define a bit pattern for an invalid integer that's not a
> valid integer?, as opposed to some user-set value (like -99 or or -32767
> or -2147483647L etc.) ?
>
> You need to define some user-set value (like -99 or or -32767 or
> -2147483647L etc.) based on what you knwo about your data.


Just to expand on Paul's answer a little, computers work with floating
point numbers very differently than they work with integers. For
floating point numbers certain bit patterns are reserved for NaN,
positive infinity and negative infinity. If you want to see the gory
details, look up the IEEE 754 spec for floating point numbers.

The integer specification does not set aside special bit patterns for
NaN or the infinities. Therefore, if you want create a NaN for
integers, you have to create an arbitrary definition based on your data.
Typically, a good rule of thumb is to use the smallest or largest
possible integers as these will most likely be outside your data set.
The problem is that since your definition will be arbitrary you need to
make sure that if others use your data you indicate that there is a
number in the data which needs to be interpreted as NaN.

For example, let's say I have a data set of all positive numbers and I
use -1 to indicated NaN. If someone else comes along and doesn't know
that -1 represents NaN, they will do their processing using the -1
values and potentially get results that are very far off. I have run
into this very thing before. Someone used -999 to represent that no
data was present, but didn't document it. It took me the major part of
an afternoon to figure out why my code was failing so badly.

-Mike
Re: Setting values to NaN [message #39927 is a reply to message #39926] Fri, 25 June 2004 09:14 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
matt_westmore@yahoo.co.uk (Matt) writes:
> OK I spotted it. F_NAN and D_NAN apply to floats.
>
> So is there an alternative I can use with integers?

There is no automatic alternative. The "manual" alternative is to
declare a certain integer as the "bad data" integer -- any integer you
like that won't interfere with your calculations (-9999 or whatever).
And then you test for that integer at every step, and accomodate for
the bad data.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Setting values to NaN [message #39928 is a reply to message #39927] Fri, 25 June 2004 08:50 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Matt wrote:
> OK I spotted it. F_NAN and D_NAN apply to floats.
>
> So is there an alternative I can use with integers?

How would you define a bit pattern for an invalid integer that's not a valid integer?, as
opposed to some user-set value (like -99 or or -32767 or -2147483647L etc.) ?

You need to define some user-set value (like -99 or or -32767 or -2147483647L etc.) based
on what you knwo about your data. Something like:

IDL> MY_INVALID_INTEGER = -32767
IDL> a = indgen(10)
IDL> lt5 = where(a lt 5)
IDL> a[lt5] = MY_INVALID_INTEGER
IDL> print, a
-32767 -32767 -32767 -32767 -32767 5 6 7 8 9

Be careful about mixing values/data types though:

IDL> MY_INVALID_INTEGER = -2147483647L
IDL> a = indgen(10)
IDL> lt5 = where(a lt 5)
IDL> a[lt5] = MY_INVALID_INTEGER
IDL> print, a
1 1 1 1 1 5 6 7 8 9

paulv


>
>
> matt_westmore@yahoo.co.uk (Matt) wrote in message news:<c66373b9.0406250228.f6cbaf4@posting.google.com>...
>
>> Hi,
>> I'd realy appreciate someone pointing out why I'm an idiot.
>>
>> I'm trying to set some values of an image to NaN so that they are not
>> included in further calculations but I can't seem to do it!!!
>>
>> eg:
>> a = indgen(10)
>> lt5 = where(a LT 5)
>> a(lt5) = !VALUES.F_NAN
>> %Program caused arithmetic error: Floating illegal operand
>> print, a
>> 0 0 0 0 0 5 6 7 8 9
>>
>> Cheers
>> Matt
Re: Setting values to NaN [message #39931 is a reply to message #39928] Fri, 25 June 2004 08:27 Go to previous messageGo to next message
matt_westmore is currently offline  matt_westmore
Messages: 4
Registered: June 2004
Junior Member
OK I spotted it. F_NAN and D_NAN apply to floats.

So is there an alternative I can use with integers?


matt_westmore@yahoo.co.uk (Matt) wrote in message news:<c66373b9.0406250228.f6cbaf4@posting.google.com>...
> Hi,
> I'd realy appreciate someone pointing out why I'm an idiot.
>
> I'm trying to set some values of an image to NaN so that they are not
> included in further calculations but I can't seem to do it!!!
>
> eg:
> a = indgen(10)
> lt5 = where(a LT 5)
> a(lt5) = !VALUES.F_NAN
> %Program caused arithmetic error: Floating illegal operand
> print, a
> 0 0 0 0 0 5 6 7 8 9
>
> Cheers
> Matt
Re: Setting values to NaN [message #39933 is a reply to message #39931] Fri, 25 June 2004 06:43 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Matt writes:

> I'd realy appreciate someone pointing out why I'm an idiot.

Wrong group. Take this over to alt.masochist.fetish. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Setting values to NaN [message #39934 is a reply to message #39933] Fri, 25 June 2004 04:41 Go to previous messageGo to next message
Klaus Scipal is currently offline  Klaus Scipal
Messages: 45
Registered: November 1997
Member
Hi Matt

!VALUES.F_NAN is a float but your a array is integer. Convert your a array
to float (float(a)) before setting the NaNs and it will work

Klaus


"Matt" <matt_westmore@yahoo.co.uk> wrote in message
news:c66373b9.0406250228.f6cbaf4@posting.google.com...
> Hi,
> I'd realy appreciate someone pointing out why I'm an idiot.
>
> I'm trying to set some values of an image to NaN so that they are not
> included in further calculations but I can't seem to do it!!!
>
> eg:
> a = indgen(10)
> lt5 = where(a LT 5)
> a(lt5) = !VALUES.F_NAN
> %Program caused arithmetic error: Floating illegal operand
> print, a
> 0 0 0 0 0 5 6 7 8 9
>
> Cheers
> Matt
Re: Setting values to NaN [message #39965 is a reply to message #39927] Wed, 30 June 2004 04:37 Go to previous message
matt_westmore is currently offline  matt_westmore
Messages: 4
Registered: June 2004
Junior Member
Thanks guys for all the advice; except of course for the re-direction
to the fetish site!

Matt
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: inverse function of binary.pro
Next Topic: Local solar time

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

Current Time: Wed Oct 08 20:03:49 PDT 2025

Total time taken to generate the page: 0.01805 seconds