diff options
author | Keith Packard <keithp@keithp.com> | 2012-12-09 18:27:49 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-12-09 18:27:49 -0800 |
commit | defd5d0784a754be30e3295067fbc85a108ad172 (patch) | |
tree | 891a08c4ea8f0eaad39b46cae64fb2a0f212c14f /src/core | |
parent | 24948ea1d41f2a7c96ac09e35d1250909e5726ae (diff) |
altos: Make sure pa to altitude conversion is done with 32 bits
We need 32 bits to hold intermediate values, even if the final
altitude is reported in only 16 bits.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ao_convert_pa.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/core/ao_convert_pa.c b/src/core/ao_convert_pa.c index 55fe6e7d..fe6e0ef6 100644 --- a/src/core/ao_convert_pa.c +++ b/src/core/ao_convert_pa.c @@ -43,13 +43,13 @@ ao_pa_to_altitude(int32_t pa) if (pa < 0) pa = 0; - if (pa > 120000) - pa = 120000; + if (pa > 120000L) + pa = 120000L; o = 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); + low = (int32_t) FETCH_ALT(o) * (ALT_SCALE - part); + high = (int32_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1); return (low + high) >> ALT_SHIFT; } |