2007-10-12 13:15:25 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-23 02:25:33 +08:00
|
|
|
// for linear algebra.
|
2007-10-07 20:44:42 +08:00
|
|
|
//
|
2008-11-24 21:40:43 +08:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2007-10-07 20:44:42 +08:00
|
|
|
//
|
2008-02-28 23:44:45 +08:00
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
2008-04-04 02:13:27 +08:00
|
|
|
// License as published by the Free Software Foundation; either
|
2008-02-28 23:44:45 +08:00
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2008-04-04 02:13:27 +08:00
|
|
|
// published by the Free Software Foundation; either version 2 of
|
2008-02-28 23:44:45 +08:00
|
|
|
// the License, or (at your option) any later version.
|
2007-10-07 20:44:42 +08:00
|
|
|
//
|
2007-10-12 13:15:25 +08:00
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
2007-10-07 20:44:42 +08:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 23:44:45 +08:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
2007-10-07 20:44:42 +08:00
|
|
|
//
|
2008-04-04 02:13:27 +08:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
2008-02-28 23:44:45 +08:00
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-07 20:44:42 +08:00
|
|
|
|
2007-12-03 02:32:59 +08:00
|
|
|
#ifndef EIGEN_NUMTRAITS_H
|
|
|
|
|
#define EIGEN_NUMTRAITS_H
|
2007-10-07 20:44:42 +08:00
|
|
|
|
2008-01-07 17:34:21 +08:00
|
|
|
/** \class NumTraits
|
|
|
|
|
*
|
|
|
|
|
* \brief Holds some data about the various numeric (i.e. scalar) types allowed by Eigen.
|
|
|
|
|
*
|
|
|
|
|
* \param T the numeric type about which this class provides data. Recall that Eigen allows
|
|
|
|
|
* only the following types for \a T: \c int, \c float, \c double,
|
2008-09-14 19:59:10 +08:00
|
|
|
* \c std::complex<float>, \c std::complex<double>, and \c long \c double (especially
|
|
|
|
|
* useful to enforce x87 arithmetics when SSE is the default).
|
2008-01-07 17:34:21 +08:00
|
|
|
*
|
2010-02-10 18:11:21 +08:00
|
|
|
* The provided data consists of everything that is supported by std::numeric_limits, plus:
|
2008-01-07 17:34:21 +08:00
|
|
|
* \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.
|
|
|
|
|
* \li A typedef \a FloatingPoint, giving the "floating-point type" of \a T. If \a T is
|
|
|
|
|
* \c int, then \a FloatingPoint is a typedef to \c double. Otherwise, \a FloatingPoint
|
|
|
|
|
* is a typedef to \a T.
|
2008-01-11 04:45:35 +08:00
|
|
|
* \li An enum value \a IsComplex. It is equal to 1 if \a T is a \c std::complex
|
|
|
|
|
* 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.
|
2010-02-10 18:11:21 +08:00
|
|
|
* \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.
|
2010-02-11 18:31:22 +08:00
|
|
|
* \li Two highest() and lowest() functions returning the highest and lowest possible values respectively.
|
2008-01-07 17:34:21 +08:00
|
|
|
*/
|
2007-10-12 04:14:01 +08:00
|
|
|
template<typename T> struct NumTraits;
|
2007-10-07 20:44:42 +08:00
|
|
|
|
2010-02-10 18:11:21 +08:00
|
|
|
template<typename T> struct ei_default_float_numtraits
|
|
|
|
|
: std::numeric_limits<T>
|
|
|
|
|
{
|
2010-02-10 18:40:55 +08:00
|
|
|
inline static T highest() { return std::numeric_limits<T>::max(); }
|
|
|
|
|
inline static T lowest() { return -std::numeric_limits<T>::max(); }
|
2010-02-10 18:11:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T> struct ei_default_integral_numtraits
|
|
|
|
|
: std::numeric_limits<T>
|
|
|
|
|
{
|
2010-02-11 18:39:02 +08:00
|
|
|
inline static T dummy_precision() { return T(0); }
|
2010-02-10 18:11:21 +08:00
|
|
|
inline static T highest() { return std::numeric_limits<T>::max(); }
|
|
|
|
|
inline static T lowest() { return std::numeric_limits<T>::min(); }
|
|
|
|
|
};
|
|
|
|
|
|
2007-10-12 04:14:01 +08:00
|
|
|
template<> struct NumTraits<int>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_integral_numtraits<int>
|
2007-10-07 20:44:42 +08:00
|
|
|
{
|
|
|
|
|
typedef int Real;
|
2007-12-26 17:25:00 +08:00
|
|
|
typedef double FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef int Nested;
|
2008-01-11 04:45:35 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = 0,
|
|
|
|
|
ReadCost = 1,
|
|
|
|
|
AddCost = 1,
|
2008-04-10 18:33:50 +08:00
|
|
|
MulCost = 1
|
2008-01-11 04:45:35 +08:00
|
|
|
};
|
2007-10-07 20:44:42 +08:00
|
|
|
};
|
|
|
|
|
|
2007-10-12 04:14:01 +08:00
|
|
|
template<> struct NumTraits<float>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_float_numtraits<float>
|
2007-10-07 20:44:42 +08:00
|
|
|
{
|
|
|
|
|
typedef float Real;
|
2007-12-26 17:25:00 +08:00
|
|
|
typedef float FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef float Nested;
|
2008-01-11 04:45:35 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = 1,
|
|
|
|
|
ReadCost = 1,
|
2008-04-05 19:10:54 +08:00
|
|
|
AddCost = 1,
|
2009-07-16 20:20:36 +08:00
|
|
|
MulCost = 1
|
2008-01-11 04:45:35 +08:00
|
|
|
};
|
2010-02-10 17:52:28 +08:00
|
|
|
|
|
|
|
|
inline static float dummy_precision() { return 1e-5f; }
|
2007-10-07 20:44:42 +08:00
|
|
|
};
|
|
|
|
|
|
2007-10-12 04:14:01 +08:00
|
|
|
template<> struct NumTraits<double>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_float_numtraits<double>
|
2007-10-07 20:44:42 +08:00
|
|
|
{
|
|
|
|
|
typedef double Real;
|
2007-12-26 17:25:00 +08:00
|
|
|
typedef double FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef double Nested;
|
2008-01-11 04:45:35 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = 1,
|
|
|
|
|
ReadCost = 1,
|
2008-04-05 19:10:54 +08:00
|
|
|
AddCost = 1,
|
2009-07-16 20:20:36 +08:00
|
|
|
MulCost = 1
|
2008-01-11 04:45:35 +08:00
|
|
|
};
|
2010-02-10 17:52:28 +08:00
|
|
|
|
|
|
|
|
inline static double dummy_precision() { return 1e-12; }
|
2007-10-07 20:44:42 +08:00
|
|
|
};
|
|
|
|
|
|
2007-10-12 04:14:01 +08:00
|
|
|
template<typename _Real> struct NumTraits<std::complex<_Real> >
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_float_numtraits<std::complex<_Real> >
|
2007-10-07 20:44:42 +08:00
|
|
|
{
|
|
|
|
|
typedef _Real Real;
|
2007-12-26 17:25:00 +08:00
|
|
|
typedef std::complex<_Real> FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef std::complex<_Real> Nested;
|
2008-01-11 04:45:35 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 1,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = NumTraits<Real>::HasFloatingPoint,
|
|
|
|
|
ReadCost = 2,
|
|
|
|
|
AddCost = 2 * NumTraits<Real>::AddCost,
|
2008-04-10 18:33:50 +08:00
|
|
|
MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
|
2008-01-11 04:45:35 +08:00
|
|
|
};
|
2010-02-10 17:52:28 +08:00
|
|
|
|
|
|
|
|
inline static Real epsilon() { return std::numeric_limits<Real>::epsilon(); }
|
|
|
|
|
inline static Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
|
2007-10-07 20:44:42 +08:00
|
|
|
};
|
|
|
|
|
|
2008-02-29 21:20:44 +08:00
|
|
|
template<> struct NumTraits<long long int>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_integral_numtraits<long long int>
|
2008-02-29 21:20:44 +08:00
|
|
|
{
|
|
|
|
|
typedef long long int Real;
|
|
|
|
|
typedef long double FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef long long int Nested;
|
2008-02-29 21:20:44 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = 0,
|
|
|
|
|
ReadCost = 1,
|
2008-04-05 19:10:54 +08:00
|
|
|
AddCost = 1,
|
2008-04-10 18:33:50 +08:00
|
|
|
MulCost = 1
|
2008-02-29 21:20:44 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<> struct NumTraits<long double>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_float_numtraits<long double>
|
2008-02-29 21:20:44 +08:00
|
|
|
{
|
|
|
|
|
typedef long double Real;
|
|
|
|
|
typedef long double FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef long double Nested;
|
2008-02-29 21:20:44 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
2008-04-03 19:10:17 +08:00
|
|
|
HasFloatingPoint = 1,
|
|
|
|
|
ReadCost = 1,
|
2008-09-14 19:59:10 +08:00
|
|
|
AddCost = 1,
|
|
|
|
|
MulCost = 1
|
2008-02-29 21:20:44 +08:00
|
|
|
};
|
2010-02-10 17:52:28 +08:00
|
|
|
|
|
|
|
|
static inline long double dummy_precision() { return NumTraits<double>::dummy_precision(); }
|
2008-02-29 21:20:44 +08:00
|
|
|
};
|
|
|
|
|
|
2008-04-04 02:13:27 +08:00
|
|
|
template<> struct NumTraits<bool>
|
2010-02-10 18:11:21 +08:00
|
|
|
: ei_default_integral_numtraits<bool>
|
2008-04-04 02:13:27 +08:00
|
|
|
{
|
|
|
|
|
typedef bool Real;
|
|
|
|
|
typedef float FloatingPoint;
|
2009-11-06 18:23:18 +08:00
|
|
|
typedef bool Nested;
|
2008-04-04 02:13:27 +08:00
|
|
|
enum {
|
|
|
|
|
IsComplex = 0,
|
|
|
|
|
HasFloatingPoint = 0,
|
|
|
|
|
ReadCost = 1,
|
|
|
|
|
AddCost = 1,
|
2008-04-10 18:33:50 +08:00
|
|
|
MulCost = 1
|
2008-04-04 02:13:27 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2007-12-03 02:32:59 +08:00
|
|
|
#endif // EIGEN_NUMTRAITS_H
|