Please rid me of this goto

Patrick Schluter via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 24 23:19:12 PDT 2016


On Friday, 24 June 2016 at 20:34:38 UTC, deadalnix wrote:
> On Friday, 24 June 2016 at 10:33:43 UTC, Patrick Schluter wrote:
>> On Friday, 24 June 2016 at 10:11:11 UTC, deadalnix wrote:
>>> On Friday, 24 June 2016 at 08:40:26 UTC, Patrick Schluter 
>>> wrote:
>>>> On Thursday, 23 June 2016 at 20:01:26 UTC, deadalnix wrote:
>>>>> On Thursday, 23 June 2016 at 19:24:54 UTC, via 
>>>>> Digitalmars-d wrote:
>>>>>> On Thu, Jun 23, 2016 at 07:11:26PM +0000, deadalnix via 
>>>>>> Digitalmars-d wrote:
>>>>>>> | is bitwize or. || is binary or.
>>>>>>> & is bitwize and. && is binary and.
>>>>>>> ^ is bitwize xor. ^^ is... no, never mind.
>>>>>>
>>>>>> binary xor is.... !=
>>>>>>
>>>>>> lol
>>>>>
>>>>> 3 != 5 is true.
>>>>> 3 binaryxor 5 is false.
>>>>
>>>> He meant logical xor, because binary xor exists (^) and 
>>>> there would be no point to mention an equivalence.
>>>
>>> Still doesn't work.
>>
>> It works if you cast each side of the comparison to boolean 
>> values (that's what logical and/or do implicitely, for != it 
>> has to be done explicitely as the operator has never been seen 
>> as logical xor).
>> in C (sorry I'm not fluent in D yet).
>> (bool)3 != (bool)5    or  old fashioned    !!3 != !!5 or after 
>> De Morgan transformation !3 == !5.
>
> So, logical xor isn't != either is it ?

It is, I shouldn't have posted the old fashioned (i.e. without 
C99 bool type) version, it has confused you.

Let's see the truth table for logical xor and !=

a  |  b  |  a ^ b | a != b
---|-----|--------|--------
0  |  0  | 0      | 0
0  |  1  | 1      | 1
1  |  0  | 1      | 1
1  |  1  | 0      | 0

omg, it's the same result, but you have first to reduce each side 
of the expression to its canonical boolean value 0 or 1 (false or 
true in Java or D).
That's also what the logical && and || do, compared to & and |.





More information about the Digitalmars-d mailing list