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