From 481b9b3798431588fe742a25dfccab3c7027dcdf Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Sat, 9 Feb 2019 18:09:39 -0800 Subject: [PATCH] fix type punned pointer warnings --- main/MadgwickAHRS.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/MadgwickAHRS.cpp b/main/MadgwickAHRS.cpp index 38a8f8b..6b74d27 100644 --- a/main/MadgwickAHRS.cpp +++ b/main/MadgwickAHRS.cpp @@ -21,6 +21,7 @@ #include "MadgwickAHRS.h" #include +#include //------------------------------------------------------------------------------------------- // Definitions @@ -269,9 +270,12 @@ void Madgwick::updateIMU(float gx, float gy, float gz, float ax, float ay, float Madgwick::invSqrt(float x) { float halfx = 0.5f * x; float y = x; - long i = *(long *)&y; + // long i = *(long *)&y; + long i; + memcpy(&i, &y, sizeof(float)); i = 0x5f3759df - (i >> 1); - y = *(float *)&i; + // y = *(float *)&i; + memcpy(&y, &i, sizeof(float)); y = y * (1.5f - (halfx * y * y)); y = y * (1.5f - (halfx * y * y)); return y;