1
2 #ifndef _LINUX_HELPER_MACROS_H_
3 #define _LINUX_HELPER_MACROS_H_
4
5 #define __find_closest(x, a, as, op) \
6 ({ \
7 typeof(as) __fc_i, __fc_as = (as) - 1; \
8 typeof(x) __fc_x = (x); \
9 typeof(*a) const *__fc_a = (a); \
10 for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \
11 if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \
12 __fc_a[__fc_i + 1], 2)) \
13 break; \
14 } \
15 (__fc_i); \
16 })
17
18
19
20
21
22
23
24
25
26
27 #define find_closest(x, a, as) __find_closest(x, a, as, <=)
28
29
30
31
32
33
34
35
36
37
38
39 #define find_closest_descending(x, a, as) __find_closest(x, a, as, >=)
40
41 #endif