From bb290977b8e4ec43dbd1f628e357d762da0e33d5 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Feb 2010 11:11:21 +0100 Subject: [PATCH] add highest and lowest functions to NumTraits --- Eigen/src/Core/NumTraits.h | 38 ++++++++++++++++++++++++++------------ 1 file 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, \c std::complex, 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 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 struct NumTraits; +template struct ei_default_float_numtraits + : std::numeric_limits +{ + inline static T higest() { return std::numeric_limits::max(); } + inline static T lowest() { return -std::numeric_limits::max(); } +}; + +template struct ei_default_integral_numtraits + : std::numeric_limits +{ + inline static int dummy_precision() { return 0; } + inline static T highest() { return std::numeric_limits::max(); } + inline static T lowest() { return std::numeric_limits::min(); } +}; + template<> struct NumTraits - : std::numeric_limits + : ei_default_integral_numtraits { typedef int Real; typedef double FloatingPoint; @@ -61,12 +79,10 @@ template<> struct NumTraits AddCost = 1, MulCost = 1 }; - - inline static int dummy_precision() { return 0; } }; template<> struct NumTraits - : std::numeric_limits + : ei_default_float_numtraits { typedef float Real; typedef float FloatingPoint; @@ -83,7 +99,7 @@ template<> struct NumTraits }; template<> struct NumTraits - : std::numeric_limits + : ei_default_float_numtraits { typedef double Real; typedef double FloatingPoint; @@ -100,7 +116,7 @@ template<> struct NumTraits }; template struct NumTraits > - : std::numeric_limits > + : ei_default_float_numtraits > { typedef _Real Real; typedef std::complex<_Real> FloatingPoint; @@ -118,7 +134,7 @@ template struct NumTraits > }; template<> struct NumTraits - : std::numeric_limits + : ei_default_integral_numtraits { typedef long long int Real; typedef long double FloatingPoint; @@ -133,7 +149,7 @@ template<> struct NumTraits }; template<> struct NumTraits - : std::numeric_limits + : ei_default_float_numtraits { typedef long double Real; typedef long double FloatingPoint; @@ -150,7 +166,7 @@ template<> struct NumTraits }; template<> struct NumTraits - : std::numeric_limits + : ei_default_integral_numtraits { typedef bool Real; typedef float FloatingPoint; @@ -162,8 +178,6 @@ template<> struct NumTraits AddCost = 1, MulCost = 1 }; - - inline static bool dummy_precision() { return 0; } }; #endif // EIGEN_NUMTRAITS_H