kurt@hi.UUCP (Kurt Zeilenga) (07/16/87)
Often one might have two "boolean" variables, say a and b, and you would like to know if A and B are both of the same truth value (zero or non-zero). I have always done this like: (!A == !B) to avoid the case that A and B are both non-zero but no the same integer value. What do all think about this? Any other clean ways of writing this? Is it readable? (I think so, but then ...) -- Kurt Zeilenga (zeilenga@hc.dspo.gov) I want my talk.flame! "Remember, Mommie, I'm off to get a commie..."
ubi@sri-unix.ARPA (Ron Ueberschaer) (07/17/87)
In article <11128@hi.UUCP> kurt@hc.dspo.gov (Kurt Zeilenga) writes: >... to know if A and B are both of the same truth value (zero or non-zero). > > (!A == !B) > >to avoid the case that A and B are both non-zero but no the same integer >value. A more outrageous way to do this, for want of a logical XOR operator, is ((A && B) || !(A || B)) which would reduce to !(A ^^ B) where the ^^ logical XOR binary operator is the analog of the ^ bitwise XOR, if only such an operator existed. ;-) --Ron Ueberschaer SRI International Menlo Park, CA ...!{hplabs,rutgers}!sri-unix!ubi ubi@sri-unix.uucp
flaps@utcsri.UUCP (07/22/87)
In article <11128@hi.UUCP> kurt@hc.dspo.gov (Kurt Zeilenga) writes: >Often one might have two "boolean" variables, say a and b, and you would >like to know if A and B are both of the same truth value (zero or non-zero). >I have always done this like: > > (!A == !B) > >[which is not the same as (A == B)] Just thinking about how to express the idea "a and b are both either zero or non-zero", I think of the test as being whether or not their equalness to zero is equal. This yields "((a == 0) == (b == 0))". The problem, in my opinion, with your solution is that it looks like the '!'s can be removed (which of course would change the semantics). > "Remember, Mommie, I'm off to get a commie..." ^^^^^^^^ Isn't that "So, so long"?? -- // Alan J Rosenthal // \\ // flaps@csri.toronto.edu, {seismo!utai or utzoo}!utcsri!flaps, \// flaps@toronto on csnet, flaps at utorgpu on bitnet. "To be whole is to be part; true voyage is return."