From 495a23a80a172f4c0fbda3f087d1469f7d5f734b Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 20 Nov 2010 11:07:24 +0100 Subject: [PATCH] Avoid division by zero in exponential filters --- src/Autopilot/digitalfilter.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Autopilot/digitalfilter.cxx b/src/Autopilot/digitalfilter.cxx index 57bca13c8..45087a79a 100644 --- a/src/Autopilot/digitalfilter.cxx +++ b/src/Autopilot/digitalfilter.cxx @@ -265,9 +265,14 @@ void ExponentialFilterImplementation::initialize( double output ) double ExponentialFilterImplementation::compute( double dt, double input ) { input = GainFilterImplementation::compute( dt, input ); + double tf = _TfInput.get_value(); double output_0; - double alpha = 1 / ((_TfInput.get_value()/dt) + 1); + + // avoid negative filter times + // and div by zero if -tf == dt + + double alpha = tf > 0.0 ? 1 / ((tf/dt) + 1) : 1.0; if(_isSecondOrder) { output_0 = alpha * alpha * input + -- 2.39.5