… | |
… | |
35 | #define IN_RANGE_EXC(val,beg,end) \ |
35 | #define IN_RANGE_EXC(val,beg,end) \ |
36 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
36 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
37 | |
37 | |
38 | void fork_abort (const char *msg); |
38 | void fork_abort (const char *msg); |
39 | |
39 | |
|
|
40 | // rationale for using (U) not (T) is to reduce signed/unsigned issues, |
|
|
41 | // as a is often a constant while b is the variable. it is still a bug, though. |
40 | template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } |
42 | template<typename T, typename U> static inline T min (T a, U b) { return (U)a < b ? (U)a : b; } |
41 | template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } |
43 | template<typename T, typename U> static inline T max (T a, U b) { return (U)a > b ? (U)a : b; } |
42 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } |
44 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? (T)a : v >(T)b ? (T)b : v; } |
43 | |
45 | |
44 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
46 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
45 | |
47 | |
46 | // this is much faster than crossfires original algorithm |
48 | // this is much faster than crossfires original algorithm |
47 | // on modern cpus |
49 | // on modern cpus |