aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-02-10 11:11:21 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-02-10 11:11:21 +0100
commitbb290977b8e4ec43dbd1f628e357d762da0e33d5 (patch)
tree85f3ba49ad57df83145646dbc16349ccd54e1d58
parentfe0827495ab34749b8896bbebc0ff9fcc661c13b (diff)
add highest and lowest functions to NumTraits
-rw-r--r--Eigen/src/Core/NumTraits.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h
index 7279e156d..f4036dc0c 100644
--- a/Eigen/src/Core/NumTraits.h
+++ b/Eigen/src/Core/NumTraits.h
@@ -34,7 +34,7 @@
* \c std::complex<float>, \c std::complex<double>, and \c long \c double (especially
* useful to enforce x87 arithmetics when SSE is the default).
*
- * The provided data consists of:
+ * The provided data consists of everything that is supported by std::numeric_limits, plus:
* \li A typedef \a Real, giving the "real part" type of \a T. If \a T is already real,
* then \a Real is just a typedef to \a T. If \a T is \c std::complex<U> then \a Real
* is a typedef to \a U.
@@ -45,11 +45,29 @@
* type, and to 0 otherwise.
* \li An enum \a HasFloatingPoint. It is equal to \c 0 if \a T is \c int,
* and to \c 1 otherwise.
+ * \li An epsilon() function which, unlike std::numeric_limits::epsilon(), returns a \a Real instead of a \a T.
+ * \li A dummy_precision() function returning a weak epsilon value. It is mainly used by the fuzzy comparison operators.
+ * \li Two higest() and lowest() functions returning the higest and lowest possible values respectively.
*/
template<typename T> struct NumTraits;
+template<typename T> struct ei_default_float_numtraits
+ : std::numeric_limits<T>
+{
+ inline static T higest() { return std::numeric_limits<T>::max(); }
+ inline static T lowest() { return -std::numeric_limits<T>::max(); }
+};
+
+template<typename T> struct ei_default_integral_numtraits
+ : std::numeric_limits<T>
+{
+ inline static int dummy_precision() { return 0; }
+ inline static T highest() { return std::numeric_limits<T>::max(); }
+ inline static T lowest() { return std::numeric_limits<T>::min(); }
+};
+
template<> struct NumTraits<int>
- : std::numeric_limits<int>
+ : ei_default_integral_numtraits<int>
{
typedef int Real;
typedef double FloatingPoint;
@@ -61,12 +79,10 @@ template<> struct NumTraits<int>
AddCost = 1,
MulCost = 1
};
-
- inline static int dummy_precision() { return 0; }
};
template<> struct NumTraits<float>
- : std::numeric_limits<float>
+ : ei_default_float_numtraits<float>
{
typedef float Real;
typedef float FloatingPoint;
@@ -83,7 +99,7 @@ template<> struct NumTraits<float>
};
template<> struct NumTraits<double>
- : std::numeric_limits<double>
+ : ei_default_float_numtraits<double>
{
typedef double Real;
typedef double FloatingPoint;
@@ -100,7 +116,7 @@ template<> struct NumTraits<double>
};
template<typename _Real> struct NumTraits<std::complex<_Real> >
- : std::numeric_limits<std::complex<_Real> >
+ : ei_default_float_numtraits<std::complex<_Real> >
{
typedef _Real Real;
typedef std::complex<_Real> FloatingPoint;
@@ -118,7 +134,7 @@ template<typename _Real> struct NumTraits<std::complex<_Real> >
};
template<> struct NumTraits<long long int>
- : std::numeric_limits<long long int>
+ : ei_default_integral_numtraits<long long int>
{
typedef long long int Real;
typedef long double FloatingPoint;
@@ -133,7 +149,7 @@ template<> struct NumTraits<long long int>
};
template<> struct NumTraits<long double>
- : std::numeric_limits<long double>
+ : ei_default_float_numtraits<long double>
{
typedef long double Real;
typedef long double FloatingPoint;
@@ -150,7 +166,7 @@ template<> struct NumTraits<long double>
};
template<> struct NumTraits<bool>
- : std::numeric_limits<bool>
+ : ei_default_integral_numtraits<bool>
{
typedef bool Real;
typedef float FloatingPoint;
@@ -162,8 +178,6 @@ template<> struct NumTraits<bool>
AddCost = 1,
MulCost = 1
};
-
- inline static bool dummy_precision() { return 0; }
};
#endif // EIGEN_NUMTRAITS_H