Default implementation of Tolerance<> is used for integer types (#229)
authorAlpar Juttner <alpar@cs.elte.hu>
Fri, 20 Feb 2009 18:06:10 +0000
changeset 4977d7d9debb29a
parent 496 7992dcb0d0e6
child 499 b1ef32ab39f3
Default implementation of Tolerance<> is used for integer types (#229)
lemon/tolerance.h
     1.1 --- a/lemon/tolerance.h	Fri Feb 20 18:06:10 2009 +0000
     1.2 +++ b/lemon/tolerance.h	Fri Feb 20 18:06:10 2009 +0000
     1.3 @@ -38,17 +38,14 @@
     1.4    ///handle the comparison of numbers that are obtained
     1.5    ///as a result of a probably inexact computation.
     1.6    ///
     1.7 -  ///This is an abstract class, it should be specialized for all
     1.8 -  ///numerical data types. These specialized classes like
     1.9 +  ///The general implementation is suitable only if the data type is exact,
    1.10 +  ///like the integer types, otherwise a specialized version must be
    1.11 +  ///implemented. These specialized classes like
    1.12    ///Tolerance<double> may offer additional tuning parameters.
    1.13    ///
    1.14    ///\sa Tolerance<float>
    1.15    ///\sa Tolerance<double>
    1.16    ///\sa Tolerance<long double>
    1.17 -  ///\sa Tolerance<int>
    1.18 -  ///\sa Tolerance<long long int>
    1.19 -  ///\sa Tolerance<unsigned int>
    1.20 -  ///\sa Tolerance<unsigned long long int>
    1.21  
    1.22    template<class T>
    1.23    class Tolerance
    1.24 @@ -64,20 +61,20 @@
    1.25      ///@{
    1.26  
    1.27      ///Returns \c true if \c a is \e surely strictly less than \c b
    1.28 -    static bool less(Value a,Value b) {return false;}
    1.29 +    static bool less(Value a,Value b) {return a<b;}
    1.30      ///Returns \c true if \c a is \e surely different from \c b
    1.31 -    static bool different(Value a,Value b) {return false;}
    1.32 +    static bool different(Value a,Value b) {return a!=b;}
    1.33      ///Returns \c true if \c a is \e surely positive
    1.34 -    static bool positive(Value a) {return false;}
    1.35 +    static bool positive(Value a) {return static_cast<Value>(0) < a;}
    1.36      ///Returns \c true if \c a is \e surely negative
    1.37 -    static bool negative(Value a) {return false;}
    1.38 +    static bool negative(Value a) {return a < static_cast<Value>(0);}
    1.39      ///Returns \c true if \c a is \e surely non-zero
    1.40 -    static bool nonZero(Value a) {return false;}
    1.41 +    static bool nonZero(Value a) {return a != static_cast<Value>(0);}
    1.42  
    1.43      ///@}
    1.44  
    1.45      ///Returns the zero value.
    1.46 -    static Value zero() {return T();}
    1.47 +    static Value zero() {return static_cast<Value>(0);}
    1.48  
    1.49      //   static bool finite(Value a) {}
    1.50      //   static Value big() {}
    1.51 @@ -238,213 +235,6 @@
    1.52      static Value zero() {return 0;}
    1.53    };
    1.54  
    1.55 -  ///Integer specialization of Tolerance.
    1.56 -
    1.57 -  ///Integer specialization of Tolerance.
    1.58 -  ///\sa Tolerance
    1.59 -  template<>
    1.60 -  class Tolerance<int>
    1.61 -  {
    1.62 -  public:
    1.63 -    ///\e
    1.64 -    typedef int Value;
    1.65 -
    1.66 -    ///\name Comparisons
    1.67 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
    1.68 -
    1.69 -    ///@{
    1.70 -
    1.71 -    ///Returns \c true if \c a is \e surely strictly less than \c b
    1.72 -    static bool less(Value a,Value b) { return a<b;}
    1.73 -    ///Returns \c true if \c a is \e surely different from \c b
    1.74 -    static bool different(Value a,Value b) { return a!=b; }
    1.75 -    ///Returns \c true if \c a is \e surely positive
    1.76 -    static bool positive(Value a) { return 0<a; }
    1.77 -    ///Returns \c true if \c a is \e surely negative
    1.78 -    static bool negative(Value a) { return 0>a; }
    1.79 -    ///Returns \c true if \c a is \e surely non-zero
    1.80 -    static bool nonZero(Value a) { return a!=0; }
    1.81 -
    1.82 -    ///@}
    1.83 -
    1.84 -    ///Returns zero
    1.85 -    static Value zero() {return 0;}
    1.86 -  };
    1.87 -
    1.88 -  ///Unsigned integer specialization of Tolerance.
    1.89 -
    1.90 -  ///Unsigned integer specialization of Tolerance.
    1.91 -  ///\sa Tolerance
    1.92 -  template<>
    1.93 -  class Tolerance<unsigned int>
    1.94 -  {
    1.95 -  public:
    1.96 -    ///\e
    1.97 -    typedef unsigned int Value;
    1.98 -
    1.99 -    ///\name Comparisons
   1.100 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
   1.101 -
   1.102 -    ///@{
   1.103 -
   1.104 -    ///Returns \c true if \c a is \e surely strictly less than \c b
   1.105 -    static bool less(Value a,Value b) { return a<b;}
   1.106 -    ///Returns \c true if \c a is \e surely different from \c b
   1.107 -    static bool different(Value a,Value b) { return a!=b; }
   1.108 -    ///Returns \c true if \c a is \e surely positive
   1.109 -    static bool positive(Value a) { return 0<a; }
   1.110 -    ///Returns \c true if \c a is \e surely negative
   1.111 -    static bool negative(Value) { return false; }
   1.112 -    ///Returns \c true if \c a is \e surely non-zero
   1.113 -    static bool nonZero(Value a) { return a!=0; }
   1.114 -
   1.115 -    ///@}
   1.116 -
   1.117 -    ///Returns zero
   1.118 -    static Value zero() {return 0;}
   1.119 -  };
   1.120 -
   1.121 -
   1.122 -  ///Long integer specialization of Tolerance.
   1.123 -
   1.124 -  ///Long integer specialization of Tolerance.
   1.125 -  ///\sa Tolerance
   1.126 -  template<>
   1.127 -  class Tolerance<long int>
   1.128 -  {
   1.129 -  public:
   1.130 -    ///\e
   1.131 -    typedef long int Value;
   1.132 -
   1.133 -    ///\name Comparisons
   1.134 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
   1.135 -
   1.136 -    ///@{
   1.137 -
   1.138 -    ///Returns \c true if \c a is \e surely strictly less than \c b
   1.139 -    static bool less(Value a,Value b) { return a<b;}
   1.140 -    ///Returns \c true if \c a is \e surely different from \c b
   1.141 -    static bool different(Value a,Value b) { return a!=b; }
   1.142 -    ///Returns \c true if \c a is \e surely positive
   1.143 -    static bool positive(Value a) { return 0<a; }
   1.144 -    ///Returns \c true if \c a is \e surely negative
   1.145 -    static bool negative(Value a) { return 0>a; }
   1.146 -    ///Returns \c true if \c a is \e surely non-zero
   1.147 -    static bool nonZero(Value a) { return a!=0;}
   1.148 -
   1.149 -    ///@}
   1.150 -
   1.151 -    ///Returns zero
   1.152 -    static Value zero() {return 0;}
   1.153 -  };
   1.154 -
   1.155 -  ///Unsigned long integer specialization of Tolerance.
   1.156 -
   1.157 -  ///Unsigned long integer specialization of Tolerance.
   1.158 -  ///\sa Tolerance
   1.159 -  template<>
   1.160 -  class Tolerance<unsigned long int>
   1.161 -  {
   1.162 -  public:
   1.163 -    ///\e
   1.164 -    typedef unsigned long int Value;
   1.165 -
   1.166 -    ///\name Comparisons
   1.167 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
   1.168 -
   1.169 -    ///@{
   1.170 -
   1.171 -    ///Returns \c true if \c a is \e surely strictly less than \c b
   1.172 -    static bool less(Value a,Value b) { return a<b;}
   1.173 -    ///Returns \c true if \c a is \e surely different from \c b
   1.174 -    static bool different(Value a,Value b) { return a!=b; }
   1.175 -    ///Returns \c true if \c a is \e surely positive
   1.176 -    static bool positive(Value a) { return 0<a; }
   1.177 -    ///Returns \c true if \c a is \e surely negative
   1.178 -    static bool negative(Value) { return false; }
   1.179 -    ///Returns \c true if \c a is \e surely non-zero
   1.180 -    static bool nonZero(Value a) { return a!=0;}
   1.181 -
   1.182 -    ///@}
   1.183 -
   1.184 -    ///Returns zero
   1.185 -    static Value zero() {return 0;}
   1.186 -  };
   1.187 -
   1.188 -#if HAVE_LONG_LONG 
   1.189 -
   1.190 -  ///Long long integer specialization of Tolerance.
   1.191 -
   1.192 -  ///Long long integer specialization of Tolerance.
   1.193 -  ///\warning This class (more exactly, type <tt>long long</tt>)
   1.194 -  ///is not ansi compatible.
   1.195 -  ///\sa Tolerance
   1.196 -  template<>
   1.197 -  class Tolerance<long long int>
   1.198 -  {
   1.199 -  public:
   1.200 -    ///\e
   1.201 -    typedef long long int Value;
   1.202 -
   1.203 -    ///\name Comparisons
   1.204 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
   1.205 -
   1.206 -    ///@{
   1.207 -
   1.208 -    ///Returns \c true if \c a is \e surely strictly less than \c b
   1.209 -    static bool less(Value a,Value b) { return a<b;}
   1.210 -    ///Returns \c true if \c a is \e surely different from \c b
   1.211 -    static bool different(Value a,Value b) { return a!=b; }
   1.212 -    ///Returns \c true if \c a is \e surely positive
   1.213 -    static bool positive(Value a) { return 0<a; }
   1.214 -    ///Returns \c true if \c a is \e surely negative
   1.215 -    static bool negative(Value a) { return 0>a; }
   1.216 -    ///Returns \c true if \c a is \e surely non-zero
   1.217 -    static bool nonZero(Value a) { return a!=0;}
   1.218 -
   1.219 -    ///@}
   1.220 -
   1.221 -    ///Returns zero
   1.222 -    static Value zero() {return 0;}
   1.223 -  };
   1.224 -
   1.225 -  ///Unsigned long long integer specialization of Tolerance.
   1.226 -
   1.227 -  ///Unsigned long long integer specialization of Tolerance.
   1.228 -  ///\warning This class (more exactly, type <tt>unsigned long long</tt>)
   1.229 -  ///is not ansi compatible.
   1.230 -  ///\sa Tolerance
   1.231 -  template<>
   1.232 -  class Tolerance<unsigned long long int>
   1.233 -  {
   1.234 -  public:
   1.235 -    ///\e
   1.236 -    typedef unsigned long long int Value;
   1.237 -
   1.238 -    ///\name Comparisons
   1.239 -    ///See \ref lemon::Tolerance "Tolerance" for more details.
   1.240 -
   1.241 -    ///@{
   1.242 -
   1.243 -    ///Returns \c true if \c a is \e surely strictly less than \c b
   1.244 -    static bool less(Value a,Value b) { return a<b;}
   1.245 -    ///Returns \c true if \c a is \e surely different from \c b
   1.246 -    static bool different(Value a,Value b) { return a!=b; }
   1.247 -    ///Returns \c true if \c a is \e surely positive
   1.248 -    static bool positive(Value a) { return 0<a; }
   1.249 -    ///Returns \c true if \c a is \e surely negative
   1.250 -    static bool negative(Value) { return false; }
   1.251 -    ///Returns \c true if \c a is \e surely non-zero
   1.252 -    static bool nonZero(Value a) { return a!=0;}
   1.253 -
   1.254 -    ///@}
   1.255 -
   1.256 -    ///Returns zero
   1.257 -    static Value zero() {return 0;}
   1.258 -  };
   1.259 -
   1.260 -#endif
   1.261 -
   1.262    /// @}
   1.263  
   1.264  } //namespace lemon