What is wrong with this c code line? -


this line

double hdg_and_lee = cal_array[variation] +                      normalize(corrected.hdg + (corrcalc.twa > 0 && corrcalc.twa < 180)                      ? -abs(corrected.leeway) : abs(corrected.leeway)); 

returns value of cal_array[variation], incorrect. corrected.leeway happens 0 corrected.hdg 211, variation 14 , line evaluates to.

i changed this, works think should same line above.

double lee = (corrcalc.twa > 0 && corrcalc.twa < 180) ? -abs(corrected.leeway) : abs(corrected.leeway)); double hdg_and_lee; hdg_and_lee  = cal_array[variation] + corrected.hdg + lee; hdg_and_lee = normalize(hdg_and_lee); 

i can't see did wrong.

here normalize. makes angle between 0 , 360;

double normalize(double angle){     while (angle < 0) angle += 360;     while (angle > 360) angle -= 360;     return angle; } 

this driving me nuts of course have working alternative. want know went wrong.

try this

double hdg_and_lee = cal_array[variation] + normalize(corrected.hdg +  ((corrcalc.twa > 0 && corrcalc.twa < 180)? -abs(corrected.leeway) : abs(corrected.leeway))); 

check c operator precedence + vs. ?:.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -