Rounding up and Down
include/math/round.h View source View on GitHubMacros
Section titled “Macros”ROUND_UP
Section titled “ROUND_UP”#define ROUND_UP(x, y) (((x) + (y) - 1) / (y)) ROUND_DOWN
Section titled “ROUND_DOWN”#define ROUND_DOWN(x, y) ((x) / (y)) #define ROUND(x, y) (((x) + ((y) / 2)) / (y)) ROUND_UP_TO_POWER_OF_2
Section titled “ROUND_UP_TO_POWER_OF_2”#define ROUND_UP_TO_POWER_OF_2(x) (1 << (32 - __builtin_clz(x - 1))) ROUND_DOWN_TO_POWER_OF_2
Section titled “ROUND_DOWN_TO_POWER_OF_2”#define ROUND_DOWN_TO_POWER_OF_2(x) (1 << (31 - __builtin_clz(x))) ROUND_TO_POWER_OF_2
Section titled “ROUND_TO_POWER_OF_2”#define ROUND_TO_POWER_OF_2(x) (1 << (32 - __