Teensyduino still uses these Arduino macors for abs and round
Not only that round causes warnings for double promotions... , they are not needed because they are already exist in newlib , are builtins for gcc, etc.
So, anyone knows why we need these macros, and would it be a problem to remove them?
Edit: Yes, one can argue that this round returns a long. Ok, if Arduino really wants that (why?? - its against the standards) you could better write that as #define round(x) ((long)__builtin_round(x)) - so why that macro with a conditional, and doubles?
Code:
#define abs(x) ({ \
typeof(x) _x = (x); \
(_x > 0) ? _x : -_x; \
})
#define round(x) ({ \
typeof(x) _x = (x); \
(_x>=0) ? (long)(_x+0.5) : (long)(_x-0.5); \
})
Not only that round causes warnings for double promotions... , they are not needed because they are already exist in newlib , are builtins for gcc, etc.
So, anyone knows why we need these macros, and would it be a problem to remove them?
Edit: Yes, one can argue that this round returns a long. Ok, if Arduino really wants that (why?? - its against the standards) you could better write that as #define round(x) ((long)__builtin_round(x)) - so why that macro with a conditional, and doubles?
Last edited: