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;
}
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;
}
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.