2.2.3.9.5 matrixbase::CastToInteger

Description

Round this matrix placing the results in a matrix having an underlying base type of int.

Syntax

int CastToInteger( matrix<int> & mInteger )

Parameters

mInteger
[output] The result matrix having an underlying base type of int

Return

Returns 0 on success and a non-zero error code on failure.

Examples

EX1

void matrixbase_CastToInteger_ex1()
{
    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
 
    matrix<double> mat1 = {
        {-1.9, 	 0, 99},
        { 1.9, 3.8, 5.7},
        { 7.6, 9.5, 11.4}
    }; 
    mat1[0][2]=NANUM;

    matrix<int> mInt;
	Mat1=mat1;
	
	int rc=mat1.CastToInteger(mInt);
    if(rc!=0) 
        printf("Error: CastToInteger on %s failed.\n",Mat1.GetName());
    else{            
        MatrixPage MatPg2;
        MatPg2.Create("Origin");
        MatrixLayer MatLy2 = MatPg2.Layers(0);
        Matrix<double> Mat2(MatLy2);
        Mat2=mInt;
    }
    // original matrix:		 
        //{-1.9,   0, --},
        //{ 1.9, 3.8, 5.7},
        //{ 7.6, 9.5, 11.4} 
    // result matrix: 
        //{-2, 0, 0}	Note that the NANUM value in double was int-cast to 0
        //{ 2, 4, 6}
        //{ 8, 9, 11}
}

Remark

Round this matrix placing the results in a matrix having an underlying base type of int. The input matrix must have an underlying base type of float or double or a run time error is generated.

See Also

matrixbase::MakeComplex, matrixbase::CastToDouble, matrixbase::GetInternalDataType

Header to Include

origin.h