libc/math: Fix warning: dereferencing type-punned pointer will break strict-aliasing rules

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I15aa5d664c20ea7bb95ba60e056134d2ff933db9
This commit is contained in:
Xiang Xiao 2020-06-29 22:40:25 +08:00 committed by Abdelatif Guettouche
parent 43b613877d
commit b71c491f00

View File

@ -38,13 +38,16 @@
float lib_sqrtapprox(float x)
{
int32_t i;
union
{
int32_t i;
float x;
} u;
/* Floats + bit manipulation = +inf fun! */
i = *((int32_t *) & x);
i = 0x1fc00000 + (i >> 1);
x = *((float *)&i);
u.x = x;
u.i = 0x1fc00000 + (u.i >> 1);
return x;
return u.x;
}