Simbody  3.7
NTraits.h File Reference

This file contains classes and typedefs needed to provide uniform handling of floating point numeric values. More...

Go to the source code of this file.

Classes

class  SimTK::conjugate< R >
 SimTK::conjugate<R> should be instantiated only for float, double. More...
 
class  SimTK::CNT< K >
 Specialized information about Composite Numerical Types which allows us to define appropriate templatized classes using them. More...
 
class  SimTK::NTraits< N >
 
class  SimTK::negator< NUMBER >
 negator<N>, where N is a number type (real, complex, conjugate), is represented in memory identically to N, but behaves as though multiplied by -1, though at zero cost. More...
 
struct  SimTK::Widest< R1, R2 >
 This class is specialized for all 16 combinations of standard types (that is, real and complex types in each of two precisions) and has typedefs "Type" which is the appropriate "widened" type for use when R1 & R2 appear in an operation together, and "Precision" which is the wider precision (float,double). More...
 
struct  SimTK::Widest< float, float >
 
struct  SimTK::Widest< float, double >
 
struct  SimTK::Widest< double, float >
 
struct  SimTK::Widest< double, double >
 
struct  SimTK::Widest< complex< R1 >, complex< R2 > >
 
struct  SimTK::Widest< complex< R1 >, R2 >
 
struct  SimTK::Widest< R1, complex< R2 > >
 
struct  SimTK::Narrowest< R1, R2 >
 This class is specialized for all 16 combinations of standard types (that is, real and complex types in each of two precisions) and has typedefs "Type" which is the appropriate "narrowed" type for use when R1 & R2 appear in an operation together where the result must be of the narrower precision, and "Precision" which is the expected precision of the result (float, double). More...
 
struct  SimTK::Narrowest< float, float >
 
struct  SimTK::Narrowest< float, double >
 
struct  SimTK::Narrowest< double, float >
 
struct  SimTK::Narrowest< double, double >
 
struct  SimTK::Narrowest< complex< R1 >, complex< R2 > >
 
struct  SimTK::Narrowest< complex< R1 >, R2 >
 
struct  SimTK::Narrowest< R1, complex< R2 > >
 
class  SimTK::RTraits< R >
 RTraits is a helper class for NTraits. More...
 
class  SimTK::RTraits< float >
 
class  SimTK::RTraits< double >
 
class  SimTK::NTraits< N >
 
class  SimTK::NTraits< complex< R > >
 Partial specialization for complex numbers – underlying real R is still a template parameter. More...
 
struct  SimTK::NTraits< complex< R > >::Result< P >
 
struct  SimTK::NTraits< complex< R > >::Substitute< P >
 
class  SimTK::NTraits< conjugate< R > >
 
struct  SimTK::NTraits< conjugate< R > >::Result< P >
 
struct  SimTK::NTraits< conjugate< R > >::Substitute< P >
 
class  SimTK::CNT< complex< R > >
 Specializations of CNT for numeric types. More...
 
class  SimTK::CNT< conjugate< R > >
 
class  SimTK::CNT< float >
 
class  SimTK::CNT< double >
 

Namespaces

 SimTK
 This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with other symbols.
 

Macros

#define SimTK_BNTCMPLX_SPEC(T1, T2)
 
#define SimTK_NTRAITS_CONJ_SPEC(T1, T2)
 
#define SimTK_DEFINE_REAL_NTRAITS(R)
 

Functions

bool SimTK::isNaN (const float &x)
 
bool SimTK::isNaN (const double &x)
 
template<class P >
bool SimTK::isNaN (const std::complex< P > &x)
 
template<class P >
bool SimTK::isNaN (const conjugate< P > &x)
 
bool SimTK::isFinite (const float &x)
 
bool SimTK::isFinite (const double &x)
 
template<class P >
bool SimTK::isFinite (const std::complex< P > &x)
 
template<class P >
bool SimTK::isFinite (const conjugate< P > &x)
 
bool SimTK::isInf (const float &x)
 
