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

Home » Public Forums » archive » HELP with IF statement
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
HELP with IF statement [message #91268] Thu, 25 June 2015 04:10 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
I have a problem with IF statement

I wanted to check whether my array A has any zero element and if so then simply return a zero array (with two zeroes). I typed the following but am not sure if it's correct.

A FLOAT = Array[58]

FOR i=0L, 57 DO BEGIN
IF A[i] EQ 0 THEN RETURN, [0,0]
ENDFOR
Re: HELP with IF statement [message #91271 is a reply to message #91268] Thu, 25 June 2015 05:22 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
g.nacarts@gmail.com writes:

> I have a problem with IF statement
>
> I wanted to check whether my array A has any zero element and if so then simply return a zero array (with two zeroes). I typed the following but am not sure if it's correct.
>
> A FLOAT = Array[58]
>
> FOR i=0L, 57 DO BEGIN
> IF A[i] EQ 0 THEN RETURN, [0,0]
> ENDFOR

There are a whole host of articles on my web page explaining why it will
be impossible to find a zero value in an array of floats. I'll just give
you the bottom line: use Floats_Equal from the Coyote Library to do this
kind of comparison:

IF Floats_Equal(a[i],0) THEN RETURN, [0,0]

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: HELP with IF statement [message #91272 is a reply to message #91271] Thu, 25 June 2015 05:48 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
So for arrays with floats need to use the floats_equal to check for zeroes?
Re: HELP with IF statement [message #91273 is a reply to message #91272] Thu, 25 June 2015 05:51 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
g.nacarts@gmail.com writes:

> So for arrays with floats need to use the floats_equal to check for zeroes?

Only if you want to find them.

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: HELP with IF statement [message #91274 is a reply to message #91273] Thu, 25 June 2015 05:56 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Good to know. Small details that make such a big difference. Thanks a lot.
Re: HELP with IF statement [message #91275 is a reply to message #91274] Thu, 25 June 2015 05:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
g.nacarts@gmail.com writes:

> Good to know. Small details that make such a big difference.

Yes. It's called computer programming. ;-)

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: HELP with IF statement [message #91277 is a reply to message #91271] Thu, 25 June 2015 08:20 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
On 06/25/15 08:22, David Fanning wrote:
> g.nacarts@gmail.com writes:
>
>> I have a problem with IF statement
>>
>> I wanted to check whether my array A has any zero element and if
>> so then simply return a zero array (with two zeroes). I typed the
>> following but am not sure if it's correct.
>>
>> A FLOAT = Array[58]
>>
>> FOR i=0L, 57 DO BEGIN
>> IF A[i] EQ 0 THEN RETURN, [0,0]
>> ENDFOR
>
> There are a whole host of articles on my web page explaining why it will
> be impossible to find a zero value in an array of floats. I'll just give
> you the bottom line: use Floats_Equal from the Coyote Library to do this
> kind of comparison:
>
> IF Floats_Equal(a[i],0) THEN RETURN, [0,0]

Yes. My first reply when I am asked this sort of question is: "What do
you think is zero?"

Or, if I'm feeling particularly obtuse: "What IS zero?" (with a suitable
gesticulatory flourish, of course :o)

Funny, now that I think about it, people haven't come to ask me
questions for a while now. Huh.

cheers,

paulv
Re: HELP with IF statement [message #91278 is a reply to message #91277] Thu, 25 June 2015 08:34 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Something that I don't understand. I tried to avoid the for loop created before and I replace this part of the code:

for i=0,n-1 do begin
IF floats_equal(A[i],0) THEN RETURN,[0,0]
endfor

By this:

IF norm(A) EQ 0 THEN RETURN, [0,0]

I thought I will end up with the same result but I didn't. Does anyone know why this happen?
Re: HELP with IF statement [message #91279 is a reply to message #91277] Thu, 25 June 2015 08:34 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> Funny, now that I think about it, people haven't come to ask me
> questions for a while now. Huh.

Who is going to read a whole damn article on how computers represent
numbers!?

http://www.idlcoyote.com/math_tips/sky_is_falling.html

Who the hell even remembers what a "mantissa" is?

Stick to the bottom line. It is SO much easier! ;-)

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: HELP with IF statement [message #91280 is a reply to message #91278] Thu, 25 June 2015 08:42 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
g.nacarts@gmail.com writes:

> Something that I don't understand. I tried to avoid the for loop created before and I replace this part of the code:
>
> for i=0,n-1 do begin
> IF floats_equal(A[i],0) THEN RETURN,[0,0]
> endfor
>
> By this:
>
> IF norm(A) EQ 0 THEN RETURN, [0,0]
>
> I thought I will end up with the same result but I didn't. Does anyone know why this happen?

Most of the people who follow this newsgroup knows why it happens:

http://www.idlcoyote.com/math_tips/sky_is_falling.html
http://www.idlcoyote.com/math_tips/storenum.html
http://www.idlcoyote.com/math_tips/razoredge.html
http://www.idlcoyote.com/code_tips/lhsvsrhs.html
http://www.idlcoyote.com/math_tips/double.html

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: HELP with IF statement [message #91281 is a reply to message #91280] Thu, 25 June 2015 08:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Most of the people who follow this newsgroup knows why it happens:
>
> http://www.idlcoyote.com/math_tips/sky_is_falling.html
> http://www.idlcoyote.com/math_tips/storenum.html
> http://www.idlcoyote.com/math_tips/razoredge.html
> http://www.idlcoyote.com/code_tips/lhsvsrhs.html
> http://www.idlcoyote.com/math_tips/double.html
>

And, maybe the most relevant for your proposes:

http://www.idlcoyote.com/code_tips/comparearray.html

Although, it won't make any sense to you, probably, without the
background of the previous articles.

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: HELP with IF statement [message #91282 is a reply to message #91281] Thu, 25 June 2015 08:53 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> And, maybe the most relevant for your proposes:

Sigh... Fingers have not only retired, but apparently have run off with
a loose woman, too. :-(

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: HELP with IF statement [message #91289 is a reply to message #91279] Thu, 25 June 2015 09:41 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 06/25/15 11:34, David Fanning wrote:
>
> Who the hell even remembers what a "mantissa" is?
>
It's a herbivorous marine mammal, no?

In Oz, we called them dugongs. Or significands.

ehem.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: BYTSCL function
Next Topic: IDL Site Issues

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

Current Time: Wed Oct 08 09:10:40 PDT 2025

Total time taken to generate the page: 0.00510 seconds