&
has &&
. |
has ||
. Why doesn\'t ^
have ^^
?
I understand that it wouldn\'t
Technically, one already exists:
a != b
since this will evaluate to true if the truth value of the operands differ.
Volte's comment:
(!a) != (!b)
is correct because my answer above does not work for int
types. I will delete mine if he adds his answer.
Maybe I'm forgetting something from C++, but the more I think about this, the more I wonder why you would ever write if (1 ^ 2)
in the first place. The purpose for ^
is to exclusive-or two numbers together (which evaluates to another number), not convert them to boolean values and compare their truth values.
This seems like it would be an odd assumption for a language designer to make.