]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/util/misc.h
Initial checkin from Perforce.
[polintos/scott/priv.git] / include / c++ / util / misc.h
1 #ifndef _UTIL_MISC_H
2 #define _UTIL_MISC_H
3
4 namespace Util {
5         // Round the given value up or down to the specified power-of-two.
6
7         template<typename T>
8         static inline T round_up(T val, int shift)
9         {
10                 return (val + (1UL << shift) - 1) & ~((1UL << shift) - 1);
11         }
12
13         template<typename T>
14         static inline T round_down(T val, int shift)
15         {
16                 return val & ~((1UL << shift) - 1);
17         }
18 }
19
20 #endif