Matrix::Trunc Method

Overload List

#SignatureDescription
1TMtxVec *Trunc() const;Rounds a real number towards zero.
2TMtxVec *Trunc(int Index, int Len) const;Truncate calling object elements [Index]..[Index+Len-1] in-place.
3TMtxVec *Trunc(TMtxVec *Src) const;Truncate all Src object elements and store the results in calling object elements.
4void Trunc(DewArray<int> &Dst) const;Truncate all calling object elements and store the result in the Dst integer array.
5TMtxVec *Trunc(TMtxVec *Src, int SrcIndex, int Index, int Len) const;Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1].

Overload 1: TMtxVec *Trunc() const;

Rounds a real number towards zero.

Remarks:

Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    a.SetIt(2, 2, false, DewArray<double>{ 1.2, 2.7, -0.5, 3.9 });
    a.Trunc();
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, -0.0, 3.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Trunc: mismatch");
}
See Also: Matrix::Frac, Matrix::Round
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 2: TMtxVec *Trunc(int Index, int Len) const;

Truncate calling object elements [Index]..[Index+Len-1] in-place.

#NameTypeDescription
1Indexint
2Lenint
Remarks:

An exception is raised if array borders are overrun/underrun.

Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 3: TMtxVec *Trunc(TMtxVec *Src) const;

Truncate all Src object elements and store the results in calling object elements.

#NameTypeDescription
1SrcTMtxVec *
Remarks:

Size and Matrix::Complex property of calling object are adjusted automatically.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    a.SetIt(2, 2, false, DewArray<double>{ 1.2, 2.7, -0.5, 3.9 });
    a.Trunc();
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, -0.0, 3.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Trunc: mismatch");
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 4: void Trunc(DewArray<int> &Dst) const;

Truncate all calling object elements and store the result in the Dst integer array.

#NameTypeDescription
1DstDewArray<int> &
Remarks:

Length of the array is automatically adjusted. If the calling object is Complex, the length of the Dst array is equal to 2*Matrix::Length.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    a.SetIt(2, 2, false, DewArray<double>{ 1.2, 2.7, -0.5, 3.9 });
    a.Trunc();
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, -0.0, 3.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Trunc: mismatch");
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 5: TMtxVec *Trunc(TMtxVec *Src, int SrcIndex, int Index, int Len) const;

Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1].

#NameTypeDescription
1SrcTMtxVec *
2SrcIndexint
3Indexint
4Lenint
Remarks:

Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and Matrix::Complex property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun.

Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler