CompositeNumericalTypes.h
Go to the documentation of this file.00001 #ifndef SimTK_SIMMATRIX_COMPOSITE_NUMERICAL_TYPES_H_
00002 #define SimTK_SIMMATRIX_COMPOSITE_NUMERICAL_TYPES_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00115 #include "SimTKcommon/internal/common.h"
00116
00117 namespace SimTK {
00118
00119
00120
00121
00122
00123
00124 enum {
00125 SCALAR_DEPTH = 0,
00126 SCALAR_COMPOSITE_DEPTH = 1,
00127 COMPOSITE_COMPOSITE_DEPTH = 2,
00128 COMPOSITE_3_DEPTH = 3,
00129 MAX_RESOLVED_DEPTH = COMPOSITE_3_DEPTH
00130 };
00131
00145 template <class K> class CNT : private K {
00146 public:
00147 typedef K T;
00148 typedef typename K::TNeg TNeg;
00149 typedef typename K::TWithoutNegator TWithoutNegator;
00150 typedef typename K::TReal TReal;
00151 typedef typename K::TImag TImag;
00152 typedef typename K::TComplex TComplex;
00153 typedef typename K::THerm THerm;
00154 typedef typename K::TPosTrans TPosTrans;
00155 typedef typename K::TSqHermT TSqHermT;
00156 typedef typename K::TSqTHerm TSqTHerm;
00157 typedef typename K::TElement TElement;
00158 typedef typename K::TRow TRow;
00159 typedef typename K::TCol TCol;
00160
00161
00162
00163 typedef typename K::TSqrt TSqrt;
00164 typedef typename K::TAbs TAbs;
00165 typedef typename K::TStandard TStandard;
00166 typedef typename K::TInvert TInvert;
00167 typedef typename K::TNormalize TNormalize;
00168
00169 typedef typename K::Scalar Scalar;
00170 typedef typename K::ULessScalar ULessScalar;
00171 typedef typename K::Number Number;
00172 typedef typename K::StdNumber StdNumber;
00173 typedef typename K::Precision Precision;
00174
00175 typedef typename K::ScalarNormSq ScalarNormSq;
00176
00177
00178 template <class P> struct Result {
00179 typedef typename K::template Result<P>::Mul Mul;
00180 typedef typename K::template Result<P>::Dvd Dvd;;
00181 typedef typename K::template Result<P>::Add Add;
00182 typedef typename K::template Result<P>::Sub Sub;
00183 };
00184
00185
00186 template <class P> struct Substitute {
00187 typedef typename K::template Substitute<P>::Type Type;
00188 };
00189
00190 enum {
00191 NRows = K::NRows,
00192 NCols = K::NCols,
00193 RowSpacing = K::RowSpacing,
00194 ColSpacing = K::ColSpacing,
00195 NPackedElements = K::NPackedElements,
00196 NActualElements = K::NActualElements,
00197 NActualScalars = K::NActualScalars,
00198 ImagOffset = K::ImagOffset,
00199 RealStrideFactor = K::RealStrideFactor,
00200 ArgDepth = K::ArgDepth,
00201 IsScalar = K::IsScalar,
00202 IsULessScalar = K::IsULessScalar,
00203 IsNumber = K::IsNumber,
00204 IsStdNumber = K::IsStdNumber,
00205 IsPrecision = K::IsPrecision,
00206 SignInterpretation = K::SignInterpretation
00207 };
00208
00209 static const Scalar* getData(const T& t) { return t.getData(); }
00210 static Scalar* updData(T& t) { return t.updData(); }
00211
00212 static const TReal& real(const T& t) { return t.real(); }
00213 static TReal& real(T& t) { return t.real(); }
00214 static const TImag& imag(const T& t) { return t.imag(); }
00215 static TImag& imag(T& t) { return t.imag(); }
00216
00217
00218
00219
00220 static const TNeg& negate(const T& t)
00221 { return reinterpret_cast<const TNeg&>(t); }
00222 static TNeg& negate(T& t)
00223 { return reinterpret_cast<TNeg&>(t); }
00224
00225 static const THerm& transpose(const K& t)
00226 { return reinterpret_cast<const THerm&>(t); }
00227 static THerm& transpose(K& t)
00228 { return reinterpret_cast<THerm&>(t); }
00229
00230 static const TPosTrans& positionalTranspose(const K& t)
00231 { return reinterpret_cast<const TPosTrans&>(t); }
00232 static TPosTrans& positionalTranspose(K& t)
00233 { return reinterpret_cast<TPosTrans&>(t); }
00234
00235
00236
00237
00238
00239
00240
00241 static const TWithoutNegator& castAwayNegatorIfAny(const T& t)
00242 {return reinterpret_cast<const TWithoutNegator&>(t);}
00243 static TWithoutNegator& updCastAwayNegatorIfAny(T& t)
00244 {return reinterpret_cast<TWithoutNegator&>(t);}
00245
00246 static ScalarNormSq scalarNormSqr(const K& t) {return t.scalarNormSqr();}
00247
00248 static TSqrt sqrt(const K& t) {return t.sqrt();}
00249 static TAbs abs(const K& t) {return t.abs();}
00250 static TStandard standardize(const K& t) {return t.standardize();}
00251 static TNormalize normalize(const K& t) {return t.normalize();}
00252 static TInvert invert(const K& t) {return t.invert();}
00253
00254 static K getInfinity() {return K::getInfinity();}
00255 static K getNaN() {return K::getNaN();}
00256
00258 static bool isNaN(const K& t) {return t.isNaN();}
00261 static bool isInf(const K& t) {return t.isInf();}
00263 static bool isFinite(const K& t) {return t.isFinite();}
00264
00272 template <class K2> static bool
00273 isNumericallyEqual(const K& t1, const K2& t2)
00274 { return t1.isNumericallyEqual(t2);}
00275 template <class K2> static bool
00276 isNumericallyEqual(const K& t1, const K2& t2, double tol)
00277 { return t1.isNumericallyEqual(t2,tol);}
00278 static double getDefaultTolerance() {return K::getDefaultTolerance();}
00279
00280 };
00281
00282 }
00283
00284 #endif // SimTK_SIMMATRIX_COMPOSITE_NUMERICAL_TYPES_H_