fix UC_ROUND_UP()

This commit is contained in:
Nils O. Selåsdal
2014-09-06 04:03:20 +02:00
parent a27711e3bd
commit 7eb42cc538
+8 -4
View File
@@ -95,20 +95,24 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
#define UC_DIV_ROUND_UP(x, y) (((x) + ((y) - 1))/(y)) #define UC_DIV_ROUND_UP(x, y) (((x) + ((y) - 1))/(y))
/** /**
* Round x down to nearest multiple of y * Round x up to nearest multiple of y
* e.g. UC_ROUND_UP(30,48) == 48
* e.g. UC_ROUND_UP(49,48) == 96
* *
* @param x numerator, must be positive * @param x numerator, must be positive
* @param y denominator * @param y denominator
* @return x rounded to nearest multiple of y * @return x rounded up to nearest multiple of y
*/ */
#define UC_ROUND_UP(x, y) (((x) / (y)) * (y)) #define UC_ROUND_UP(x, y) (UC_DIV_ROUND_UP(x, y) * (y))
/** /**
* Round x down to nearest multiple of y * Round x down to nearest multiple of y
* e.g. UC_ROUND_UP(30,48) == 0
* e.g. UC_ROUND_UP(49,48) == 48
* *
* @param x numerator, must be positive * @param x numerator, must be positive
* @param y denominator * @param y denominator
* @return x rounded to nearest multiple of y * @return x rounded down nearest multiple of y
*/ */
#define UC_ROUND_DOWN(x, y) ((x) / (y) * (y)) #define UC_ROUND_DOWN(x, y) ((x) / (y) * (y))