Was looking at the code in MS2 and me thinks I've found a bug in the air density correction code...
There is a cast to an unsigned char (ccor) when in the cor calc above it could be less than 100 and therefore "cor - 100" could be -3 and when cast to unsigned char this would be a bad/incorrect value yeah? Even worse, the sign from the previous calc is also lost by making it unsigned.
Code: Select all
int aircor_eq(int mat)
{
signed int cor;
signed char ccor;
// returns air density correction from equation in % (100 is no correction)
... <snip> ....
cor = 529700 / (mat + 4597);
// Changed for 3.0.3w to ignore this (unused) setting always use degF internally.
// }
// else { // deg C
// cor = 293200 / (mat + 2732);
// }
if (flash5.airden_scaling) { // only if non-zero
ccor = (unsigned char)cor - 100; /// <<<<<<< this shouldn't be cast to an unsigned char !!!
cor = ((signed int)(ccor * flash5.airden_scaling)) / 100;
cor = cor + 100;
}
return (int)cor;
}