casacore
|
#include <NumericTraits.h>
Public Types | |
typedef T | value_type |
Template argument. More... | |
typedef Char | BaseType |
Numeric type. More... | |
typedef Char | ConjugateType |
Conjugate (real<->complex ) type. More... | |
typedef Char | PrecisionType |
Higher precision type (Float->Double ) More... | |
Static Public Member Functions | |
static uInt | size () |
Number of relevant numeric values. More... | |
static void | setImag (T &, const BaseType &) |
Set the imaginary part of a complex value only (a NOP for reals) More... | |
static BaseType | getValue (const T &, const uInt) |
Get the nsize()-th numeric value. More... | |
static void | setValue (T &, const BaseType &, const uInt) |
Set the nsize()-th numeric value. More... | |
Static Public Attributes | |
static const Double & | epsilon |
Relevant minimum and maximum numbers. More... | |
static const Double & | minimum |
static const Double & | maximum |
Relationships between numeric data types
Public interface
A trait is a characteristic feature. NumericTraits defines relationships between and characteristics of Numeric data types.
This templated class contains a number of typedefs and definitions that describe the relationship between different numeric data types and there characteristics. Its use is in templated classes either where the use of one type implictly implies the use of a corresponding one or where a characteristic value differs with templating argument. Use of this class often avoids the need for double templating.
Currently this class defines the following relationships:
value_type
value_type
is the C++ standard (e.g. DComplex::value_type
equals double
) BaseType
Double
for Double
and DComplex
; Float
for Float
and Complex
ConjugateType
PrecisionType
Double
or DComplex
And the following characteristics:
epsilon
minimum
maximum
size()
setImag(T &other, const BaseType &val)
getValue(T &other, const uInt n)
nsize()-th
value in the argument. For complex numbers the sequence is real, imaginary part. setValue(T &other, const BaseType &val, const uInt n)
nsize()-th
value in the argument. For complex numbers the sequence is real, imaginary part. For complex numbers these values are applicable to the real or imaginary components separately.
The use of this class is best illustrated in a number of examples.
A default template declaration is required by the C++ standard. It should never be used, except through the specialisations. The default types for ConjugateType and PrecisionType are deliberatly set to a non-numeric type to further discourage the use of the non-specialized class defined below. It also helps when using this class with the Sun native compiler.
Warning: The specialized instantiations seem to have a name with an appended code; This is only for cxx2html reasons; The name is in all cases NumericTraits
This class is implemented as a number of specialisations for the following data types.
This class should not be used with other template types and does nothing except return its template type if it is used. ie.
NumericTraits<ArbitraryType>::ConjugateType
returns Char
and
NumericTraits<ArbitraryType>::PrecisionType
returns Char
NumericTraits<ArbitraryType>::epsilon
is undefined
NumericTraits<ArbitraryType>::minimum
is undefined
NumericTraits<ArbitraryType>::maximum
is undefined
Suppose you are writing a templated class that needs to do Fourier Transforms. The FFTServer class can do FFT's of Float or Double data types, but you need to doubly template it on the conjugate data type. To avoid having the conjugate data type appear as a template in the class you are writing you can use the ConjugateType typedef.
The ConjugateType transforms
Suppose you have a templated numerical integrator class. Because the individual samples can be negative it is possible to add two numbers of nearly equal magnitude but opposite sign and lose precision considerably. One way to combat this is to make the accumulator variable the next higher precision numerical type. The PrecisionType typedef defines what type this is
The PrecisionType transforms
Suppose you have a templated class that needs to use the allNear
functions from ArrayMath to determine if a templated Array is near one. The tolerance argument to the allNear function will depend on the template type and this is not known until the template is instantiated. The epsilon trait can be used to supply this value.
NumericTraits<T>::epsilon
NumericTraits<T>::minimum
NumericTraits<T>::maximum
See the C class/namespace for the values of these variables.
This is a nice way to make the Convolver class singly templated (as it should be), even though the FFTServer it contains is doubly templated.
Definition at line 223 of file NumericTraits.h.
typedef Char casacore::NumericTraits< T >::BaseType |
Numeric type.
Definition at line 228 of file NumericTraits.h.
typedef Char casacore::NumericTraits< T >::ConjugateType |
Conjugate (real<->complex
) type.
Definition at line 230 of file NumericTraits.h.
typedef Char casacore::NumericTraits< T >::PrecisionType |
Higher precision type (Float->Double
)
Definition at line 232 of file NumericTraits.h.
typedef T casacore::NumericTraits< T >::value_type |
Template argument.
Definition at line 226 of file NumericTraits.h.
|
inlinestatic |
Get the nsize()-th
numeric value.
Definition at line 244 of file NumericTraits.h.
|
inlinestatic |
Set the imaginary part of a complex value only (a NOP for reals)
Definition at line 242 of file NumericTraits.h.
|
inlinestatic |
Set the nsize()-th
numeric value.
Definition at line 246 of file NumericTraits.h.
|
inlinestatic |
Number of relevant numeric values.
Definition at line 240 of file NumericTraits.h.
|
static |
Relevant minimum and maximum numbers.
Definition at line 235 of file NumericTraits.h.
|
static |
Definition at line 237 of file NumericTraits.h.
|
static |
Definition at line 236 of file NumericTraits.h.