None
template <class T> class rw_numeric_traits
rw_numeric_traits<int> rw_numeric_traits<float> rw_numeric_traits<double> rw_numeric_traits<DComplex> rw_numeric_traits<UChar> rw_numeric_traits<SChar>
The rw_numeric_traits class is a helper class that contains only typedef information. The generic rw_numeric_traits<T> assumes that all the typedefs are set to T. Since this is not desirable for many types, we specialize for each numeric type that is used in the library.
The specializations used in the library are contained in the file
rw/math/numtrait.h. For an overview of how to add a new numeric type, see Section 2.2.2 of the Math.h++ User's Guide.
There are seven public typedefs in each specialized rw_numeric_traits class. Each typedef must be defined in a given specialization for proper results. The generic class is:
template< class T > class rw_numeric_traits { public: typedef T norm_type; typedef T calc_type; typedef T numeric_type; typedef T c_type; typedef T promote_type; typedef T (* mathFunType)(T); typedef norm_type (*mathFunType2)(T); };
rw_numeric_traits<T>::norm_type
The return type of abs(T) or similar numerical norm-like functions, such as rw_numeric_traits<DComplex>::norm_type, is double because abs(DComplex) returns a double. This is most often double for built-in types.
rw_numeric_traits<T>::calc_type
For some aggregate functions such as sum, a higher-precision numeric type can be used for intermediate calculations. This is intended mostly for floating point types to reduce round-off error in computations. For example, rw_numeric_traits<float>::calc_type is double because this makes the sum of a vector of floats less susceptible to round-off error.
rw_numeric_traits<T>::numeric_type
For most types this should be set to T. This typedef is aimed to improve I/O operations for char based collections. If T is a char-like type, but it is used in any RWMathVec<T>, RWGenMat<T>, or RWMathArray<T>, the typedef should be set to int.
rw_numeric_traits<T>::c_type
This is the companion to numeric_type. If T is a char-like type, it should be set to char; otherwise, it should be set to T.
rw_numeric_traits<T>::promote_type
Automatic conversions and templates do not work well together because they readily lead to ambiguity errors. For that reason, automatic conversions of the collection classes are limited to one promotion type per numeric type T. The promote_type setting allows an RWMathVec<T> to be converted automatically to
RWMathVec<rw_numeric_traits<T>::promote_type>. In other words, rw_numeric_traits<float>::promote_type is double, while rw_numeric_traits<double::promote_type is DComplex. This typedef is designed to assist in backward compatibility, and may become obsolete when new language features become available.
rw_numeric_traits<T>::mathFunType
The member functions RWMathVec<T>::apply, RWGenMat<T>::apply, and RWMathArray<T>::apply take a function pointer of type mathFunType. These functions are used to apply a global function to each element of a collection. The compiler must make an exact match for the apply function to work, and since most global numerical functions take a double and return a double, the mathFunType is set to double in almost all cases except complex. If type T is readily converted to type double and you want to use the apply function with built-in functions, mathFunType should be set by:
typedef double (*mathFunType)(double);
If, on the other hand, your type T uses specific functions that take T and return T, the default setting is appropriate. Note that some compilers distinguish and do not match between the above typedef and:
typedef double (*mathFunType)(const double&);
Be sure that your definition of mathFunType is consistent with the functions you use in apply.
rw_numeric_traits<T>::mathFunType2
The member functions RWMathVec<T>::apply2, RWGenMat<T>::apply2, and RWMathArray<T>::apply2 take a function pointer of type mathFunType2. The discussion of mathFunType applies equally here, with the exception of the return type. The return type for the apply2 function is type norm_type. The mathFunType and mathFunType2 definitions are most often the same except that the return type of mathFunType2 is norm_type.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.