From 3c4220e78403b2193c073f8f732c483e7ef3e8a3 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 26 Dec 2021 19:32:44 -0600 Subject: [PATCH] AICarrier: clamp bug fix. Since this code attempts to clamp values between 0.0 and 1.0, the comparision needs to occur using double types. --- src/AIModel/AICarrier.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index 5aa8c0924..292bfc17a 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -712,11 +712,12 @@ void FGAICarrier::UpdateElevator(double dt) { _elevator_pos_norm = (_elevator_pos_norm_raw * _elevator_time_constant) + (_elevator_pos_norm * (1 - _elevator_time_constant)); //sanitise the output - if (_elevator_pos_norm_raw >= 1) { - _elevator_pos_norm_raw = 1; - } else if (_elevator_pos_norm_raw <= 0) { - _elevator_pos_norm_raw = 0; + if (_elevator_pos_norm_raw >= 1.0) { + _elevator_pos_norm_raw = 1.0; + } else if (_elevator_pos_norm_raw <= 0.0) { + _elevator_pos_norm_raw = 0.0; } + return; } // end UpdateElevator @@ -754,10 +755,10 @@ void FGAICarrier::UpdateJBD(double dt) { _jbd_elevator_pos_norm = (_jbd_elevator_pos_norm_raw * _jbd_time_constant) + (_jbd_elevator_pos_norm * (1 - _jbd_time_constant)); //sanitise the output - if (_jbd_elevator_pos_norm >= 1) { - _jbd_elevator_pos_norm = 1; - } else if (_jbd_elevator_pos_norm <= 0) { - _jbd_elevator_pos_norm = 0; + if (_jbd_elevator_pos_norm >= 1.0) { + _jbd_elevator_pos_norm = 1.0; + } else if (_jbd_elevator_pos_norm <= 0.0) { + _jbd_elevator_pos_norm = 0.0; } return;