Vector.Sign Method

Overload List

#SignatureDescription
1function Sign: TMtxVec;Changes elements sign.
└ indexed: function Sign(Index: Integer; Len: Integer): TMtxVec;
2function Sign(const X: TMtxVec): TMtxVec;Change all X object elements sign and store the results in calling object.
└ indexed: function Sign(const X: TMtxVec; XIndex: Integer; Index: Integer; Len: Integer): TMtxVec;

Overload 1: function Sign: TMtxVec;

Changes elements sign.

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

Remarks:

Changes all calling object elements sign (v -> -v) in-place.

Examples
var a: Vector;
begin
    a.SetIt(False,[1,2,-3,4]);
    a.Sign; // a = [-1,-2,3,-4]
end;
var
    a, expected: Vector;
begin
    a := [-3.0, -1.0, 1.0, 2.0];
    a.Sign;
    expected := [3.0, 1.0, -1.0, -2.0];
    if not a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute) then
        raise Exception.Create('Vector.Sign: mismatch');
end;
See Also: Vector.Mul

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

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

#NameTypeDescription
1IndexIntegerstart index
2LenIntegerelement count

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

Remarks:

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

Overload 2: function Sign(const X: TMtxVec): TMtxVec;

Change all X object elements sign and store the results in calling object.

#NameTypeDescription
1XTMtxVec

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

Remarks:

Size and Vector.Complex properties of calling object are adjusted automatically.

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

Indexed: function Sign(const X: TMtxVec; XIndex: Integer; Index: Integer; Len: Integer): TMtxVec;

Change X object elements [XIndex]..[XIndex+Len-1] sign and store the results in calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1XTMtxVec
2XIndexIntegerX start index
3IndexIntegerstart index
4LenIntegerelement count

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

Remarks:

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