bool SimTK::isInf (const double &x)
 
template<class P >
bool SimTK::isInf (const std::complex< P > &x)
 
template<class P >
bool SimTK::isInf (const conjugate< P > &x)
 
bool SimTK::isNumericallyEqual (const float &a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
 Compare two floats for approximate equality. More...
 
bool SimTK::isNumericallyEqual (const double &a, const double &b, double tol=RTraits< double >::getDefaultTolerance())
 Compare two doubles for approximate equality. More...
 
bool SimTK::isNumericallyEqual (const float &a, const double &b, double tol=RTraits< float >::getDefaultTolerance())
 Compare a float and a double for approximate equality at float precision. More...
 
bool SimTK::isNumericallyEqual (const double &a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
 Compare a float and a double for approximate equality at float precision. More...
 
bool SimTK::isNumericallyEqual (const float &a, int b, double tol=RTraits< float >::getDefaultTolerance())
 Test a float for approximate equality to an integer. More...
 
bool SimTK::isNumericallyEqual (int a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
 Test a float for approximate equality to an integer. More...
 
bool SimTK::isNumericallyEqual (const double &a, int b, double tol=RTraits< double >::getDefaultTolerance())
 Test a double for approximate equality to an integer. More...
 
bool SimTK::isNumericallyEqual (int a, const double &b, double tol=RTraits< double >::getDefaultTolerance())
 Test a double for approximate equality to an integer. More...
 
template<class P , class Q >
bool SimTK::isNumericallyEqual (const std::complex< P > &a, const std::complex< Q > &b, double tol=RTraits< typename Narrowest< P, Q >::Precision >::getDefaultTolerance())
 Compare two complex numbers for approximate equality, using the numerical accuracy expectation of the narrower of the two precisions in the case of mixed precision. More...
 
template<class P , class Q >
bool SimTK::isNumericallyEqual (const conjugate< P > &a, const conjugate< Q > &b, double tol=RTraits< typename Narrowest< P, Q >::Precision >::getDefaultTolerance())
 Compare two conjugate numbers for approximate equality, using the numerical accuracy expectation of the narrower of the two precisions in the case of mixed precision. More...
 
template<class P , class Q >
bool SimTK::isNumericallyEqual (const std::complex< P > &a, const conjugate< Q > &b, double tol=RTraits< typename Narrowest< P, Q >::Precision >::getDefaultTolerance())
 Compare a complex and a conjugate number for approximate equality, using the numerical accuracy expectation of the narrower of the two precisions in the case of mixed precision. More...
 
template<class P , class Q >
bool SimTK::isNumericallyEqual (const conjugate< P > &a, const std::complex< Q > &b, double tol=RTraits< typename Narrowest< P, Q >::Precision >::getDefaultTolerance())
 Compare a complex and a conjugate number for approximate equality, using the numerical accuracy expectation of the narrower of the two precisions in the case of mixed precision. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const std::complex< P > &a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular real float. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const float &a, const std::complex< P > &b, double tol=RTraits< float >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular real float. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const std::complex< P > &a, const double &b, double tol=RTraits< typename Narrowest< P, double >::Precision >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular real double. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const double &a, const std::complex< P > &b, double tol=RTraits< typename Narrowest< P, double >::Precision >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular real double. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const std::complex< P > &a, int b, double tol=RTraits< P >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular integer. More...
 
template<class P >
bool SimTK::isNumericallyEqual (int a, const std::complex< P > &b, double tol=RTraits< P >::getDefaultTolerance())
 Test whether a complex number is approximately equal to a particular integer. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const conjugate< P > &a, const float &b, double tol=RTraits< float >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular real float. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const float &a, const conjugate< P > &b, double tol=RTraits< float >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular real float. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const conjugate< P > &a, const double &b, double tol=RTraits< typename Narrowest< P, double >::Precision >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular real double. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const double &a, const conjugate< P > &b, double tol=RTraits< typename Narrowest< P, double >::Precision >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular real double. More...
 
template<class P >
bool SimTK::isNumericallyEqual (const conjugate< P > &a, int b, double tol=RTraits< P >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular integer. More...
 
template<class P >
bool SimTK::isNumericallyEqual (int a, const conjugate< P > &b, double tol=RTraits< P >::getDefaultTolerance())
 Test whether a conjugate number is approximately equal to a particular integer. More...
 
 SimTK::SimTK_BNTCMPLX_SPEC (float, float)
 
 SimTK::SimTK_BNTCMPLX_SPEC (float, double)
 
 SimTK::SimTK_BNTCMPLX_SPEC (double, float)
 
 SimTK::SimTK_BNTCMPLX_SPEC (double, double)
 
 SimTK::SimTK_NTRAITS_CONJ_SPEC (float, float)
 
 SimTK::SimTK_NTRAITS_CONJ_SPEC (float, double)
 
 SimTK::SimTK_NTRAITS_CONJ_SPEC (double, float)
 
 SimTK::SimTK_NTRAITS_CONJ_SPEC (double, double)
 
 SimTK::SimTK_DEFINE_REAL_NTRAITS (float)
 
 SimTK::SimTK_DEFINE_REAL_NTRAITS (double)
 

Detailed Description

This file contains classes and typedefs needed to provide uniform handling of floating point numeric values.

There are three numeric types: real, complex, conjugate and each comes in float and double precision. Each of these may be modified by a negator, which does not change the in-memory representation but negates the interpretation. Thus there are 12 distinct scalar types: 2 precisions each of real, complex, and conjugate and their negators.

*      The Scalar Types
*      ----------------
*      Here is a complete taxonomy of the scalar types we support.
*
*      <scalar>    ::= <number> | negator< <number> >
*      <number>    ::= <standard> | <conjugate>
*      <standard>  ::= <real> | <complex>
*
*      <real>      ::= float | double
*      <complex>   ::= complex< <real> >
*      <conjugate> ::= conjugate< <real> >
* 

Macro Definition Documentation

◆ SimTK_BNTCMPLX_SPEC

#define SimTK_BNTCMPLX_SPEC (   T1,
  T2 
)
Value:
template<> template<> struct NTraits< complex<T1> >::Result<T2> { \
typedef Widest< complex<T1>,T2 >::Type W; \
typedef W Mul; typedef W Dvd; typedef W Add; typedef W Sub; \
}; \
template<> template<> struct NTraits< complex<T1> >::Result< complex<T2> > { \
typedef Widest< complex<T1>,complex<T2> >::Type W; \
typedef W Mul; typedef W Dvd; typedef W Add; typedef W Sub; \
}; \
template<> template<> struct NTraits< complex<T1> >::Result< conjugate<T2> > { \
typedef Widest< complex<T1>,complex<T2> >::Type W; \
typedef W Mul; typedef W Dvd; typedef W Add; typedef W Sub; \
}

◆ SimTK_NTRAITS_CONJ_SPEC

#define SimTK_NTRAITS_CONJ_SPEC (   T1,
  T2 
)
Value:
template<> template<> struct NTraits< conjugate<T1> >::Result<T2> { \
typedef conjugate<Widest<T1,T2>::Type> W; \
typedef W Mul; typedef W Dvd; typedef W Add; typedef W Sub; \
}; \
template<> template<> struct NTraits< conjugate<T1> >::Result<complex<T2> >{\
typedef Widest<complex<T1>,complex<T2> >::Type W; \
typedef W Mul; typedef W Dvd; typedef W Add; typedef negator<W> Sub; \
}; \
template<> template<> struct NTraits< conjugate<T1> >::Result<conjugate<T2> >{\
typedef Widest<T1,T2>::Type W; typedef complex<W> WC; \
typedef negator<WC> Mul; typedef WC Dvd; typedef conjugate<W> Add; typedef WC Sub;\
}

◆ SimTK_DEFINE_REAL_NTRAITS

#define SimTK_DEFINE_REAL_NTRAITS (   R)