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

Home » Public Forums » archive » Logical operators
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: Logical operators [message #93871 is a reply to message #93867] Sun, 13 November 2016 19:05 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Sunday, November 13, 2016 at 8:30:50 AM UTC-6, Glan wrote:
> Hi
> I am trying to do
> if( ( (a gt 50) and ( b lt 50) ) or ((a lt 50) and ( b gt 50)) then begin
> c=! NANQ
>
> ...but the multiplie logical operator not working.
> Can you help
> GlanPlon

First, and just to clarify for others, "and" and "or" or not, strictly speaking, logical operators (&&, ||). They are bitwise. Here, they essentially work the same as the logical ops, since the result of the relational operators (lt,gt, etc.) lead to ones or zeros. But, the logical operators have the added benefit of "short-circuiting," so that 1 || _some_expression is true, without evaluating _some_expression. Similarly, 0 && _some_expression is false, without evaluating _some_expression.

With that said, a simple test shows the code does not always evaluate to true:

IDL> a = 0 & b=0
IDL> ( (a gt 50) and ( b lt 50) ) or ((a lt 50) and ( b gt 50))
0
IDL> a = 0 & b=51
IDL> ( (a gt 50) and ( b lt 50) ) or ((a lt 50) and ( b gt 50))
1
IDL> a = 51 & b=0
IDL> ( (a gt 50) and ( b lt 50) ) or ((a lt 50) and ( b gt 50))
1
IDL> a = 51 & b=51
IDL> ( (a gt 50) and ( b lt 50) ) or ((a lt 50) and ( b gt 50))
0

(Your code seems to be missing a parentheses, BTW.)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL Bridge Failing When >52 Bridges are Built (IDL6.4)
Next Topic: Conversion of MS 64bit timestamps to JD

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

Current Time: Wed Oct 08 15:48:23 PDT 2025

Total time taken to generate the page: 0.00441 seconds