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 <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
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     // make sure to override this for floating-point types
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


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:01