Please explain... [message #5253] |
Sun, 26 November 1995 00:00  |
mallozzi
Messages: 60 Registered: August 1994
|
Member |
|
|
Can someone explain this to me?
IDL> .r
- x = 0 & y = 0
- case 1 of
- x and y: print, '1'
- NOT x and y: print, '2'
- x and NOT y: print, '3'
- NOT x and NOT y: print, '4'
- endcase
- end
% Compiled module: $MAIN$.
% Case statement found no matches.
% Execution halted at $MAIN$ </dev/tty( 1)> .
IDL> if NOT x and NOT y then print, '4'
4
IDL>
The other three cases work as I expected in the case statement. Thanks.
-Bob
|
|
|
Re: Please explain... [message #5397 is a reply to message #5253] |
Mon, 27 November 1995 00:00  |
Ding Wu - see John Vo
Messages: 1 Registered: November 1995
|
Junior Member |
|
|
Please note:
The NOT operator is the Boolean inverse and is
a unary operator because it has only one operand.
In other words, "NOT true" is equal to "false"
and "NOT false" is equal to "true." NOT complements
each bit for integer operands. For floating-point
operands, the result is 1.0 if the operand is zero;
otherwise, the result is zero.
So
1: if change x=0 & y=0 to x=.0 & y=.0 then all will work.
For x=0 & y=0 , ( not x and not y) is (not 0000 and not 0000) ie. -1,
For x=.0 & y=.0, ( not x and not y) is 1.0
2: in the case statement, each of the conditions must be
matched to 1.
so, case statement ( not x and not y = -1 ) found no matches.
3: but in if statement, the conditions only need to be
not zero.
so, if statement ( not x and not y = -1 ) is true.
Ding Wu, need a job, desperately!
mallozzi@ssl.msfc.nasa.gov wrote: : Can someone explain this
to me?
: IDL> .r
: - x = 0 & y = 0
: - case 1 of
: - x and y: print, '1'
: - NOT x and y: print, '2'
: - x and NOT y: print, '3'
: - NOT x and NOT y: print, '4'
: - endcase
: - end
: % Compiled module: $MAIN$.
: % Case statement found no matches.
: % Execution halted at $MAIN$ </dev/tty( 1)> .
: IDL> if NOT x and NOT y then print, '4'
: 4
: IDL>
: The other three cases work as I expected in the case statement. Thanks.
: -Bob
|
|
|
Re: Please explain... [message #5400 is a reply to message #5253] |
Mon, 27 November 1995 00:00  |
jlaw
Messages: 11 Registered: November 1995
|
Junior Member |
|
|
In article 2gt@hammer.msfc.nasa.gov, mallozzi@ssl.msfc.nasa.gov writes:
> Can someone explain this to me?
>
> IDL> .r
> - x = 0 & y = 0
> - case 1 of
> - x and y: print, '1'
> - NOT x and y: print, '2'
> - x and NOT y: print, '3'
> - NOT x and NOT y: print, '4'
> - endcase
> - end
> % Compiled module: $MAIN$.
> % Case statement found no matches.
> % Execution halted at $MAIN$ </dev/tty( 1)> .
Well, I am getting
: x = 0
: print, NOT x
-1
: y = 0
: print, NOT x AND NOT y
-1
So your CASE does not evaluate to 1 here. < time out to look at online help >
The 'problem' is the implementation of Boolean types in IDL : It is done
bitwise, and even integers are true.. In fact there are no special
"TRUE" and "FALSE" values. Perhaps its best here to use an ELSE: label.
Are you sure all your booleans will always be 0 or 1?
f.
|
|
|