Skip to content

Commit 839e293

Browse files
author
Richard Unger
committed
trying to fix sqrt compiler issue on esp32
1 parent 3dd61bb commit 839e293

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/common/foc_utils.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,10 @@ float _electricalAngle(float shaft_angle, int pole_pairs) {
8787
// https://reprap.org/forum/read.php?147,219210
8888
// https://en.wikipedia.org/wiki/Fast_inverse_square_root
8989
__attribute__((weak)) float _sqrtApprox(float number) {//low in fat
90-
// float x;
91-
// const float f = 1.5F; // better precision
92-
93-
// x = number * 0.5F;
94-
float y;
95-
y = number;
96-
uint32_t i = *reinterpret_cast<uint32_t*>(&y);
97-
i = 0x5f375a86 - ( i >> 1 );
98-
y = *reinterpret_cast<float*>(&i);
99-
// y = y * ( f - ( x * y * y ) ); // better precision
100-
return number * y;
90+
union {
91+
float f;
92+
uint32_t i;
93+
} y = { .f = number };
94+
y.i = 0x5f375a86 - ( y.i >> 1 );
95+
return number * y.f;
10196
}

0 commit comments

Comments
 (0)