OSVR-Core
NumTraits.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_NUMTRAITS_H
11 #define EIGEN_NUMTRAITS_H
12 
13 namespace Eigen {
14 
51 template<typename T> struct GenericNumTraits
52 {
53  enum {
54  IsInteger = std::numeric_limits<T>::is_integer,
55  IsSigned = std::numeric_limits<T>::is_signed,
56  IsComplex = 0,
57  RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
58  ReadCost = 1,
59  AddCost = 1,
60  MulCost = 1
61  };
62 
63  typedef T Real;
64  typedef typename internal::conditional<
65  IsInteger,
67  T
68  >::type NonInteger;
69  typedef T Nested;
70 
71  static inline Real epsilon() { return std::numeric_limits<T>::epsilon(); }
72  static inline Real dummy_precision()
73  {
74  // make sure to override this for floating-point types
75  return Real(0);
76  }
77  static inline T highest() { return (std::numeric_limits<T>::max)(); }
78  static inline T lowest() { return IsInteger ? (std::numeric_limits<T>::min)() : (-(std::numeric_limits<T>::max)()); }
79 
80 #ifdef EIGEN2_SUPPORT
81  enum {
82  HasFloatingPoint = !IsInteger
83  };
84  typedef NonInteger FloatingPoint;
85 #endif
86 };
87 
88 template<typename T> struct NumTraits : GenericNumTraits<T>
89 {};
90 
91 template<> struct NumTraits<float>
92  : GenericNumTraits<float>
93 {
94  static inline float dummy_precision() { return 1e-5f; }
95 };
96 
97 template<> struct NumTraits<double> : GenericNumTraits<double>
98 {
99  static inline double dummy_precision() { return 1e-12; }
100 };
101 
102 template<> struct NumTraits<long double>
103  : GenericNumTraits<long double>
104 {
105  static inline long double dummy_precision() { return 1e-15l; }
106 };
107 
108 template<typename _Real> struct NumTraits<std::complex<_Real> >
109  : GenericNumTraits<std::complex<_Real> >
110 {
111  typedef _Real Real;
112  enum {
113  IsComplex = 1,
114  RequireInitialization = NumTraits<_Real>::RequireInitialization,
115  ReadCost = 2 * NumTraits<_Real>::ReadCost,
116  AddCost = 2 * NumTraits<Real>::AddCost,
118  };
119 
120  static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
121  static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
122 };
123 
124 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
125 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
126 {
128  typedef typename NumTraits<Scalar>::Real RealScalar;
130  typedef typename NumTraits<Scalar>::NonInteger NonIntegerScalar;
132  typedef ArrayType & Nested;
133 
134  enum {
135  IsComplex = NumTraits<Scalar>::IsComplex,
136  IsInteger = NumTraits<Scalar>::IsInteger,
137  IsSigned = NumTraits<Scalar>::IsSigned,
138  RequireInitialization = 1,
139  ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
140  AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
141  MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
142  };
143 
144  static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
145  static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); }
146 };
147 
148 } // end namespace Eigen
149 
150 #endif // EIGEN_NUMTRAITS_H
Definition: NumTraits.h:51
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Definition: TypeSafeIdHash.h:44
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Definition: Meta.h:29
Definition: Meta.h:56
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Definition: osvr_print_tree.cpp:52