home *** CD-ROM | disk | FTP | other *** search
- {
- procedure and functions in this library
-
- Sign returns sign (-1,0,+1) of integer value
- Min returns minimum of two integers
- Max returns maximum of two integers
- ISwap trade two integer values
- ISqrt returns integer square root of integer value
- Condition forces integer into the range Min..Max
- AMin returns minimum integer in array
- AMax returns maximum integer in array
-
- }
-
- function Sign(Val : Integer) : Integer;
- {
- purpose returns sign (-1,0,1) of Val
- last update 23 Jun 85
- }
- begin
- if Val > 0
- then Sign := 1
- else if Val < 0
- then Sign := -1
- else Sign := 0
- end; { of func Sign }
-
- function Min(Val1,Val2 : Integer) : Integer;
- {
- purpose returns minimum of two integers
- last update 08 Jul 85
- }
- begin
- if Val1 < Val2
- then Min := Val1
- else Min := Val2
- end; { of func Min }
-
- function Max(Val1,Val2 : Integer) : Integer;
- {
- purpose returns maximum of two integers
- last update 08 Jul 85
- }
- begin
- if Val1 > Val2
- then Max := Val1
- else Max := Val2
- end; { of func Max }
-
- procedure ISwap(var Val1,Val2 : Integer);
- {
- purpose swaps values of Val1 and Val2
- last update 08 Jul 85
- }
- var
- Temp : Integer;
- begin
- Temp := Val1;
- Val1 := Val2;
- Val2 := Temp
- end; { of proc ISwap }
-
- function ISqrt(Val : Integer) : Integer;
- {
- purpose returns integer square root of Val
- note well: this routine rounds to the nearest square root
- last update 23 Jan 85
- }
- var
- OddSeq,Square,Root : Integer;
- begin
- OddSeq := -1;
- Square := 0;
- repeat
- OddSeq := OddSeq + 2;
- Square := Square + OddSeq
- until Val < Square;
- Root := Succ(OddSeq shr 1);
- if Val <= Square - Root
- then Root := Pred(Root);
- ISqrt := Root
- end; { of func ISqrt }
-
- procedure Condition(Min : Integer; var Val : Integer; Max : Integer);
- {
- purpose forces Min <= Val <= Max
- last update 08 Jul 85
- }
- begin
- if Max < Min
- then ISwap(Min,Max);
- if Val < Min
- then Val := Min
- else if Max < Val
- then Val := Max
- end; { of proc Condition }
-
- function AMin(var IAddr; Size : Integer; var Mndx : Integer) : Integer;
- {
- purpose finds minimum value in integer array
-
- note Size should be the size in *words*; if the
- the function SizeOf is used, then you need
- to divide the result by 2 before passing it on:
- MVal := AMin(IArray,(SizeOf(IArray) shr 1),Indx);
-
- last update 09 Jul 85
- }
- const
- HalfMax = 16383; { MaxInt div 2 }
- type
- DummyArray = array[1..HalfMax] of Integer;
- var
- A1 : DummyArray absolute IAddr;
- Indx,Temp : Integer;
- begin
- Temp := MaxInt;
- Mndx := 0;
- for Indx := 1 to Size do
- if A1[Indx] < Temp then begin
- Mndx := Indx;
- Temp := A1[Indx]
- end;
- AMin := Temp
- end; { of func AMin }
-
- function AMax(var IAddr; Size : Integer; var Mndx : Integer) : Integer;
- {
- purpose finds maximum value in integer array
-
- note Size should be the size in *words*; if the
- the function SizeOf is used, then you need
- to divide the result by 2 before passing it on:
- MVal := AMax(IArray,(SizeOf(IArray) shr 1),Indx);
-
- last update 09 Jul 85
- }
- const
- HalfMax = 16383; { MaxInt div 2 }
- type
- DummyArray = array[1..HalfMax] of Integer;
- var
- A1 : DummyArray absolute IAddr;
- Indx,Temp : Integer;
- begin
- Temp := - MaxInt - 1; { lowest possible integer value }
- Mndx := 0;
- for Indx := 1 to Size do
- if A1[Indx] > Temp then begin
- Mndx := Indx;
- Temp := A1[Indx]
- end;
- AMax := Temp
- end; { of func AMax }
-
-