Tolerance<long double> added
authoralpar
Wed, 18 Jan 2006 09:40:53 +0000
changeset 1897dd90f57b01d1
parent 1896 92ef660710f1
child 1898 f030c01e6173
Tolerance<long double> added
lemon/base.cc
lemon/tolerance.h
     1.1 --- a/lemon/base.cc	Sat Jan 14 13:42:37 2006 +0000
     1.2 +++ b/lemon/base.cc	Wed Jan 18 09:40:53 2006 +0000
     1.3 @@ -21,8 +21,9 @@
     1.4  #include<lemon/invalid.h>
     1.5  namespace lemon {
     1.6  
     1.7 +  float Tolerance<float>::def_epsilon = 1e-4;
     1.8    double Tolerance<double>::def_epsilon = 1e-10;
     1.9 -  float Tolerance<float>::def_epsilon = 1e-4;
    1.10 +  long double Tolerance<long double>::def_epsilon = 1e-14;
    1.11  
    1.12  #ifndef LEMON_ONLY_TEMPLATES
    1.13    const Invalid INVALID = Invalid();
     2.1 --- a/lemon/tolerance.h	Sat Jan 14 13:42:37 2006 +0000
     2.2 +++ b/lemon/tolerance.h	Wed Jan 18 09:40:53 2006 +0000
     2.3 @@ -44,6 +44,7 @@
     2.4    ///
     2.5    ///\sa Tolerance<float>
     2.6    ///\sa Tolerance<double>
     2.7 +  ///\sa Tolerance<long double>
     2.8    ///\sa Tolerance<int>
     2.9    ///\sa Tolerance<long long int>
    2.10  
    2.11 @@ -82,6 +83,57 @@
    2.12    };
    2.13  
    2.14  
    2.15 +  ///Float specialization of \ref Tolerance.
    2.16 +
    2.17 +  ///Float specialization of \ref Tolerance.
    2.18 +  ///\sa Tolerance
    2.19 +  ///\relates Tolerance
    2.20 +  template<>
    2.21 +  class Tolerance<float>
    2.22 +  {
    2.23 +    static float def_epsilon;
    2.24 +    float _epsilon;
    2.25 +  public:
    2.26 +    ///\e
    2.27 +    typedef float Value;
    2.28 +
    2.29 +    ///Constructor setting the epsilon tolerance to the default value.
    2.30 +    Tolerance() : _epsilon(def_epsilon) {}
    2.31 +    ///Constructor setting the epsilon tolerance.
    2.32 +    Tolerance(float e) : _epsilon(e) {}
    2.33 +
    2.34 +    ///Return the epsilon value.
    2.35 +    Value epsilon() {return _epsilon;}
    2.36 +    ///Set the epsilon value.
    2.37 +    void epsilon(Value e) {_epsilon=e;}
    2.38 +
    2.39 +    ///Return the default epsilon value.
    2.40 +    static Value defaultEpsilon() {return def_epsilon;}
    2.41 +    ///Set the default epsilon value.
    2.42 +    static void defaultEpsilon(Value e) {def_epsilon=e;}
    2.43 +
    2.44 +    ///\name Comparisons
    2.45 +    ///See class Tolerance for more details.
    2.46 +
    2.47 +    ///@{
    2.48 +
    2.49 +    ///Returns \c true if \c a is \e surely strictly less than \c b
    2.50 +    bool less(Value a,Value b) {return a+_epsilon<b;}
    2.51 +    ///Returns \c true if \c a is \e surely different from \c b
    2.52 +    bool different(Value a,Value b) { return less(a,b)||less(b,a); }
    2.53 +    ///Returns \c true if \c a is \e surely positive
    2.54 +    bool positive(Value a) { return _epsilon<a; }
    2.55 +    ///Returns \c true if \c a is \e surely negative
    2.56 +    bool negative(Value a) { return -_epsilon>a; }
    2.57 +    ///Returns \c true if \c a is \e surely non-zero
    2.58 +    Value nonZero(Value a) { return positive(a)||negative(a); };
    2.59 +
    2.60 +    ///@}
    2.61 +
    2.62 +    ///Returns zero
    2.63 +    static Value zero() {return 0;}
    2.64 +  };
    2.65 +
    2.66    ///Double specialization of \ref Tolerance.
    2.67  
    2.68    ///Double specialization of \ref Tolerance.
    2.69 @@ -133,24 +185,24 @@
    2.70      static Value zero() {return 0;}
    2.71    };
    2.72  
    2.73 -  ///Float specialization of \ref Tolerance.
    2.74 +  ///Long double specialization of \ref Tolerance.
    2.75  
    2.76 -  ///Float specialization of \ref Tolerance.
    2.77 +  ///Long double specialization of \ref Tolerance.
    2.78    ///\sa Tolerance
    2.79    ///\relates Tolerance
    2.80    template<>
    2.81 -  class Tolerance<float>
    2.82 +  class Tolerance<long double>
    2.83    {
    2.84 -    static float def_epsilon;
    2.85 -    float _epsilon;
    2.86 +    static long double def_epsilon;
    2.87 +    long double _epsilon;
    2.88    public:
    2.89      ///\e
    2.90 -    typedef float Value;
    2.91 +    typedef long double Value;
    2.92  
    2.93      ///Constructor setting the epsilon tolerance to the default value.
    2.94      Tolerance() : _epsilon(def_epsilon) {}
    2.95      ///Constructor setting the epsilon tolerance.
    2.96 -    Tolerance(float e) : _epsilon(e) {}
    2.97 +    Tolerance(long double e) : _epsilon(e) {}
    2.98  
    2.99      ///Return the epsilon value.
   2.100      Value epsilon() {return _epsilon;}