brintos

brintos / linux-shallow public Read only

0
0
Text · 764 B · 4e7af99 Raw
26 lines · c
1#ifndef _TOOLS_MATH_H2#define _TOOLS_MATH_H3 4/*5 * This looks more complex than it should be. But we need to6 * get the type for the ~ right in round_down (it needs to be7 * as wide as the result!), and we want to evaluate the macro8 * arguments just once each.9 */10#define __round_mask(x, y) ((__typeof__(x))((y)-1))11#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)12#define round_down(x, y) ((x) & ~__round_mask(x, y))13 14#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))15 16#ifndef roundup17#define roundup(x, y) (                                \18{                                                      \19	const typeof(y) __y = y;		       \20	(((x) + (__y - 1)) / __y) * __y;	       \21}                                                      \22)23#endif24 25#endif26