core/macros: add math helper macros
Contribution description
This adds a few commonly useful math helper macros to core/macros:
SIGNOF()returns the sign of an integerDIV_ROUND()performs arithmetic integer divisionDIV_ROUND_UP()performs arithmetic integer division, always rounding to the next integer larger in magnitude.
Testing procedure
unittests/tests-core was extended with test cases for the new macros
Issues/PRs references
... and they are supposed to be used in compile-time situations, I guess?
Also at run-time. It's just that I've found myself open-coding those way too often, so I thought providing a macro would be appropriate.
https://github.com/RIOT-OS/RIOT/blob/6db9960741cc93acbc903f482a93391333f8b6e8/cpu/stm32/periph/ptp.c#L63-L71
It's just that I've found myself open-coding those way too often, so I thought providing a macro would be appropriate.
Yes, indeed. Is just one of the cases where this would have been useful.