00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00036
00037 #ifndef _KernelMath_h_
00038 #define _KernelMath_h_
00039
00040
00041
00042
00043
00044 #include <limits.h>
00045
00046
00047
00048
00049
00052 template <class T>
00053 inline T Max(T a, T b)
00054 {
00055 return a > b ? a : b;
00056 }
00057
00058
00061 inline double Max(double a, double b)
00062 {
00063 return a > b ? a : b;
00064 }
00065
00068 inline double Max(double a, long b)
00069 {
00070 return a > b ? a : b;
00071 }
00072
00075 inline double Max(double a, unsigned long b)
00076 {
00077 return a > b ? a : b;
00078 }
00079
00082 inline double Max(double a, int b)
00083 {
00084 return a > b ? a : b;
00085 }
00086
00089 inline double Max(double a, unsigned b)
00090 {
00091 return a > b ? a : b;
00092 }
00093
00096 inline double Max(long a, double b)
00097 {
00098 return a > b ? a : b;
00099 }
00100
00103 inline double Max(unsigned long a, double b)
00104 {
00105 return a > b ? a : b;
00106 }
00107
00110 inline double Max(int a, double b)
00111 {
00112 return a > b ? a : b;
00113 }
00114
00117 inline double Max(unsigned a, double b)
00118 {
00119 return a > b ? a : b;
00120 }
00121
00124 inline int Max(int a, int b)
00125 {
00126 return a > b ? a : b;
00127 }
00128
00129 #if 1
00130
00133 inline unsigned long Max(unsigned long a, int b)
00134 {
00135
00136 return b < 0 ? a : Max(unsigned(a), unsigned(b));
00137 }
00138
00141 inline unsigned long Max(int a, unsigned long b)
00142 {
00143
00144 return a < 0 ? b : Max(unsigned(a), unsigned(b));
00145 }
00146
00149 inline unsigned long Max(unsigned a, unsigned long b)
00150 {
00151 return a > b ? a : b;
00152 }
00153 #endif
00154
00157 inline unsigned Max(unsigned a, unsigned b)
00158 {
00159 return a > b ? a : b;
00160 }
00161
00164 inline unsigned Max(int a, unsigned b)
00165 {
00166 return a < 0 ? b : Max(unsigned(a), b);
00167 }
00168
00171 inline unsigned Max(unsigned a, int b)
00172 {
00173 return Max(b, a);
00174 }
00175
00178 inline double Max(double a, double b, double c)
00179 {
00180 return Max(a, Max(b, c));
00181 }
00182
00185 template<typename A, typename B, typename C, typename D, typename R>
00186 inline R Max(A a, B b, C c, D d)
00187 {
00188 return Max(a, Max(b, Max(c, d)));
00189 }
00190
00193 template <class T>
00194 inline T Min(T a, T b)
00195 {
00196 return a < b ? a : b;
00197 }
00198
00201 inline double Min(double a, double b)
00202 {
00203 return a < b ? a : b;
00204 }
00205
00208 inline double Min(double a, long b)
00209 {
00210 return a < b ? a : b;
00211 }
00212
00215 inline double Min(double a, int b)
00216 {
00217 return a < b ? a : b;
00218 }
00219
00222 inline double Min(double a, unsigned long b)
00223 {
00224 return a < b ? a : b;
00225 }
00226
00229 inline double Min(double a, unsigned b)
00230 {
00231 return a < b ? a : b;
00232 }
00233
00236 inline double Min(long a, double b)
00237 {
00238 return a < b ? a : b;
00239 }
00240
00243 inline double Min(int a, double b)
00244 {
00245 return a < b ? a : b;
00246 }
00247
00250 inline double Min(unsigned long a, double b)
00251 {
00252 return a < b ? a : b;
00253 }
00254
00257 inline double Min(unsigned a, double b)
00258 {
00259 return a < b ? a : b;
00260 }
00261
00264 inline int Min(int a, int b)
00265 {
00266 return a < b ? a : b;
00267 }
00268
00271 inline void* Min(void* a, void* b)
00272 {
00273 return a < b ? a : b;
00274 }
00275
00278 inline unsigned Min(unsigned a, unsigned b)
00279 {
00280 return a < b ? a : b;
00281 }
00282
00285 inline int Min(int a, unsigned int b)
00286 {
00287 return b > INT_MAX ? a : (Min(int(b), a));
00288 }
00289
00292 inline int Min(unsigned int a, int b)
00293 {
00294 return Min(b, a);
00295 }
00296
00299 inline double Min(double a, double b, double c)
00300 {
00301 return Min(a, Min(b, c));
00302 }
00303
00306 template<typename A, typename B, typename C, typename D, typename R>
00307 inline R Min(A a, B b, C c, D d)
00308 {
00309 return Min(a, Min(b, Min(c, d)));
00310 }
00311
00314 template<typename T>
00315 inline T Abs(T x)
00316 {
00317 return (x > 0 ? x : -x);
00318 }
00319
00320 #endif