tolerance.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  *
00003  * This file is a part of LEMON, a generic C++ optimization library
00004  *
00005  * Copyright (C) 2003-2006
00006  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00007  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00008  *
00009  * Permission to use, modify and distribute this software is granted
00010  * provided that this copyright notice appears in all copies. For
00011  * precise terms see the accompanying LICENSE file.
00012  *
00013  * This software is provided "AS IS" with no warranty of any kind,
00014  * express or implied, and with no claim as to its suitability for any
00015  * purpose.
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     //   static bool finite(Value a) {}
00083     //   static Value big() {}
00084     //   static Value negativeBig() {}
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 } //namespace lemon
00310 
00311 #endif //LEMON_TOLERANCE_H

Generated on Fri Feb 3 18:39:50 2006 for LEMON by  doxygen 1.4.6