# HG changeset patch # User Alpar Juttner # Date 1235153170 0 # Node ID 7d7d9debb29a2e94e0e4056c5e96d54be9d64c3f # Parent 7992dcb0d0e6562056e16635b3a1b2a8908652d9 Default implementation of Tolerance<> is used for integer types (#229) diff -r 7992dcb0d0e6 -r 7d7d9debb29a lemon/tolerance.h --- a/lemon/tolerance.h Fri Feb 20 18:06:10 2009 +0000 +++ b/lemon/tolerance.h Fri Feb 20 18:06:10 2009 +0000 @@ -38,17 +38,14 @@ ///handle the comparison of numbers that are obtained ///as a result of a probably inexact computation. /// - ///This is an abstract class, it should be specialized for all - ///numerical data types. These specialized classes like + ///The general implementation is suitable only if the data type is exact, + ///like the integer types, otherwise a specialized version must be + ///implemented. These specialized classes like ///Tolerance may offer additional tuning parameters. /// ///\sa Tolerance ///\sa Tolerance ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance - ///\sa Tolerance template class Tolerance @@ -64,20 +61,20 @@ ///@{ ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) {return false;} + static bool less(Value a,Value b) {return a(0) < a;} ///Returns \c true if \c a is \e surely negative - static bool negative(Value a) {return false;} + static bool negative(Value a) {return a < static_cast(0);} ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) {return false;} + static bool nonZero(Value a) {return a != static_cast(0);} ///@} ///Returns the zero value. - static Value zero() {return T();} + static Value zero() {return static_cast(0);} // static bool finite(Value a) {} // static Value big() {} @@ -238,213 +235,6 @@ static Value zero() {return 0;} }; - ///Integer specialization of Tolerance. - - ///Integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0; } - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned integer specialization of Tolerance. - - ///Unsigned integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return a - class Tolerance - { - public: - ///\e - typedef long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0;} - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned long integer specialization of Tolerance. - - ///Unsigned long integer specialization of Tolerance. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return along long) - ///is not ansi compatible. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef long long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return aa; } - ///Returns \c true if \c a is \e surely non-zero - static bool nonZero(Value a) { return a!=0;} - - ///@} - - ///Returns zero - static Value zero() {return 0;} - }; - - ///Unsigned long long integer specialization of Tolerance. - - ///Unsigned long long integer specialization of Tolerance. - ///\warning This class (more exactly, type unsigned long long) - ///is not ansi compatible. - ///\sa Tolerance - template<> - class Tolerance - { - public: - ///\e - typedef unsigned long long int Value; - - ///\name Comparisons - ///See \ref lemon::Tolerance "Tolerance" for more details. - - ///@{ - - ///Returns \c true if \c a is \e surely strictly less than \c b - static bool less(Value a,Value b) { return a