00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_NUMTRAITS_H
00026 #define EIGEN_NUMTRAITS_H
00027
00028 namespace Eigen {
00029
00066 template<typename T> struct GenericNumTraits
00067 {
00068 enum {
00069 IsInteger = std::numeric_limits<T>::is_integer,
00070 IsSigned = std::numeric_limits<T>::is_signed,
00071 IsComplex = 0,
00072 RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
00073 ReadCost = 1,
00074 AddCost = 1,
00075 MulCost = 1
00076 };
00077
00078 typedef T Real;
00079 typedef typename internal::conditional<
00080 IsInteger,
00081 typename internal::conditional<sizeof(T)<=2, float, double>::type,
00082 T
00083 >::type NonInteger;
00084 typedef T Nested;
00085
00086 static inline Real epsilon() { return std::numeric_limits<T>::epsilon(); }
00087 static inline Real dummy_precision()
00088 {
00089
00090 return Real(0);
00091 }
00092 static inline T highest() { return (std::numeric_limits<T>::max)(); }
00093 static inline T lowest() { return IsInteger ? (std::numeric_limits<T>::min)() : (-(std::numeric_limits<T>::max)()); }
00094
00095 #ifdef EIGEN2_SUPPORT
00096 enum {
00097 HasFloatingPoint = !IsInteger
00098 };
00099 typedef NonInteger FloatingPoint;
00100 #endif
00101 };
00102
00103 template<typename T> struct NumTraits : GenericNumTraits<T>
00104 {};
00105
00106 template<> struct NumTraits<float>
00107 : GenericNumTraits<float>
00108 {
00109 static inline float dummy_precision() { return 1e-5f; }
00110 };
00111
00112 template<> struct NumTraits<double> : GenericNumTraits<double>
00113 {
00114 static inline double dummy_precision() { return 1e-12; }
00115 };
00116
00117 template<> struct NumTraits<long double>
00118 : GenericNumTraits<long double>
00119 {
00120 static inline long double dummy_precision() { return 1e-15l; }
00121 };
00122
00123 template<typename _Real> struct NumTraits<std::complex<_Real> >
00124 : GenericNumTraits<std::complex<_Real> >
00125 {
00126 typedef _Real Real;
00127 enum {
00128 IsComplex = 1,
00129 RequireInitialization = NumTraits<_Real>::RequireInitialization,
00130 ReadCost = 2 * NumTraits<_Real>::ReadCost,
00131 AddCost = 2 * NumTraits<Real>::AddCost,
00132 MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
00133 };
00134
00135 static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
00136 static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
00137 };
00138
00139 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00140 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
00141 {
00142 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
00143 typedef typename NumTraits<Scalar>::Real RealScalar;
00144 typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real;
00145 typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
00146 typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger;
00147 typedef ArrayType & Nested;
00148
00149 enum {
00150 IsComplex = NumTraits<Scalar>::IsComplex,
00151 IsInteger = NumTraits<Scalar>::IsInteger,
00152 IsSigned = NumTraits<Scalar>::IsSigned,
00153 RequireInitialization = 1,
00154 ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
00155 AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
00156 MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
00157 };
00158 };
00159
00160 }
00161
00162 #endif // EIGEN_NUMTRAITS_H