This commit is contained in:
2026-06-15 10:50:54 +02:00
parent cec0cd966b
commit 2fed5cbe1b
4 changed files with 17 additions and 6 deletions
+11 -2
View File
@@ -177,7 +177,8 @@ typedef unsigned __int128 U128;
#define CeilDiv(x, y) (((x) + ((y) - 1)) / (y))
/**
* Round x up to nearest multiple of y
* Round x up to nearest multiple of y:
* (((x) + (y) - 1) - (((x) + (y) - 1) % (y)))
* e.g. RoundUp(30,48) == 48
* e.g. RoundUp(49,48) == 96
*
@@ -185,7 +186,15 @@ typedef unsigned __int128 U128;
* @param y denominator
* @return x rounded up to nearest multiple of y
*/
#define RoundUpToMultiple(x, y) (CeilDiv((x), (y)) * (y))
#define RoundUpToMultiple(x, y) \
({ \
__typeof__(x) _x = (x); \
__typeof__(y) _y = (y); \
Assert(_y ! = 0); \
__typeof__(x) _tmp = _x + _y - 1; \
_tmp - _tmp % _y; \
})
/**
* Round x down to nearest multiple of y