Unit ESBMaths

Classes

Functions

CompMOD - Performs Floating Point Remainder.
DecLim - Increments a LongInt up to Limit.
DecLimI - Decrements a Word down to Limit.
DecLimL - Decrements an Integer down to Limit.
DecLimSI - Decrements a Byte down to Limit.
DecLimW - Decrements a ShortInt down to Limit.
Distance - Returns -1 if X < 0 0 if X = 0 1 if X > 0
DMS2Extended - Converts Cartesian Co-ordinates to Polar Co-ordinates
Extended2DMS - Converts Degrees/Minutes/Seconds into an Extended Real
ExtMod - Returns the straight line Distance between (X1, Y1) and (X2, Y2)
ExtRem - Performs Floating Point Modulus.
FloatIsZero - Returns True if X1 and X2 are within ESBTolerance of each other
Get87ControlWord - ISqrt (I) computes INT (SQRT (I)), that is, the integral part of the square root of integer I.
IncLim - Returns True if X is within ESBTolerance of 0

Returns the Sum of an Array of Comp Reals
IncLimI - Increments a Word up to Limit.
IncLimL - Increments an Integer up to Limit.
IncLimSI - Increments a Byte up to Limit.
IncLimW - Increments a ShortInt up to Limit.
ISqrt - Returns the Sum of an array of Longints.
Max3Word - Returns the Minimum of 4 Words - BASM
Max4Word - Returns -1 if B < 0 0 if B = 0 1 if B > 0 BASM
MaxB - Decrements a LongInt down to Limit.
MaxBArray - Returns the Minimum of 3 Words - BASM
MaxCArray - Returns the Minimum of an array of Single Reals
MaxEArray - Returns the Minimum of two Extended Reals
MaxExt - Converts an Extended Real into Degrees/Minutes/Seconds
MaxI - Returns the minimum value between two Words.
MaxIArray - Returns the Maximum of an array of ShortInts
MaxL - Returns the minimum value between two Integers.
MaxLArray - Returns the Maximum of an array of Integers
MaxSArray - Returns the Minimum of an array of Extended Reals
MaxSI - Returns the minimum value between two Bytes.
MaxSIArray - Returns the Maximum of an array of Words
MaxW - Returns the minimum value between two ShortInts.
MaxWArray - Returns the Maximum of an array of Bytes
Min3Word - Returns the Maximum of 3 Words - BASM
Min4Word - Returns the Maximum of 4 Words - BASM
MinB - Returns the maximum value between two Bytes.
MinBArray - Returns the Maximum of an array of LongInts
MinCArray - Returns the Maximum of an array of Comp Reals
MinEArray - Returns the Maximum of an array of Extended Reals
MinExt - Returns the Maximum of two Extended Reals
MinI - Returns the maximum value between two Integers.
MinIArray - Returns the Minimum of an array of ShortInts
MinL - Returns the maximum value between two LongInts.
MinLArray - Returns the Minimum of an array of Integers
MinSArray - Returns the Maximum of an array of Single Reals
MinSI - Returns the maximum value between two ShortInts.
MinSIArray - Returns the Minimum of an array of Words
MinW - Returns the maximum value between two Words.
MinWArray - Returns the Minimum of an array of Bytes
Polar2XY - Returns X mod Y for Comp Data Types } {#Z+} {*** Conversions ***} {#Z-

Load '87 Control Word
SameFloat -
Set87ControlWord - Returns the 80x87 Control Word 15-12 Reserved On 8087/80287 12 was Infinity Control 0 Projective 1 Affine 11-10 Rounding Control 00 Round to nearest even 01 Round Down 10 Round Up 11 Chop - Truncate towards Zero 9-8 Precision Control 00 24 bits Single Precision 01 Reserved 10 53 bits Double Precision 11 64 bits Extended Precision (Default) 7-6 Reserved On 8087 7 was Interrupt Enable Mask 5 Precesion Exception Mask 4 Underflow Exception Mask 3 Overflow Exception Mask 2 Zero Divide Exception Mask 1 Denormalised Operand Exception Mask 0 Invalid Operation Exception Mask BASM

Leave in AX for function
Sgn - Sets the 80x87 Control Word 15-12 Reserved On 8087/80287 12 was Infinity Control 0 Projective 1 Affine 11-10 Rounding Control 00 Round to nearest even 01 Round Down 10 Round Up 11 Chop - Truncate towards Zero 9-8 Precision Control 00 24 bits Single Precision 01 Reserved 10 53 bits Double Precision 11 64 bits Extended Precision (Default) 7-6 Reserved On 8087 7 was Interrupt Enable Mask 5 Precesion Exception Mask 4 Underflow Exception Mask 3 Overflow Exception Mask 2 Zero Divide Exception Mask 1 Denormalised Operand Exception Mask 0 Invalid Operation Exception Mask BASM } {#Z+} {*** Misc Mathematical Routines ***} {#Z-
Sign - Swap Two LongInts.
SumBArray - Returns the Minimum of an array of LongInts

until square greater than argument
SumBArray2 - Returns the Sum of an array of Bytes.
SumCArray - Returns the Sum of an Array of Extended Reals
SumEArray - Returns the Sum of an Array of Single Reals
SumIArray - Returns the Sum of an array of Words.
SumLArray - Returns the Sum of an array of Integers.
SumSArray - Returns the Minimum of an array of Comp Reals
SumSIArray - Returns the Sum of an array of Bytes.
SumSIArray2 - Returns the Sum of an array of ShortInts.
SumWArray - Returns the Sum of an array of ShortInts.
SumWArray2 - Returns the Sum of an array of Words.
SwapB - Returns the minimum value between two LongInts.
SwapI - Swap Two Words.
SwapL - Swap Two Integers.
SwapSI - Swap Two Bytes.
SwapW - Swap Two ShortInts.
XY2Polar - Converts Polar Co-ordinates into Cartesion Co-ordinates

Types

TBitList

Constants

Variables

ESBTolerance


Functions


function CompMOD (const X, Y: Comp): Comp;

Performs Floating Point Remainder. ExtRem := X - Int ( X / Y ) * Y

procedure DecLim (var B: Byte; const Limit: Byte);

Increments a LongInt up to Limit. If B >= Limit no increment occurs.

procedure DecLimI (var B: Integer; const Limit: Integer);

Decrements a Word down to Limit. If B <= Limit no increment occurs.

procedure DecLimL (var B: LongInt; const Limit: LongInt);

Decrements an Integer down to Limit. If B <= Limit no increment occurs.

procedure DecLimSI (var B: ShortInt; const Limit: ShortInt);

Decrements a Byte down to Limit. If B <= Limit no increment occurs. BASM

procedure DecLimW (var B: Word; const Limit: Word);

Decrements a ShortInt down to Limit. If B <= Limit no increment occurs.

function Distance (const X1, Y1, X2, Y2: Extended): Extended;

Returns -1 if X < 0 0 if X = 0 1 if X > 0

function DMS2Extended (const Degs, Mins, Secs: Extended): Extended;

Converts Cartesian Co-ordinates to Polar Co-ordinates

procedure Extended2DMS (const X: Extended; var Degs, Mins, Secs: Extended);

Converts Degrees/Minutes/Seconds into an Extended Real

function ExtMod (const X, Y: Extended): Extended;

Returns the straight line Distance between (X1, Y1) and (X2, Y2)

function ExtRem (const X, Y: Extended): Extended;

Performs Floating Point Modulus. ExtMod := X - Floor ( X / Y ) * Y

Z now has Floor (X / Y


function FloatIsZero (const X: Extended): Boolean;

Returns True if X1 and X2 are within ESBTolerance of each other

function Get87ControlWord: TBitList;

ISqrt (I) computes INT (SQRT (I)), that is, the integral part of the square root of integer I. It does not check for negative arguments. For all arguments 0..MaxInt the correct result is returned. The algorithm exploits the following property: n n**2 = Sigma (2i-1) i=1 Routine by Norbert Joffa

procedure IncLim (var B: Byte; const Limit: Byte);

Returns True if X is within ESBTolerance of 0

Returns the Sum of an Array of Comp Reals


procedure IncLimI (var B: Integer; const Limit: Integer);

Increments a Word up to Limit. If B >= Limit no increment occurs.

procedure IncLimL (var B: LongInt; const Limit: LongInt);

Increments an Integer up to Limit. If B >= Limit no increment occurs.

procedure IncLimSI (var B: ShortInt; const Limit: ShortInt);

Increments a Byte up to Limit. If B >= Limit no increment occurs.

procedure IncLimW (var B: Word; const Limit: Word);

Increments a ShortInt up to Limit. If B >= Limit no increment occurs.

function ISqrt (const I: SmallInt): SmallInt;

Returns the Sum of an array of Longints. All Operation in Longints

function Max3Word (const X1, X2, X3: Word): Word;

Returns the Minimum of 4 Words - BASM

function Max4Word (const X1, X2, X3, X4: Word): Word;

Returns -1 if B < 0 0 if B = 0 1 if B > 0 BASM

function MaxB (const B1, B2: Byte): Byte;

Decrements a LongInt down to Limit. If B <= Limit no increment occurs.

function MaxBArray (const B: array of Byte): Byte;

Returns the Minimum of 3 Words - BASM

function MaxCArray (const B: array of Comp): Comp;

Returns the Minimum of an array of Single Reals

function MaxEArray (const B: array of Extended): Extended;

Returns the Minimum of two Extended Reals

function MaxExt (const X, Y: Extended): Extended;

Converts an Extended Real into Degrees/Minutes/Seconds

function MaxI (const B1, B2: Integer): Integer;

Returns the minimum value between two Words. BASM

function MaxIArray (const B: array of Integer): Integer;

Returns the Maximum of an array of ShortInts

function MaxL (const B1, B2: LongInt): LongInt;

Returns the minimum value between two Integers.

function MaxLArray (const B: array of LongInt): LongInt;

Returns the Maximum of an array of Integers

function MaxSArray (const B: array of Single): Single;

Returns the Minimum of an array of Extended Reals

function MaxSI (const B1, B2: ShortInt): ShortInt;

Returns the minimum value between two Bytes. BASM

function MaxSIArray (const B: array of ShortInt): ShortInt;

Returns the Maximum of an array of Words

function MaxW (const B1, B2: Word): Word;

Returns the minimum value between two ShortInts.

function MaxWArray (const B: array of Word): Word;

Returns the Maximum of an array of Bytes

function Min3Word (const X1, X2, X3: Word): Word;

Returns the Maximum of 3 Words - BASM

function Min4Word (const X1, X2, X3, X4: Word): Word;

Returns the Maximum of 4 Words - BASM

function MinB (const B1, B2: Byte): Byte;

Returns the maximum value between two Bytes. BASM

function MinBArray (const B: array of Byte): Byte;

Returns the Maximum of an array of LongInts

function MinCArray (const B: array of Comp): Comp;

Returns the Maximum of an array of Comp Reals

function MinEArray (const B: array of Extended): Extended;

Returns the Maximum of an array of Extended Reals

function MinExt (const X, Y: Extended): Extended;

Returns the Maximum of two Extended Reals

function MinI (const B1, B2: Integer): Integer;

Returns the maximum value between two Integers.

function MinIArray (const B: array of Integer): Integer;

Returns the Minimum of an array of ShortInts

function MinL (const B1, B2: LongInt): LongInt;

Returns the maximum value between two LongInts.

function MinLArray (const B: array of LongInt): LongInt;

Returns the Minimum of an array of Integers

function MinSArray (const B: array of Single): Single;

Returns the Maximum of an array of Single Reals

function MinSI (const B1, B2: ShortInt): ShortInt;

Returns the maximum value between two ShortInts.

function MinSIArray (const B: array of ShortInt): ShortInt;

Returns the Minimum of an array of Words

function MinW (const B1, B2: Word): Word;

Returns the maximum value between two Words. BASM

function MinWArray (const B: array of Word): Word;

Returns the Minimum of an array of Bytes

procedure Polar2XY (const Rho, Theta: Extended; var X, Y: Extended);

Returns X mod Y for Comp Data Types } {#Z+} {*** Conversions ***} {#Z-

Load '87 Control Word


function SameFloat (const X1, X2: Extended): Boolean;


procedure Set87ControlWord (const CWord: TBitList);

Returns the 80x87 Control Word 15-12 Reserved On 8087/80287 12 was Infinity Control 0 Projective 1 Affine 11-10 Rounding Control 00 Round to nearest even 01 Round Down 10 Round Up 11 Chop - Truncate towards Zero 9-8 Precision Control 00 24 bits Single Precision 01 Reserved 10 53 bits Double Precision 11 64 bits Extended Precision (Default) 7-6 Reserved On 8087 7 was Interrupt Enable Mask 5 Precesion Exception Mask 4 Underflow Exception Mask 3 Overflow Exception Mask 2 Zero Divide Exception Mask 1 Denormalised Operand Exception Mask 0 Invalid Operation Exception Mask BASM

Leave in AX for function


function Sgn (const X: Extended): ShortInt;

Sets the 80x87 Control Word 15-12 Reserved On 8087/80287 12 was Infinity Control 0 Projective 1 Affine 11-10 Rounding Control 00 Round to nearest even 01 Round Down 10 Round Up 11 Chop - Truncate towards Zero 9-8 Precision Control 00 24 bits Single Precision 01 Reserved 10 53 bits Double Precision 11 64 bits Extended Precision (Default) 7-6 Reserved On 8087 7 was Interrupt Enable Mask 5 Precesion Exception Mask 4 Underflow Exception Mask 3 Overflow Exception Mask 2 Zero Divide Exception Mask 1 Denormalised Operand Exception Mask 0 Invalid Operation Exception Mask BASM } {#Z+} {*** Misc Mathematical Routines ***} {#Z-

function Sign (const B: LongInt): ShortInt;

Swap Two LongInts. BASM - using Registers

function SumBArray (const B: array of Byte): Byte;

Returns the Minimum of an array of LongInts

until square greater than argument


function SumBArray2 (const B: array of Byte): Word;

Returns the Sum of an array of Bytes. All Operation in Bytes

function SumCArray (const B: array of Comp): Comp;

Returns the Sum of an Array of Extended Reals

function SumEArray (const B: array of Extended): Extended;

Returns the Sum of an Array of Single Reals

function SumIArray (const B: array of Integer): Integer;

Returns the Sum of an array of Words. All Operation in Longints

function SumLArray (const B: array of LongInt): LongInt;

Returns the Sum of an array of Integers. All Operation in Integers

function SumSArray (const B: array of Single): Single;

Returns the Minimum of an array of Comp Reals

function SumSIArray (const B: array of ShortInt): ShortInt;

Returns the Sum of an array of Bytes. All Operation in Words

function SumSIArray2 (const B: array of ShortInt): Integer;

Returns the Sum of an array of ShortInts. All Operation in ShortInts

function SumWArray (const B: array of Word): Word;

Returns the Sum of an array of ShortInts. All Operation in Integers

function SumWArray2 (const B: array of Word): LongInt;

Returns the Sum of an array of Words. All Operation in Words

procedure SwapB (var B1, B2: Byte);

Returns the minimum value between two LongInts.

procedure SwapI (var B1, B2: SmallInt);

Swap Two Words. BASM - using Registers

procedure SwapL (var B1, B2: LongInt);

Swap Two Integers. BASM - using Registers

procedure SwapSI (var B1, B2: ShortInt);

Swap Two Bytes. BASM - using Registers

procedure SwapW (var B1, B2: Word);

Swap Two ShortInts. BASM - using Registers

procedure XY2Polar (const X, Y: Extended; var Rho, Theta: Extended);

Converts Polar Co-ordinates into Cartesion Co-ordinates

Types


TBitList = Word
{$DEFINE UseMath} // comment out this line if you don't want to use the Delphi Math Library Desktop versions of Delphi do not include the Math Library

Constants


Variables

ESBTolerance : Double = 0.00001

Used for a Bit List of 16 bits from 15 -> 0