From 64966d4539f20fb5b9ce5434a63494bc1fab992d Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 11 Jan 2016 11:17:33 -0800 Subject: [PATCH] Fix NaNs coming out of angle_approx_0deg27(). Used in FM demodulator, was causing downstream problems when using the floating point values directly. --- firmware/baseband/dsp_demodulate.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/firmware/baseband/dsp_demodulate.cpp b/firmware/baseband/dsp_demodulate.cpp index 42f04b01..67d24ca2 100644 --- a/firmware/baseband/dsp_demodulate.cpp +++ b/firmware/baseband/dsp_demodulate.cpp @@ -69,8 +69,12 @@ static inline float angle_approx_4deg0(const complex32_t t) { } */ static inline float angle_approx_0deg27(const complex32_t t) { - const auto x = static_cast(t.imag()) / static_cast(t.real()); - return x / (1.0f + 0.28086f * x * x); + if( t.real() ) { + const auto x = static_cast(t.imag()) / static_cast(t.real()); + return x / (1.0f + 0.28086f * x * x); + } else { + return (t.imag() < 0) ? -1.5707963268f : 1.5707963268f; + } } static inline float angle_precise(const complex32_t t) {