Re: Comparison operators and floating-point errors [message #70552] |
Mon, 19 April 2010 15:23 |
R.G.Stockwell
Messages: 163 Registered: October 2004
|
Senior Member |
|
|
"pp" <pp.penteado@gmail.com> wrote in message
news:54eb565d-1480-43e8-b202-1e938bebb5e6@n20g2000prh.google groups.com...
On Apr 19, 6:24 pm, Ed Hyer <ejh...@gmail.com> wrote:
> On Apr 19, 1:36 pm, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>
>> Right. Try setting NAN=0.0/0.0 or NAN=!values.f_nan.
>
> OK, so for the purpose of masking an array with a binary mask, I had
> been using
>
> MASKED_DATA = DATA / FLOAT(MASK)
>
> and should instead use
>
> MASKED_DATA = (DATA * MASK) / FLOAT(MASK)
>
> in order to ensure that the masked values are all NaN.
> Or
> w=where(~mask,nw)
> if (nw gt 0) then masked_data[w]=!values.d_nan
Definitely good advice. You want people to understand your
code when they read it, and if you want nans, then explicitly
put in nans. There is no way a person can know what is
in your mask array, and know that you are NANing out values.
cheers,
bob
|
|
|
Re: Comparison operators and floating-point errors [message #70553 is a reply to message #70552] |
Mon, 19 April 2010 14:45  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Apr 19, 6:24 pm, Ed Hyer <ejh...@gmail.com> wrote:
> On Apr 19, 1:36 pm, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>
>> Right. Try setting NAN=0.0/0.0 or NAN=!values.f_nan.
>
> OK, so for the purpose of masking an array with a binary mask, I had
> been using
>
> MASKED_DATA = DATA / FLOAT(MASK)
>
> and should instead use
>
> MASKED_DATA = (DATA * MASK) / FLOAT(MASK)
>
> in order to ensure that the masked values are all NaN.
Or
w=where(~mask,nw)
if (nw gt 0) then masked_data[w]=!values.d_nan
|
|
|
Re: Comparison operators and floating-point errors [message #70554 is a reply to message #70553] |
Mon, 19 April 2010 14:24  |
MarioIncandenza
Messages: 231 Registered: February 2005
|
Senior Member |
|
|
On Apr 19, 1:36 pm, Craig Markwardt <craig.markwa...@gmail.com> wrote:
> Right. Try setting NAN=0.0/0.0 or NAN=!values.f_nan.
OK, so for the purpose of masking an array with a binary mask, I had
been using
MASKED_DATA = DATA / FLOAT(MASK)
and should instead use
MASKED_DATA = (DATA * MASK) / FLOAT(MASK)
in order to ensure that the masked values are all NaN.
|
|
|
Re: Comparison operators and floating-point errors [message #70556 is a reply to message #70554] |
Mon, 19 April 2010 13:36  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Apr 19, 3:18 pm, pp <pp.pente...@gmail.com> wrote:
> On Apr 19, 3:31 pm, Ed Hyer <ejh...@gmail.com> wrote:
>
>
>
>> IDL> nan=1/0.0
>> % Program caused arithmetic error: Floating divide by 0
>> IDL> print, -0.1 > nan
>> Inf
>> IDL> print, -0.1 < nan
>> -0.100000
>> IDL> print, 1 gt nan
>> 0
>> IDL> print, 1 lt nan
>> 1
>
>> I thought the rule was "Any calculation involving a NaN will produce
>> NaN."
>> Has it been this way since the dawn of time? I'm sure it has.
>
>> I have found a few uses for NaN in IDL over the years, and now I have
>> to come up with new ones.
>
>> For instance (the one that led me to track this down), I use NaN to
>> exclude areas from contour plots. There are other ways, but none quite
>> as simple and flexible.
>
> This all looks right to me, for one thing because there are no NaNs
> around. The variable you called nan is infinity, no NaN.
Right. Try setting NAN=0.0/0.0 or NAN=!values.f_nan.
Craig
|
|
|
Re: Comparison operators and floating-point errors [message #70557 is a reply to message #70556] |
Mon, 19 April 2010 12:18  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Apr 19, 3:31 pm, Ed Hyer <ejh...@gmail.com> wrote:
> IDL> nan=1/0.0
> % Program caused arithmetic error: Floating divide by 0
> IDL> print, -0.1 > nan
> Inf
> IDL> print, -0.1 < nan
> -0.100000
> IDL> print, 1 gt nan
> 0
> IDL> print, 1 lt nan
> 1
>
> I thought the rule was "Any calculation involving a NaN will produce
> NaN."
> Has it been this way since the dawn of time? I'm sure it has.
>
> I have found a few uses for NaN in IDL over the years, and now I have
> to come up with new ones.
>
> For instance (the one that led me to track this down), I use NaN to
> exclude areas from contour plots. There are other ways, but none quite
> as simple and flexible.
This all looks right to me, for one thing because there are no NaNs
around. The variable you called nan is infinity, no NaN.
|
|
|