Base template for the MathTrait class.
The MathTrait class template offers the possibility to select the resulting data type of a generic mathematical operation. In case of operations between built-in data types, the MathTrait class defines the more significant data type as the resulting data type. For this selection, signed data types are given a higher significance. In case of operations involving user-defined data types, the MathTrait template specifies the resulting data type of this operation.
Specifying the resulting data type for a specific operation is done by specializing the MathTrait template for this particular type combination. In case a certain type combination is not defined in a MathTrait specialization, the base template is selected, which defines no resulting types and therefore stops the compilation process. Each specialization defines the data types HighType that represents the high-order data type of the two given data types and LowType that represents the low-order data type. Additionally, each specialization defines the types AddType, SubType, MultType and DivType, that represent the type of the resulting data type of the corresponding mathematical operation. The following example shows the specialization for operations between the double and the integer type:
Per default, the MathTrait template provides specializations for the following built-in data types:
It is possible to specialize the MathTrait template for additional user-defined data types. However, it is possible that a specific mathematical operation is invalid for the particular type combination. In this case, the INVALID_NUMERICAL_TYPE can be used to fill the missing type definition. The INVALID_NUMERICAL_TYPE represents the resulting data type of an invalid numerical operation. It is left undefined to stop the compilation process in case it is instantiated. The following example shows the specialization of the MathTrait template for Matrix3 and Vector3. In this case, only the multiplication between the matrix and the vector is a valid numerical operation. Therefore for all other types the INVALID_NUMERICAL_TYPE is used.
The following example demonstrates the use of the MathTrait template, where depending on the two given data types the resulting data type is selected:
Additionally, the specializations of the MathTrait template enable arithmetic operations between any combination of the supported data types:
#include <MathTrait.h>
Public Types | |
using | HighType = T1 |
using | LowType = T2 |
using | High = T1 |
using | Low = T2 |
using walberla::math::MathTrait< T1, T2 >::High = T1 |
using walberla::math::MathTrait< T1, T2 >::HighType = T1 |
using walberla::math::MathTrait< T1, T2 >::Low = T2 |
using walberla::math::MathTrait< T1, T2 >::LowType = T2 |