Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template<typename T> struct GenericNumTraits
00063 {
00064 enum {
00065 IsInteger = std::numeric_limits<T>::is_integer,
00066 IsSigned = std::numeric_limits<T>::is_signed,
00067 IsComplex = 0,
00068 ReadCost = 1,
00069 AddCost = 1,
00070 MulCost = 1
00071 };
00072
00073 typedef T Real;
00074 typedef typename internal::conditional<
00075 IsInteger,
00076 typename internal::conditional<sizeof(T)<=2, float, double>::type,
00077 T
00078 >::type NonInteger;
00079 typedef T Nested;
00080
00081 inline static Real epsilon() { return std::numeric_limits<T>::epsilon(); }
00082 inline static Real dummy_precision()
00083 {
00084
00085 return Real(0);
00086 }
00087 inline static T highest() { return std::numeric_limits<T>::max(); }
00088 inline static T lowest() { return IsInteger ? std::numeric_limits<T>::min() : (-std::numeric_limits<T>::max()); }
00089 };
00090
00091 template<typename T> struct NumTraits : GenericNumTraits<T>
00092 {};
00093
00094 template<> struct NumTraits<float>
00095 : GenericNumTraits<float>
00096 {
00097 inline static float dummy_precision() { return 1e-5f; }
00098 };
00099
00100 template<> struct NumTraits<double> : GenericNumTraits<double>
00101 {
00102 inline static double dummy_precision() { return 1e-12; }
00103 };
00104
00105 template<> struct NumTraits<long double>
00106 : GenericNumTraits<long double>
00107 {
00108 static inline long double dummy_precision() { return 1e-15l; }
00109 };
00110
00111 template<typename _Real> struct NumTraits<std::complex<_Real> >
00112 : GenericNumTraits<std::complex<_Real> >
00113 {
00114 typedef _Real Real;
00115 enum {
00116 IsComplex = 1,
00117 ReadCost = 2 * NumTraits<_Real>::ReadCost,
00118 AddCost = 2 * NumTraits<Real>::AddCost,
00119 MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
00120 };
00121
00122 inline static Real epsilon() { return NumTraits<Real>::epsilon(); }
00123 inline static Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
00124 };
00125
00126 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00127 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
00128 {
00129 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> ArrayType;
00130 typedef typename NumTraits<Scalar>::Real RealScalar;
00131 typedef Array<RealScalar, Rows, Cols, Options, MaxRows, MaxCols> Real;
00132 typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
00133 typedef Array<NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols> NonInteger;
00134 typedef ArrayType & Nested;
00135
00136 enum {
00137 IsComplex = NumTraits<Scalar>::IsComplex,
00138 IsInteger = NumTraits<Scalar>::IsInteger,
00139 IsSigned = NumTraits<Scalar>::IsSigned,
00140 ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
00141 AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
00142 MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
00143 };
00144 };
00145
00146
00147
00148 #endif // EIGEN_NUMTRAITS_H