File Index
Files and directories
Sign in
FILE

math.h

File preview with syntax highlighting.

linux-6.19.14/tools/include/linux/math.h C
 1#ifndef _TOOLS_MATH_H
 2#define _TOOLS_MATH_H
 3
 4/*
 5 * This looks more complex than it should be. But we need to
 6 * get the type for the ~ right in round_down (it needs to be
 7 * as wide as the result!), and we want to evaluate the macro
 8 * 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 roundup
17#define roundup(x, y) (                                \
18{                                                      \
19	const typeof(y) __y = y;		       \
20	(((x) + (__y - 1)) / __y) * __y;	       \
21}                                                      \
22)
23#endif
24
25#endif
~/ Read-only file preview.