Skip to content

Commit

Permalink
Merge pull request #12 from markub3327/master
Browse files Browse the repository at this point in the history
Avoid warnings about `type-punned`
  • Loading branch information
aster94 authored Jan 10, 2023
2 parents 91e68c8 + a2cd7bd commit 28a74ab
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/SensorFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ SF::SF()
float SF::invSqrt(float x)
{
float halfx = 0.5f * x;
float y = x;
long i = *(long*)&y;
i = 0x5f3759df - (i>>1);
y = *(float*)&i;
y = y * (1.5f - (halfx * y * y));
y = y * (1.5f - (halfx * y * y));
union {
float f;
uint32_t i;
} conv = { .f = x };
conv.i = 0x5f3759df - (conv.i >> 1);
conv.f *= 1.5f - (halfx * conv.f * conv.f);
conv.f *= 1.5f - (halfx * conv.f * conv.f);
return y;
}

Expand Down

0 comments on commit 28a74ab

Please sign in to comment.