Medial Code Documentation
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
51template<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,
66 typename internal::conditional<sizeof(T)<=2, float, double>::type,
67 T
68 >::type NonInteger;
69 typedef T Nested;
70
72 static inline Real epsilon()
73 {
74 #if defined(__CUDA_ARCH__)
75 return internal::device::numeric_limits<T>::epsilon();
76 #else
77 return std::numeric_limits<T>::epsilon();
78 #endif
79 }
81 static inline Real dummy_precision()
82 {
83 // make sure to override this for floating-point types
84 return Real(0);
85 }
86
87
89 static inline T highest() {
90#if defined(__CUDA_ARCH__)
91 return (internal::device::numeric_limits<T>::max)();
92#else
93 return (std::numeric_limits<T>::max)();
94#endif
95 }
96
98 static inline T lowest() {
99#if defined(__CUDA_ARCH__)
100 return IsInteger ? (internal::device::numeric_limits<T>::min)() : (-(internal::device::numeric_limits<T>::max)());
101#else
102 return IsInteger ? (std::numeric_limits<T>::min)() : (-(std::numeric_limits<T>::max)());
103#endif
104 }
105};
106
107template<typename T> struct NumTraits : GenericNumTraits<T>
108{};
109
110template<> struct NumTraits<float>
111 : GenericNumTraits<float>
112{
114 static inline float dummy_precision() { return 1e-5f; }
115};
116
117template<> struct NumTraits<double> : GenericNumTraits<double>
118{
120 static inline double dummy_precision() { return 1e-12; }
121};
122
123template<> struct NumTraits<long double>
124 : GenericNumTraits<long double>
125{
126 static inline long double dummy_precision() { return 1e-15l; }
127};
128
129template<typename _Real> struct NumTraits<std::complex<_Real> >
130 : GenericNumTraits<std::complex<_Real> >
131{
132 typedef _Real Real;
133 enum {
134 IsComplex = 1,
135 RequireInitialization = NumTraits<_Real>::RequireInitialization,
136 ReadCost = 2 * NumTraits<_Real>::ReadCost,
137 AddCost = 2 * NumTraits<Real>::AddCost,
139 };
140
141 static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
142 static inline Real dummy_precision() { return NumTraits<Real>::dummy_precision(); }
143};
144
145template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
146struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
147{
149 typedef typename NumTraits<Scalar>::Real RealScalar;
153 typedef ArrayType & Nested;
154
155 enum {
159 RequireInitialization = 1,
160 ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
161 AddCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
162 MulCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
163 };
164
165 static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
166 static inline RealScalar dummy_precision() { return NumTraits<RealScalar>::dummy_precision(); }
167};
168
169} // end namespace Eigen
170
171#endif // EIGEN_NUMTRAITS_H
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:47
Pseudo expression representing a solving operation.
Definition Solve.h:63
Definition StdDeque.h:58
Definition NumTraits.h:52
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition Meta.h:34
Definition Meta.h:61