Comment 1 for bug 396278

Revision history for this message
Andy St.Martin (andystmartin) wrote :

There is an operator precedence snafu in WeatherStation::fitValue in weatherstation.cpp.

The line checking that the number of digits of the temperature is less than the total digits allowed looks like this:
    if (mainDigits < 3 && mainDigits + (v < 0)?1:0 + 1 < digits) {

The "?:" is supposed to add 1 ito the mainDigits if the temp is less than 0. However, '+" and '<' have higher precedence than "?:". This yields an expected value. When parentheses are properly inserted, the correct value is evaluated. Such as:
    if (mainDigits < 3 && (mainDigits + ((v < 0)?1:0) + 1) < digits) {

Finally, the last "<" should probably be a "<=". If 3 digits are allowed and allowing for a tenth of a degree is 3 or less, then display the tenth. I think the final, correct expression should look something like this:
    if (mainDigits < 3 && (mainDigits + ((v < 0)?1:0) + 1) <= digits) {