Converting Precisions
Converting between matrices of the same shape but different precisions is much the same as converting between scalar types. Both follow similar rules in C++. The following program gives an example of type conversions that are possible using tridiagonal matrices:
 
#include <rw/lapack/trdgmat.h>
 
int main()
{
RWTriDiagMat<float> Afloat(5,5); // 1
RWTriDiagMat<double> Adouble = Afloat; // 2
RWTriDiagMat<DComplex> Acomplex = Adouble; // 3
 
return 0;
}
//1 This line creates a 5 x 5 tridiagonal matrix of floats.
//2 This line demonstrates that this matrix can be converted automatically to a matrix of doubles.
//3 This line shows that this matrix can be converted to a matrix of complex.
In each of the conversions above, no information is lost. However, conversions in the opposite direction are narrowing and may cause a loss of precision. These conversions are possible, but you must explicitly use a function provided for this purpose. For example:
 
#include <rw/lapack/trdgmat.h>
 
int main()
{
RWTriDiagMat<DComplex> Acomplex(5,5); // 1
RWTriDiagMat<double> Adouble = real(Acomplex); // 2
RWTriDiagMat<float> Afloat= toFloat(Adouble); // 3
 
return 0;
}
//1 This line defines a 5 x 5 complex tridiagonal matrix.
//2 Takes the real part of the complex matrix and stores it as a matrix of doubles.
//3 Converts a matrix of doubles to a matrix of floats.
Type conversions between RWGenMat<T> matrices is different due to their template definition. Automatic conversions are not generally available. For a complete discussion about type conversions for general matrices, see the Essential Math Module User’s Guide.