From ff01781f6cdada33c6545c0f9c8601e9e7336284 Mon Sep 17 00:00:00 2001 From: JuliooCesarMDM Date: Sun, 15 Aug 2021 18:46:39 -0300 Subject: [PATCH] Safe SquareRoot --- src/main/common/maths.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/common/maths.c b/src/main/common/maths.c index a99c3f346b..4a07f7a8ef 100644 --- a/src/main/common/maths.c +++ b/src/main/common/maths.c @@ -524,11 +524,15 @@ float bellCurve(const float x, const float curveWidth) } float fast_fsqrtf(const double value) { + float ret = 0.0f; #ifdef USE_ARM_MATH - float squirt; - arm_sqrt_f32(value, &squirt); - return squirt; + arm_sqrt_f32(value, &ret); #else - return sqrtf(value); + ret = sqrtf(value); #endif + if (isnan(ret)) + { + return 0; + } + return ret; } \ No newline at end of file