Vector.Sgn Method

Overload List

#SignatureDescription
1function Sgn: TMtxVec;Computes signum function of calling object elements.
└ indexed: function Sgn(Index: Integer; Len: Integer): TMtxVec;
2function Sgn(const Src: TMtxVec): TMtxVec;Computes signum function from Src elements and stores the result in the calling object.
└ indexed: function Sgn(const Src: TMtxVec; SrcIndex: Integer; Index: Integer; Len: Integer): TMtxVec;

Overload 1: function Sgn: TMtxVec;

Computes signum function of calling object elements.

Result: stored in self (calling object), returns self for chaining

Remarks:

Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0.

Examples
var
    a, expected: Vector;
begin
    a := [-3.0, -1.0, 1.0, 2.0];
    a.Sgn;
    expected := [-1.0, -1.0, 1.0, 1.0];
    if not a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute) then
        raise Exception.Create('Vector.Sgn: mismatch');
end;

Indexed: function Sgn(Index: Integer; Len: Integer): TMtxVec;

Computes signum function of calling object elements [Index..Index+Len-1].

#NameTypeDescription
1IndexIntegerstart index
2LenIntegerelement count

Result: stored in self (calling object), returns self for chaining

Remarks:

Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0.

Overload 2: function Sgn(const Src: TMtxVec): TMtxVec;

Computes signum function from Src elements and stores the result in the calling object.

#NameTypeDescription
1SrcTMtxVec

Result: stored in self (calling object), returns self for chaining

Remarks:

Size and Vector.Complex properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0.

Examples
var
    a, x, expected: Vector;
begin
    x := [-3.0, -1.0, 1.0, 2.0];
    a.Sgn(x);
    expected := [-1.0, -1.0, 1.0, 1.0];
    if not a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute) then
        raise Exception.Create('Vector.Sgn: mismatch');
end;

Indexed: function Sgn(const Src: TMtxVec; SrcIndex: Integer; Index: Integer; Len: Integer): TMtxVec;

Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1].

#NameTypeDescription
1SrcTMtxVec
2SrcIndexIntegersource start index
3IndexIntegerstart index
4LenIntegerelement count

Result: stored in self (calling object), returns self for chaining

Remarks:

Size and Vector.Complex properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0.