Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _TOOLS_MATH_H
0002 #define _TOOLS_MATH_H
0003 
0004 /*
0005  * This looks more complex than it should be. But we need to
0006  * get the type for the ~ right in round_down (it needs to be
0007  * as wide as the result!), and we want to evaluate the macro
0008  * arguments just once each.
0009  */
0010 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
0011 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
0012 #define round_down(x, y) ((x) & ~__round_mask(x, y))
0013 
0014 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
0015 
0016 #ifndef roundup
0017 #define roundup(x, y) (                                \
0018 {                                                      \
0019     const typeof(y) __y = y;               \
0020     (((x) + (__y - 1)) / __y) * __y;           \
0021 }                                                      \
0022 )
0023 #endif
0024 
0025 #endif