00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef LEMON_TOLERANCE_H
00020 #define LEMON_TOLERANCE_H
00021
00028
00029
00030 namespace lemon {
00031
00034
00052
00053 template<class T>
00054 class Tolerance
00055 {
00056 public:
00057 typedef T Value;
00058
00063
00065
00067 static bool less(Value a,Value b) {return false;}
00069 static bool different(Value a,Value b) {return false;}
00071 static bool positive(Value a) {return false;}
00073 static bool negative(Value a) {return false;}
00075 static bool nonZero(Value a) {return false;}
00076
00078
00080 static Value zero() {return T();}
00081
00082
00083
00084
00085 };
00086
00087
00089
00093 template<>
00094 class Tolerance<float>
00095 {
00096 static float def_epsilon;
00097 float _epsilon;
00098 public:
00100 typedef float Value;
00101
00103 Tolerance() : _epsilon(def_epsilon) {}
00105 Tolerance(float e) : _epsilon(e) {}
00106
00108 Value epsilon() {return _epsilon;}
00110 void epsilon(Value e) {_epsilon=e;}
00111
00113 static Value defaultEpsilon() {return def_epsilon;}
00115 static void defaultEpsilon(Value e) {def_epsilon=e;}
00116
00119
00121
00123 bool less(Value a,Value b) {return a+_epsilon<b;}
00125 bool different(Value a,Value b) { return less(a,b)||less(b,a); }
00127 bool positive(Value a) { return _epsilon<a; }
00129 bool negative(Value a) { return -_epsilon>a; }
00131 Value nonZero(Value a) { return positive(a)||negative(a); };
00132
00134
00136 static Value zero() {return 0;}
00137 };
00138
00140
00144 template<>
00145 class Tolerance<double>
00146 {
00147 static double def_epsilon;
00148 double _epsilon;
00149 public:
00151 typedef double Value;
00152
00154 Tolerance() : _epsilon(def_epsilon) {}
00156 Tolerance(double e) : _epsilon(e) {}
00157
00159 Value epsilon() {return _epsilon;}
00161 void epsilon(Value e) {_epsilon=e;}
00162
00164 static Value defaultEpsilon() {return def_epsilon;}
00166 static void defaultEpsilon(Value e) {def_epsilon=e;}
00167
00170
00172
00174 bool less(Value a,Value b) {return a+_epsilon<b;}
00176 bool different(Value a,Value b) { return less(a,b)||less(b,a); }
00178 bool positive(Value a) { return _epsilon<a; }
00180 bool negative(Value a) { return -_epsilon>a; }
00182 Value nonZero(Value a) { return positive(a)||negative(a); };
00183
00185
00187 static Value zero() {return 0;}
00188 };
00189
00191
00195 template<>
00196 class Tolerance<long double>
00197 {
00198 static long double def_epsilon;
00199 long double _epsilon;
00200 public:
00202 typedef long double Value;
00203
00205 Tolerance() : _epsilon(def_epsilon) {}
00207 Tolerance(long double e) : _epsilon(e) {}
00208
00210 Value epsilon() {return _epsilon;}
00212 void epsilon(Value e) {_epsilon=e;}
00213
00215 static Value defaultEpsilon() {return def_epsilon;}
00217 static void defaultEpsilon(Value e) {def_epsilon=e;}
00218
00221
00223
00225 bool less(Value a,Value b) {return a+_epsilon<b;}
00227 bool different(Value a,Value b) { return less(a,b)||less(b,a); }
00229 bool positive(Value a) { return _epsilon<a; }
00231 bool negative(Value a) { return -_epsilon>a; }
00233 Value nonZero(Value a) { return positive(a)||negative(a); };
00234
00236
00238 static Value zero() {return 0;}
00239 };
00240
00242
00245 template<>
00246 class Tolerance<int>
00247 {
00248 public:
00250 typedef int Value;
00251
00254
00256
00258 static bool less(Value a,Value b) { return a<b;}
00260 static bool different(Value a,Value b) { return a!=b; }
00262 static bool positive(Value a) { return 0<a; }
00264 static bool negative(Value a) { return 0>a; }
00266 static Value nonZero(Value a) { return a!=0;};
00267
00269
00271 static Value zero() {return 0;}
00272 };
00273
00275
00278 template<>
00279 class Tolerance<long long int>
00280 {
00281 public:
00283 typedef long long int Value;
00284
00287
00289
00291 static bool less(Value a,Value b) { return a<b;}
00293 static bool different(Value a,Value b) { return a!=b; }
00295 static bool positive(Value a) { return 0<a; }
00297 static bool negative(Value a) { return 0>a; }
00299 static Value nonZero(Value a) { return a!=0;};
00300
00302
00304 static Value zero() {return 0;}
00305 };
00306
00308
00309 }
00310
00311 #endif //LEMON_TOLERANCE_H