Traumflug / Teacup_Firmware

Firmware for RepRap and other 3D printers
http://forums.reprap.org/read.php?147
GNU General Public License v2.0
312 stars 199 forks source link

preprocessor_math #284

Open Wurstnase opened 6 years ago

Wurstnase commented 6 years ago

The compiler this days doing a good job.

sqrt(x) is calculated at compile-time without overhead. So there is no need anymore for the preprocessor SQRT(x).
Traumflug commented 6 years ago

Good news!

Wurstnase commented 6 years ago

GCC <= 4 needs a _builtin\ function. e.g. __builtin_sqrt.

So for the Arduino IDE we replace now sqrt with the builtin instruction. This will also fit if this is not a constant expression.

dda.c:65:3: warning: initializer element is not a constant expression
   (uint32_t)((double)F_CPU / sqrt((double)STEPS_PER_M_X * ACCELERATION / 2000.)),
   ^
dda.c:65:3: warning: (near initialization for 'c0_P[0]')