MOAB  4.9.3pre
NumTraits.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2006-2010 Benoit Jacob <[email protected]>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_NUMTRAITS_H
00011 #define EIGEN_NUMTRAITS_H
00012 
00013 namespace Eigen {
00014 
00051 template<typename T> struct GenericNumTraits
00052 {
00053   enum {
00054     IsInteger = std::numeric_limits<T>::is_integer,
00055     IsSigned = std::numeric_limits<T>::is_signed,
00056     IsComplex = 0,
00057     RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
00058     ReadCost = 1,
00059     AddCost = 1,
00060     MulCost = 1
00061   };
00062 
00063   typedef T Real;
00064   typedef typename internal::conditional<
00065                      IsInteger,
00066                      typename internal::conditional<sizeof(T)<=2, float, double>::type,
00067                      T
00068                    >::type NonInteger;
00069   typedef T Nested;
00070 
00071   EIGEN_DEVICE_FUNC
00072   static inline Real epsilon()
00073   {
00074     return numext::numeric_limits<T>::epsilon();
00075   }
00076   EIGEN_DEVICE_FUNC
00077   static inline Real dummy_precision()
00078   {
00079     // make sure to override this for floating-point types
00080     return Real(0);
00081   }
00082 
00083 
00084   EIGEN_DEVICE_FUNC
00085   static inline T highest() {
00086     return (numext::numeric_limits<T>::max)();
00087   }
00088 
00089   EIGEN_DEVICE_FUNC
00090   static inline T lowest()  {
00091     return IsInteger ? (numext::numeric_limits<T>::min)() : (-(numext::numeric_limits<T>::max)());
00092   }
00093 
00094   EIGEN_DEVICE_FUNC
00095   static inline T infinity() {
00096     return numext::numeric_limits<T>::infinity();
00097   }
00098 };
00099 
00100 template<typename T> struct NumTraits : GenericNumTraits<T>
00101 {};
00102 
00103 template<> struct NumTraits<float>
00104   : GenericNumTraits<float>
00105 {
00106   EIGEN_DEVICE_FUNC
00107   static inline float dummy_precision() { return 1e-5f; }
00108 };
00109 
00110 template<> struct NumTraits<double> : GenericNumTraits<double>
00111 {
00112   EIGEN_DEVICE_FUNC
00113   static inline double dummy_precision() { return 1e-12; }
00114 };
00115 
00116 template<> struct NumTraits<long double>
00117   : GenericNumTraits<long double>
00118 {
00119   static inline long double dummy_precision() { return 1e-15l; }
00120 };
00121 
00122 template<typename _Real> struct NumTraits<std::complex<_Real> >
00123   : GenericNumTraits<std::complex<_Real> >
00124 {
00125   typedef _Real Real;
00126   enum {
00127     IsComplex = 1,
00128     RequireInitialization = NumTraits<_Real>::RequireInitialization,
00129     ReadCost = 2 * NumTraits<_Real>::ReadCost,
00130     AddCost = 2 * NumTraits<Real>::AddCost,
00131     MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
00132   };
00133 
00134   static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
00135   static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
00136 };
00137 
00138 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00139 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
00140 {
00141   typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
00142   typedef typename NumTraits<Scalar>::Real RealScalar;
00143   typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real;
00144   typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
00145   typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger;
00146   typedef ArrayType & Nested;
00147   
00148   enum {
00149     IsComplex = NumTraits<Scalar>::IsComplex,
00150     IsInteger = NumTraits<Scalar>::IsInteger,
00151     IsSigned  = NumTraits<Scalar>::IsSigned,
00152     RequireInitialization = 1,
00153     ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
00154     AddCost  = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
00155     MulCost  = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
00156   };
00157   
00158   static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
00159   static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); }
00160 };
00161 
00162 } // end namespace Eigen
00163 
00164 #endif // EIGEN_NUMTRAITS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines