unit PascalFunctions;

// D. Rosseel
// Original: 07-06-2009
// Latest update: 21-06-2011

     
// interface
           
type Sett  = DWord;
     SettArr = array[4] of byte;
     PByte = ^byte;
     
// *****************  Standard Pascal Functions ********************************
     
function Odd(Value:   DWord)  :boolean;
// Odd tests if the argument is an odd number.
// It returns True if Value is an odd number, False if Value is even.

function Succ(Value:  DWord)  :DWord;
// Succ returns the successor of the argument, Value.

function Pred(Value:  DWord)  :DWord;
// Pred returns the predecessor of the argument, Value.

{$IFNDEF __Lib_Trigon_Janni_Yo2Lio}
function Abs(Value:   LongInt):DWord;
// Abs returns the absolute value of the integer argument.
{$ENDIF}

function SqrInt(Value:   LongInt):DWord;
// The Sqr function returns the square of the integer argument.

{$IFNDEF __Lib_Trigon_Janni_Yo2Lio}
function Sqr(Value:  Real)   :Real;
// The Sqr function returns the square of the real argument.

function Trunc(Value: Real)  :LongInt;
// Trunc returns an integer value that is the value of realtype Value rounded toward zero.
// Same as function "Int"

function Round(Value: Real)  :LongInt;
// Round returns a LongInt value that is the value of Value rounded to the nearest whole number.

function Frac(Value:  Real)  :Real;
// The Frac function returns the fractional part of the argument.

function Int(Value: real)    :Real;
// Int returns the integer part of Value; that is, Value rounded toward zero.
{$ENDIF}


// *****************  Pascal "Set" type Operators ******************************

// Element has always a value from 0..31 (Sett has 4 bytes, which is 32 bits)

function IsInSet(Set_: Sett; Element: byte): boolean;
// Returns true if "Element" is an element of "Set_"

procedure AddToSet(var Set_: Sett; Element: byte);
// Adds "Element" to the set "Set_"

procedure RemoveFromSet(var Set_: Sett; Element: byte);
// Removes "Element" from the set "Set_"

function UnionSet(Set1, Set2: Sett): Sett;
// Returns the union of Set1 and Set 2
// The union has all elements that are elements of Set1 or set2
// Same as the "+" operator on sets in Delphi

function DiffSet(Set1, Set2: Sett): Sett;
// Returns the difference of Set1 and Set2
// The difference has all elements of Set1 that are not in Set2
// Same as the "-" operator on sets in Delphi

function IntersectSet(Set1, Set2: Sett): Sett;
// Returns the intersection of Set1 and Set2
// The intersection has all elements that are both in Set and in Set2
// Same as the "*" operator on sets in Delphi

function IsSubSet(Set1, Set2: Sett): boolean;
// Returns True if Set1 is a subset of Set 2
// Set1 is a subset of Set2 if all its elements ar also in Set2
// Same as the "<="  operator on sets in Delphi

function IsSuperSet(Set1, Set2: Sett): boolean;
// Returns True if Set1 is a superset of Set 2
// Set1 is a superset of Set2 if all of Set2 are in Set1
// Same as the ">="  operator on sets in Delphi

function IsEqualSet(Set1, Set2: Sett): boolean;
// Returns True if Set1 is equal to Set 2
// Same as the "="  operator on sets in Delphi
// This function can also be replaced by a simple "=" as long the
// type "DWord" is used to represent the "Sett" type

function IsUnEqualSet(Set1, Set2: Sett): boolean;
// Returns True if Set1 is unequal to Set 2
// Same as the "<>"  operator on sets in Delphi
// This function can also be replaced by a simple "<>" as long the
// type "DWord" is used to represent the "Sett" type