$treeview $search $mathjax
Eigen
3.2.5
$projectbrief
|
$projectbrief
|
$searchbox |
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com> 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 static inline Real epsilon() { return std::numeric_limits<T>::epsilon(); } 00072 static inline Real dummy_precision() 00073 { 00074 // make sure to override this for floating-point types 00075 return Real(0); 00076 } 00077 static inline T highest() { return (std::numeric_limits<T>::max)(); } 00078 static inline T lowest() { return IsInteger ? (std::numeric_limits<T>::min)() : (-(std::numeric_limits<T>::max)()); } 00079 00080 #ifdef EIGEN2_SUPPORT 00081 enum { 00082 HasFloatingPoint = !IsInteger 00083 }; 00084 typedef NonInteger FloatingPoint; 00085 #endif 00086 }; 00087 00088 template<typename T> struct NumTraits : GenericNumTraits<T> 00089 {}; 00090 00091 template<> struct NumTraits<float> 00092 : GenericNumTraits<float> 00093 { 00094 static inline float dummy_precision() { return 1e-5f; } 00095 }; 00096 00097 template<> struct NumTraits<double> : GenericNumTraits<double> 00098 { 00099 static inline double dummy_precision() { return 1e-12; } 00100 }; 00101 00102 template<> struct NumTraits<long double> 00103 : GenericNumTraits<long double> 00104 { 00105 static inline long double dummy_precision() { return 1e-15l; } 00106 }; 00107 00108 template<typename _Real> struct NumTraits<std::complex<_Real> > 00109 : GenericNumTraits<std::complex<_Real> > 00110 { 00111 typedef _Real Real; 00112 enum { 00113 IsComplex = 1, 00114 RequireInitialization = NumTraits<_Real>::RequireInitialization, 00115 ReadCost = 2 * NumTraits<_Real>::ReadCost, 00116 AddCost = 2 * NumTraits<Real>::AddCost, 00117 MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost 00118 }; 00119 00120 static inline Real epsilon() { return NumTraits<Real>::epsilon(); } 00121 static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); } 00122 }; 00123 00124 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols> 00125 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > 00126 { 00127 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType; 00128 typedef typename NumTraits<Scalar>::Real RealScalar; 00129 typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real; 00130 typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar; 00131 typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger; 00132 typedef ArrayType & Nested; 00133 00134 enum { 00135 IsComplex = NumTraits<Scalar>::IsComplex, 00136 IsInteger = NumTraits<Scalar>::IsInteger, 00137 IsSigned = NumTraits<Scalar>::IsSigned, 00138 RequireInitialization = 1, 00139 ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost, 00140 AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost, 00141 MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost 00142 }; 00143 00144 static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); } 00145 static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); } 00146 }; 00147 00148 } // end namespace Eigen 00149 00150 #endif // EIGEN_NUMTRAITS_H