I'm trying to write a very basic if() conditional statement, which in its ideal/simplest form, should look like this:
Code:
double Lq[5] = {0.0};
double Lq_sign = 0.0;
/* call function to assign values to Lq[ ] array */
for(j = 0; j < 5; j++){
Lq_sign = 0.0;
if(Lq[j] >= 0.005) Lq_sign = 1.0;
else if(fabs(Lq[j]) < 0.005) Lq_sign = 0.0;
else if(Lq[j] <= -0.005) Lq_sign = -1.0;
}
When I print the resulting Lq_sign values for each iteration, the values of 1.0 and 0.0 are correctly assigned with no problems. However, the assignment of -1.0 never happens (the Lq values that *should* be -1.0 show up as 0.0).
I've done some troubleshooting, to determine why the negative Lq values aren't being recognized. Below are the various troubleshooting statements that I've performed:
Code:
...
else if(fabs(Lq[j]) > 0.005) printf("abs val is > 0.005.\n"); /* A */
else if(Lq[j] < 0.0) printf("Lq[%d] is < 0.\n", j); /* B */
else if((fabs(Lq[j]) > 0.005) && (Lq[j] < 0)) Lq_sign = -1.0; /* C */
Statement A above always executes when it should, whether the Lq value in question is + or --. However, statement B *never* executes, although there are plenty of negative Lq values that should trigger this statement. And, of course, statement C never executes.
Does anyone have a suggestion about why my negative Lq[ ] array values aren't being recognized as negative?? Thanks in advance for your input.