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)
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:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }