*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
alt_t
ao_pa_to_altitude(pres_t pa)
{
- int16_t o;
+ uint16_t o;
int16_t part;
alt_t low, high;
pa = 0;
if (pa > 120000L)
pa = 120000L;
- o = pa >> ALT_SHIFT;
+ o = (uint16_t) (pa >> ALT_SHIFT);
part = pa & ALT_MASK;
low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part);
- high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1);
- return (low + high) >> ALT_SHIFT;
+ high = (alt_t) FETCH_ALT(o+1) * part;
+ return (low + high + (ALT_SCALE >> 1)) >> ALT_SHIFT;
}
#ifdef AO_CONVERT_TEST