# T(I/E)ASet(Min/Max/Range)

## Recommended Posts

Lovely title, ehh? ;D

Example for all 3 actions (Min/Max/Range) at the bottom of this post.

TIASetMin - Sets minimum value (x) to TIA

```procedure TIASetMin(var TIA: TIntArray; x: Integer);
var
h, i: Integer;
begin
h := High(TIA);
for i := 0 to h do
if (TIA[i] < x) then
TIA[i] := x;
end;```

TEASetMin - Sets minimum value (x) to TEA

```procedure TEASetMin(var TEA: TExtArray; x: Extended);
var
h, i: Integer;
begin
h := High(TEA);
for i := 0 to h do
if (TEA[i] < x) then
TEA[i] := x;
end;```

TIASetMax - Sets maximum value (x) to TIA

```procedure TIASetMax(var TIA: TIntArray; x: Integer);
var
h, i: Integer;
begin
h := High(TIA);
for i := 0 to h do
if (TIA[i] > x) then
TIA[i] := x;
end;```

TEASetMax - Sets maximum value (x) to TEA

```procedure TEASetMax(var TEA: TExtArray; x: Extended);
var
h, i: Integer;
begin
h := High(TEA);
for i := 0 to h do
if (TEA[i] > x) then
TEA[i] := x;
end;```

TIASetRange - Sets TIA values inside range (mn = minimum, mx = maximum)

```procedure TIASetRange(var TIA: TIntArray; mn, mx: Integer);
var
h, i: Integer;
begin
if (mn > mx) then
Swap(mn, mx);
h := High(TIA);
if (h > -1) then
case (mn = mx) of
True:
for i := 0 to h do
if ((TIA[i] < mn) or (TIA[i] > mx)) then
TIA[i] := mn;
False:
for i := 0 to h do
begin
if (TIA[i] < mn) then
TIA[i] := mn;
if (TIA[i] > mx) then
TIA[i] := mx;
end;
end;
end;```

TEASetRange - Sets TEA values inside range (mn = minimum, mx = maximum)

```procedure TEASetRange(var TEA: TExtArray; mn, mx: Extended);
var
h, i: Integer;
begin
if (mn > mx) then
Swap(mn, mx);
h := High(TEA);
if (h > -1) then
case (mn = mx) of
True:
for i := 0 to h do
if ((TEA[i] < mn) or (TEA[i] > mx)) then
TEA[i] := mn;
False:
for i := 0 to h do
begin
if (TEA[i] < mn) then
TEA[i] := mn;
if (TEA[i] > mx) then
TEA[i] := mx;
end;
end;
end;```

Example for Min, Max and Range with TIA:

```procedure TIASetMin(var TIA: TIntArray; x: Integer);
var
h, i: Integer;
begin
h := High(TIA);
for i := 0 to h do
if (TIA[i] < x) then
TIA[i] := x;
end;

procedure TIASetMax(var TIA: TIntArray; x: Integer);
var
h, i: Integer;
begin
h := High(TIA);
for i := 0 to h do
if (TIA[i] > x) then
TIA[i] := x;
end;

procedure TIASetRange(var TIA: TIntArray; mn, mx: Integer);
var
h, i: Integer;
begin
if (mn > mx) then
Swap(mn, mx);
h := High(TIA);
if (h > -1) then
case (mn = mx) of
True:
for i := 0 to h do
if ((TIA[i] < mn) or (TIA[i] > mx)) then
TIA[i] := mn;
False:
for i := 0 to h do
begin
if (TIA[i] < mn) then
TIA[i] := mn;
if (TIA[i] > mx) then
TIA[i] := mx;
end;
end;
end;

var
TIA: TIntArray;

begin
ClearDebug;

TIA := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
WriteLn('Before TIASetMin(TIA, 1): ' + TIAToStr(TIA));
TIASetMin(TIA, 1);
WriteLn('After TIASetMin(TIA, 1): ' + TIAToStr(TIA) + #13#10);

TIA := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
WriteLn('Before TIASetMax(TIA, 9): ' + TIAToStr(TIA));
TIASetMax(TIA, 9);
WriteLn('After TIASetMax(TIA, 9): ' + TIAToStr(TIA) + #13#10);

TIA := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
WriteLn('Before TIASetRange(TIA, 1, 9): ' + TIAToStr(TIA));
TIASetRange(TIA, 1, 9);
WriteLn('After TIASetRange(TIA, 1, 9): ' + TIAToStr(TIA));

SetLength(TIA, 0);
end.```

-Jani

Edited by Janilabo

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×