mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-1535 - uses union in fast_invsqrt
This commit is contained in:
parent
5d074063d1
commit
fe20e39d5c
@ -124,17 +124,20 @@ static inline float y_on_curve(float x, const pointf points[], int num_points)
|
||||
|
||||
static inline float fast_invsqrtf(float number)
|
||||
{
|
||||
uint32_t i;
|
||||
float x2, y;
|
||||
const float threehalfs = 1.5F;
|
||||
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} i;
|
||||
|
||||
x2 = number * 0.5F;
|
||||
y = number;
|
||||
void *tmp = &y;
|
||||
i = *(uint32_t *)tmp; // evil floating point bit level hacking
|
||||
i = 0x5f3759df - (i >> 1); // what the fxck?
|
||||
tmp = &i;
|
||||
y = *(float *)tmp;
|
||||
|
||||
i.f = y; // evil floating point bit level hacking
|
||||
i.u = 0x5f3759df - (i.u >> 1); // what the fxck?
|
||||
y = i.f;
|
||||
y = y * (threehalfs - (x2 * y * y)); // 1st iteration
|
||||
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user