[Lemon-commits] Alpar Juttner: Default implementation of Toleran...
Lemon HG
hg at lemon.cs.elte.hu
Fri Feb 20 23:02:43 CET 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/7d7d9debb29a
changeset: 527:7d7d9debb29a
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Fri Feb 20 18:06:10 2009 +0000
description:
Default implementation of Tolerance<> is used for integer types
(#229)
diffstat:
1 file changed, 9 insertions(+), 219 deletions(-)
lemon/tolerance.h | 228 ++---------------------------------------------------
diffs (265 lines):
diff --git a/lemon/tolerance.h b/lemon/tolerance.h
--- a/lemon/tolerance.h
+++ b/lemon/tolerance.h
@@ -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<double> may offer additional tuning parameters.
///
///\sa Tolerance<float>
///\sa Tolerance<double>
///\sa Tolerance<long double>
- ///\sa Tolerance<int>
- ///\sa Tolerance<long long int>
- ///\sa Tolerance<unsigned int>
- ///\sa Tolerance<unsigned long long int>
template<class T>
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<b;}
///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) {return false;}
+ static bool different(Value a,Value b) {return a!=b;}
///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) {return false;}
+ static bool positive(Value a) {return static_cast<Value>(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<Value>(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<Value>(0);}
///@}
///Returns the zero value.
- static Value zero() {return T();}
+ static Value zero() {return static_cast<Value>(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<int>
- {
- 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 a<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value a) { return 0>a; }
- ///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<unsigned int>
- {
- 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<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value) { return false; }
- ///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;}
- };
-
-
- ///Long integer specialization of Tolerance.
-
- ///Long integer specialization of Tolerance.
- ///\sa Tolerance
- template<>
- class Tolerance<long int>
- {
- 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 a<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value a) { return 0>a; }
- ///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<unsigned long int>
- {
- 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 a<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value) { return false; }
- ///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;}
- };
-
-#if HAVE_LONG_LONG
-
- ///Long long integer specialization of Tolerance.
-
- ///Long long integer specialization of Tolerance.
- ///\warning This class (more exactly, type <tt>long long</tt>)
- ///is not ansi compatible.
- ///\sa Tolerance
- template<>
- class Tolerance<long long int>
- {
- 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 a<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value a) { return 0>a; }
- ///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 <tt>unsigned long long</tt>)
- ///is not ansi compatible.
- ///\sa Tolerance
- template<>
- class Tolerance<unsigned long long int>
- {
- 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<b;}
- ///Returns \c true if \c a is \e surely different from \c b
- static bool different(Value a,Value b) { return a!=b; }
- ///Returns \c true if \c a is \e surely positive
- static bool positive(Value a) { return 0<a; }
- ///Returns \c true if \c a is \e surely negative
- static bool negative(Value) { return false; }
- ///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;}
- };
-
-#endif
-
/// @}
} //namespace lemon
More information about the Lemon-commits
mailing list