Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mtune!codas!killer!jfh From: jfh@killer.UUCP (The Beach Bum) Newsgroups: comp.lang.c Subject: Re: "logical" xor Message-ID: <2796@killer.UUCP> Date: 11 Jan 88 19:43:22 GMT References: <2946@zeus.TEK.COM> <195@fxgrp.UUCP> Organization: Big "D" Home for Wayward Hackers Lines: 51 Summary: Here it is ... ... the LOGICAL XOR macro. In article <195@fxgrp.UUCP>, ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) writes: > In article <2946@zeus.TEK.COM> dant@tekla.UUCP (Dan Tilque) writes: > > ... > >Tell me, what is the ^^ supposed to add that is not already done by ^ ? > >The answer is nothing. The "bitwise" xor does exactly what you would want > >a "logical" xor to do. In fact, the terms "bitwise" and "logical" are > >misnomers. They should be "unoptimized" and "optimized". And there's no > >way to optimize an exclusive-or operation. Only half true. Actually, not true at all. | and & operate on bits. Calling boolean operators an "optimized" version of a bit operator is a lot like calling a type definition an "optimized" procedure call. > >The only reason to add ^^ is esthetic. ... > > ... True here. The correct result can be had with little effort. I would say leaving out ^^ is at most being incomplete. > I'm sorry, but I disagree. Try running this program: > [ eaten by the line eater ] > Lloyd Zusman Here is the macro for you impatient people: #define XOR(a,b) (((a)==0)!=((b)==0)) Unless I am missing something very subtle in the casting that will go on if the macro is call with floating point expressions, this thing should work like a dream. The != operator has the same truth table as ^^ would, if handed boolean values (ie, 0 and 1). Proof: a b ^^ != 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 0 Testing a and b for equality against 0 should produce two boolean values, or, given a good compiler, a couple of test and branch statements. My only question is about the casting. - John. -- John F. Haugh II SNAIL: HECI Exploration Co. Inc. UUCP: ...!ihnp4!killer!jfh 11910 Greenville Ave, Suite 600 "Don't Have an Oil Well? ... Dallas, TX. 75243 ... Then Buy One!" (214) 231-0993 Ext 260