ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.78 by root, Thu Dec 4 03:48:19 2008 UTC vs.
Revision 1.79 by root, Fri Dec 19 22:47:29 2008 UTC

105template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } 105template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; }
106 106
107template<typename T, typename U, typename V> static inline T min (T a, U b, V c) { return min (a, min (b, c)); } 107template<typename T, typename U, typename V> static inline T min (T a, U b, V c) { return min (a, min (b, c)); }
108template<typename T, typename U, typename V> static inline T max (T a, U b, V c) { return max (a, max (b, c)); } 108template<typename T, typename U, typename V> static inline T max (T a, U b, V c) { return max (a, max (b, c)); }
109 109
110// sign returns -1 or +1
111template<typename T>
112static inline T sign (T v) { return v < 0 ? -1 : +1; }
113// relies on 2c representation
114template<>
115inline sint8 sign (sint8 v) { return 1 - (sint8 (uint8 (v) >> 7) * 2); }
116
117// sign0 returns -1, 0 or +1
118template<typename T>
119static inline T sign0 (T v) { return v ? sign (v) : 0; }
120
110// div, with correct rounding (< 0.5 downwards, >=0.5 upwards) 121// div, with correct rounding (< 0.5 downwards, >=0.5 upwards)
111template<typename T> static inline T div (T val, T div) { return (val + div / 2) / div; } 122template<typename T> static inline T div (T val, T div) { return (val + div / 2) / div; }
112// div, round-up 123// div, round-up
113template<typename T> static inline T div_ru (T val, T div) { return (val + div - 1) / div; } 124template<typename T> static inline T div_ru (T val, T div) { return (val + div - 1) / div; }
114// div, round-down 125// div, round-down

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines