I’m wondering what is the problem in the following code
[codebox]int i, j, KI, KJ, KIJ;
KI = ( i < 10000 ) ? 0 : 1;
for ( … )
{
j = …
KJ = ( j < 10000 ) ? 0 : 1;
KIJ = ( KI != KJ ) ? 1: ( ( KI == 0 ) ? 0 : 2 );
// KIJ = ( KI | KJ ) + ( KI & KJ );
// KIJ = KI + KJ;
result = array[KIJ] * R4 + array[KIJ] / ( 1.0 + R2 );
…
}
[/codebox]
array[3] is a constant array.
If I use KIJ = ( KI != KJ ) ? 1: ( ( KI == 0 ) ? 0 : 2 ) the code is ok,
but when KIJ = KI + KJ or KIJ = ( KI | KJ ) + ( KI & KJ ) is used, the result is not right.
Is there any error in the code?