mirror of
https://github.com/lvgl/lvgl.git
synced 2026-06-02 01:18:04 +08:00
fix(vg_lite): fix strict alias warning with higher optimization levels (#8136)
This commit is contained in:
@@ -39,19 +39,14 @@
|
|||||||
|
|
||||||
float math_fast_inv_sqrtf(float number)
|
float math_fast_inv_sqrtf(float number)
|
||||||
{
|
{
|
||||||
const float threehalfs = 1.5f;
|
/* From https://en.wikipedia.org/wiki/Fast_inverse_square_root#Avoiding_undefined_behavior */
|
||||||
|
union {
|
||||||
float x2 = number * 0.5f;
|
float f;
|
||||||
float y = number;
|
int32_t i;
|
||||||
int32_t i = *(int32_t *)&y; /* evil floating point bit level hacking */
|
} conv = { .f = number };
|
||||||
|
conv.i = 0x5f3759df - (conv.i >> 1);
|
||||||
i = 0x5f3759df /* floating-point representation of an approximation of {\sqrt {2^{127}}}} see https://en.wikipedia.org/wiki/Fast_inverse_square_root. */
|
conv.f *= 1.5F - (number * 0.5F * conv.f * conv.f);
|
||||||
- (i >>
|
return conv.f;
|
||||||
1);
|
|
||||||
y = *(float *)&i;
|
|
||||||
y = y * (threehalfs - (x2 * y * y)); /* 1st iteration */
|
|
||||||
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|||||||
Reference in New Issue
Block a user