home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ENTERPRS
/
CPM
/
UTILS
/
A
/
BYTETURB.ARC
/
INTEGERS.LIB
< prev
next >
Wrap
Text File
|
1989-09-27
|
4KB
|
157 lines
{
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 }
if a1[indx] > temp then begin
m