I’ve noticed that a lot of usage of double as floating-point types. So many infact that it is probably intended. @Antun_Skuric you do know that not post-fixing floating point constant is interpreted as a double (on most compilers with default settings, at least)?
If you look at foc_utils
I don’t see a single
it should read:
#define _sign(a) ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) ) #define _round(x) ((x)>=0?(long)((x)+0.5f):(long)((x)-0.5f)) #define _constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define _sqrt(a) (_sqrtApprox(a)) #define _isset(a) ( (a) != (NOT_SET) ) #define _UNUSED(v) (void) (v) // utility defines #define _2_SQRT3 1.15470053838f #define _SQRT3 1.73205080757f #define _1_SQRT3 0.57735026919f #define _SQRT3_2 0.86602540378f #define _SQRT2 1.41421356237f #define _120_D2R 2.09439510239f #define _PI 3.14159265359f #define _PI_2 1.57079632679f #define _PI_3 1.0471975512f #define _2PI 6.28318530718f #define _3PI_2 4.71238898038f #define _PI_6 0.52359877559f #define NOT_SET -12345.0f
It can have a dramatic impact on performance, especially for 8-bit MCU, but also for M0, M4 and M4F cores. I’ve read somewhere that the M4F reverts to software based floating poins when presented with doubles.