[C] Comparisons versus XOR
1
Name:
Anonymous
2010-11-14 12:39
You're parsing arguments and they are mutually exclusive.
if ((A == 0 && B == 0) || (A != 0 && B!= 0))
return EXIT_FAILURE;
versus
if ((A ^ B) == 0)
return EXIT_FAILURE;
2
Name:
Anonymous
2010-11-14 12:45
versus
if(A/B == 0)
return EXIT_FAILURE;
3
Name:
Anonymous
2010-11-14 12:50
#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes
unless(A^B)return EF;
4
Name:
Anonymous
2010-11-14 12:50
if(!(A && B) && !(!A && !B))
return ANUS_FAILURE;
5
Name:
VIPPER
2010-11-14 12:53
>>1
You might aswell use:
if ((!A && !B) || (A && B))
return EXIT_FAILURE;
if (!A ^ B)
return EXIT_FAILURE;
6
Name:
Anonymous
2010-11-14 12:54
if(!(A && B) && !(!A && !B))
return ANUS_FAILURE;
7
Name:
Anonymous
2010-11-14 12:55
>>5
if (!A ^ B)
Logical NOT used in bitwise operation
8
Name:
Anonymous
2010-11-14 12:57
>>4 Oops!
if(!(!(A && B) && !(!A && !B)))
return ANUS_FAILURE;
9
Name:
Anonymous
2010-11-14 15:27
10
Name:
Anonymous
2010-11-14 15:33
Short-circuits are faster if we are dealing with booleans. If A and B are HUGE -bit extreme floats it is not cool to wake your x87.
11
Name:
Anonymous
2010-11-14 21:39
One's anus should not use xor in this place. Consider A = 2, B=4
First version will return, xor version will not.
ENTERPRISE solution:
if(!!a == !!b) return;
Using See !! Normalise Integer operator.
And real hardcore
if((!!a + !!b)&1==0) return;
12
Name:
Anonymous
2010-11-15 2:09
if (!A ^ !B) return EXIT_FAILURE;
13
Name:
Anonymous
2010-11-15 14:44
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
auto const unsigned int A = 2;
auto const unsigned int B = 4;
if ((A == 0 && B == 0) || (A != 0 && B!= 0))
printf("test01\n");
if ((A ^ B) == 0)
printf("test02\n");
if (A/B == 0)
printf("test03\n");
if (!(!(A && B) && !(!A && !B)))
printf("test04\n");
if ((!A && !B) || (A && B))
printf("test05\n");
if (!A ^ B)
printf("test06\n");
if (!(A && B) && !(!A && !B))
printf("test07\n");
if (!!A == !!B)
printf("test08\n");
if ((!!A + !!B) & 1 == 0)
printf("test09\n");
if (!A ^ !B)
printf("test10\n");
return EXIT_SUCCESS;
}
Output:
test01
test03
test04
test05
test06
test08
14
Name:
Anonymous
2010-11-15 17:07
Can I ask what is going on here? What was op trying to say? Two mutually exclusive parameters? As in... not equal?
like... != ?
!(A ^ B) === A != B
But the two propositions are not equivalent so how is it a comparison?
I am confuse.
15
Name:
Anonymous
2010-11-15 21:37
I'd just like to inform y'all that PHP, king of languages, has a logical xor operator. Enjoy your portable assembly.
16
Name:
Anonymous
2010-11-16 2:17
if ((!!A + !!B) & 1 == 0)
no test 9
Fuck! I forgot that C has shittiest precedence.
if ((!!A + !!B) & 1 == 0)printf("hurr\n");
if (((!!A + !!B) & 1) == 0)printf("durr\n");
Output:
durr
IHBT by K&R.
17
Name:
Anonymous
2010-11-16 21:12
>>14
From the first example given by the OP you should be able to get that he's parsing two arguments and only one is accepted into his shit.
18
Name:
Anonymous
2010-11-16 22:24
xor :: Bool -> Bool -> Bool
xor True = not
xor False = id
19
Name:
Anonymous
2010-11-17 0:31
>>17
but... Oh did op not realize second example wouldn't work?
... ooooo k.
20
Name:
Anonymous
2010-11-17 1:27
but... Oh did
>>19 realize
he have bitch tits ?
... ooooo k.
21
Name:
Anonymous
2011-02-03 2:29