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

Home » Public Forums » archive » Re: Mulitple conditionals
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Mulitple conditionals [message #64974] Sat, 07 February 2009 04:48
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Bernhard Reinhardt writes:

> I guess I can not shock you IDL old stagers with this but for an IDL
> newbee like me this seems quite strange:
>
> IDL> if 1 eq (1 or 2) then print, "true" else print, "false"
> false
> IDL> if "a" eq ("a" or "b") then print, "true" else print, "false"
> true
>
> Maybe thats the IDL-way of punishing people to addle to type the long
> version:
>
> IDL> if ("a" eq "a" or "a" eq "b") then print, "true" else print,"false"
> true
> IDL> if (1 eq 1 or 1 eq 2) then print, "true" else print, "false"
> true
>
> Can anyone explain the logic behind this behavoir to me?

I've given up "explaining" a great deal of IDL's behavior,
but this one is fairly simple. IDL does "bitwise" comparisons
between values. So...

IDL> print, binary(1 or 2)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
IDL> print, binary(1)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Clearly, these two bit patterns are different, so the answer
is "false":

IDL> if 1 eq (1 or 2) then print, "true" else print, "false"
false

I'll leave it to someone else to explain why strings
are handled differently. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Previous Topic: Mulitple conditionals
Next Topic: Aspect Ratio vs X/Y Range

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

Current Time: Fri Oct 10 00:12:06 PDT 2025

Total time taken to generate the page: 0.12758 seconds