Exponential operator
Michel Fortin
michel.fortin at michelf.com
Fri Aug 7 10:31:25 PDT 2009
On 2009-08-07 13:01:55 -0400, Daniel Keep <daniel.keep.lists at gmail.com> said:
> Michel Fortin wrote:
>> I always wondered why there isn't an XOR logical operator.
>>
>> binary logical
>> (a & b) => (a && b)
>> (a | b) => (a || b)
>> (a ^ b) => (a ^^ b)
>
> a | b | a ^^ b | a != b
> ---+---+--------+--------
> F | F | F | F
> F | T | T | T
> T | F | T | T
> T | T | F | F
>
> That's why.
For this table to work, a and b need to be boolean values. With && and
||, you have an implicit convertion to boolean, not with !=. So if a ==
1 and b == 2, an hypothetical ^^ would yeild false since both are
converted to true, while != would yield false.
But I have another explanation now. With && and ||, there's always a
chance that the expression on the left won't be evaluated. If that
wasn't the case, the only difference in && vs. &, and || vs. | would be
the automatic convertion to a boolean value. With ^^, you always have
to evaluate both sides, so it's less useful.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list