I was told the following
was equivalent toCode:if ( (a && b) || (!a && !b) )
Can someone explain to me how they arrive at this answer? I really don't see the steps involved.Code:if(!!a == !!b)
This is a discussion on I don't get how the following expression gets simplified within the C Programming forums, part of the General Programming Boards category; I was told the following Code: if ( (a && b) || (!a && !b) ) was equivalent to Code: ...
I was told the following
was equivalent toCode:if ( (a && b) || (!a && !b) )
Can someone explain to me how they arrive at this answer? I really don't see the steps involved.Code:if(!!a == !!b)
The first expression evaluates to true if both a and b are true, or if neither a nor b are true. Since any non-zero value is true, then you cannot just condense this to "a == b". But if you double-negate, then a true value negates to zero, then negates to one, and then the comparison will work.
If only we had a logical XOR (as opposed to bitwise), we could say:
But alas we don't.Code:if( ! ( a ^^ b ) )
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Okay. I get it.
It could be further simplified to either:
!a == !b
- or -
!( !a ^ !b )
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}