const
{$IFDEF PAIDVERS}
SDLVersionInfo = 'math1_r1210_full';
IsLightEd = false;
{$ELSE}
SDLVersionInfo = 'math1_r1210_lighted';
IsLightEd = true;
{$ENDIF}
Release = 1210;
type
ESDLMath1Error = class(ESDLError); { exception type to indicate errors }
{$IFDEF GE_LEV29}
[ComponentPlatformsAttribute(pidWin32 or pidWin64 or pidWin64x)]
{$ENDIF}
TKahanSum = class (TComponent)
private
cps : double; // compensation variable
public
Sum : double;
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure Reset;
procedure Add (ANumber: double);
end;
function AngleToXAxis
(x,y : double) { coordinates of data point }
: double; { angle between data point, origin and x-axis }
function Bin
(innum : longint; { number to convert to binary string }
places : byte) { number of places }
: string; { binary number }
function BitReversal
(InByte : byte) { input byte }
: byte; { bit-reversed byte }
function BRandom
(p : double) { probability }
: boolean; { TRUE with probability p }
procedure CalcScalePars
(Ntick : integer; { number of ticks on scale }
LowVal, { beginning of scaling }
HighVal : extended; { end point of scaling }
var LowTick, { first tick on scale }
Distance : extended; { distance of scale ticks }
var Divi : word); { nr. of divisions between scaling labels }
procedure CancelFraction
(var numer, { numerator of fraction }
denom : integer); { denominator of fraction }
function CanonicalAngleRadians
(phi : double) { angle in radians }
: double; { canonical angle in the range -Pi to +Pi }
function CanonicalAngleDegrees
(phi : double) { angle in degrees }
: double; { canonical angle in the range -180 to +180 }
function CcwTriangle
(p1, p2, p3 : TPointDouble) { the corners of a triangle }
: integer; { test for counter-clockwise points }
function CenteredPolynomial
(Coeff : array of double; { coefficients of the polynomial }
NOrd : integer; { order of the polynomial }
XShift : double; { x position of polynomial center }
X : double) { argument }
: double; { value of the polynomial at X }
function CheckPowerOfTwo
(AInt : longword) { number to check }
: boolean; { TRUE if AInt is a power of 2 }
function ConfinePointToRect
(var Point : TPointDouble; { point to be checked }
BoundRect : TRectDouble) { confining rectangle }
: boolean; { TRUE if point has been corrected }
function ConfineValue
(Inval : double; { value to check and confine }
Boundary1 : double; { boundary 1 of interval }
Boundary2 : double) { boundary 2 of interval }
: double; overload { confined value }
function ConfineValue
(Inval : single; { value to check and confine }
Boundary1 : single; { boundary 1 of interval }
Boundary2 : single) { boundary 2 of interval }
: single; overload { confined value }
function ConfineValue
(Inval : integer; { value to check and confine }
Boundary1 : integer; { boundary 1 of interval }
Boundary2 : integer) { boundary 2 of interval }
: integer; overload { confined value }
procedure ConvertDegrees
(var deg, min, sec : double; { degrees, minutes, and seconds to convert }
InFormat, { input format }
OutFormat : TDegreeFormat); { output format }
{$IFNDEF DOTNET}
function ConvertEndian
(value : double) { big/little endian input }
: double; overload; { little/big endian output }
function ConvertEndian
(value : single) { big/little endian input }
: single; overload; { little/big endian output }
function ConvertEndian
(value : integer) { big/little endian input }
: integer; overload; { little/big endian output }
function ConvertEndian
(value : word) { big/little endian input }
: word; overload; { little/big endian output }
{$ENDIF}
function cosh
(x : double) { angle in radians }
: double; { hyperbolic cosine }
function cot
(x : double) { angle in radians }
: double; { cotangens }
function CountBits
(InByte : byte) { byte to count bits in }
: integer; { number of bits }
function CRandom
(loc, wid : double) { location and width of Cauchy distribution }
: double; { Cauchy-distributed random variable}
function Decimal
(innum : longint; { number to convert to decimal string }
places : byte) { number of places }
: string; { decimal string with leading 0s }
function DecodeBit
(ix : integer) { number of bit (0..7) }
: byte; { byte holding decoded bit }
function DecodeLong
(ix : integer) { number of bit (0..31) }
: longint; { longint holding decoded bit }
function DegreeToStr
(innum : double; { value to be converted }
format : TDegreeFormat; { format of output }
precision : integer) { number of decimal places }
: string; { deg/min/sec notation }
function DistanceToSegment
(TestPoint, { coordinates of the test point }
SegP1, SegP2 : TPointDouble) { endpoints of the segment }
: double; { distance to the segment }
function DistFromEllipse
(RefPos : TPointDouble; { coordinates of reference point }
CentX, CentY, { coordinates of center of the ellipse }
HorizAxLeng, { half-length of the horizontal axis }
VertAxLeng : double; { half-length of the vertical axis }
var CloseP : TPointDouble) { coordinates of the closest point }
: double; { distance from the ellipse }
function DistFromRect
(RefPos : TPoint; { coordinates of reference point }
Rectangle : TRect) { coordinates of rectangle }
: integer; { distance from nearest rectangle side }
function EEngStr
(innum : double; { value to be converted }
precision : integer) { number of significant digits }
: string; { electrical engineering notation }
function EncodeLong
(value : longint) { longint holding decoded bit }
: integer; { number of bit (0..31) }
function EuclideanDistance
(x1,y1,x2,y2 : double) { coordinates of the two points }
: double; overload; { Euclidean distance }
function EuclideanDistance
(P1, P2 : TPointDouble) { two points }
: double; overload; { Euclidean distance between points }
{$IFNDEF DOTNET}
procedure ExChange
(var x,y; { pair of variables, untyped }
size : word); overload; { length of variable }
{$ENDIF}
procedure ExChange
(var x,y : integer); overload; { variables to exchange }
procedure ExChange
(var x,y : byte); overload; { variables to exchange }
procedure ExChange
(var x,y : single); overload; { variables to exchange }
procedure ExChange
(var x,y : double); overload; { variables to exchange }
procedure ExChange
(var x,y : extended); overload; { variables to exchange }
procedure ExChange
(var x,y : string); overload; { variables to exchange }
procedure ExChange
(var x,y : char); overload; { variables to exchange }
procedure ExChange
(var x,y : boolean); overload; { variables to exchange }
{$IFDEF DOTNET}
procedure ExChange
(var x,y : AnsiChar); overload; { variables to exchange }
{$ENDIF}
procedure ExChange
(var x,y : ShortInt); overload; { variables to exchange }
procedure ExChange
(var x,y : Word); overload; { variables to exchange }
procedure ExChange
(var x,y : Cardinal); overload; { variables to exchange }
procedure ExChange
(var x,y : Int64); overload; { variables to exchange }
{$IFDEF GELEV7}
procedure ExChange
(var x,y : UInt64); overload; { variables to exchange }
{$ENDIF}
function Factorial
(argument : integer) { function argument }
: extended; { factorial of argument }
function FindPrimeFactors
(number : integer) { number to be analyzed }
: TIntArray; { list of prime factors }
function GRandom
: double; { Gaussian noise }
function GrayCode
(InNum : word) { number to convert }
: word; { Gray code of 'InNum' }
function Hex
(innum : longint; { number to convert to hex string }
places : byte) { number of places }
: string; { hexadecimal notation }
{$IFNDEF DOTNET}
function FPNumToHex
(innum : double) { number to convert to hex string }
: string; overload; { hexadecimal notation }
{$IFDEF WIN32}
function FPNumToHex
(innum : extended) { number to convert to hex string }
: string; overload; { hexadecimal notation }
{$ENDIF}
function FPNumToHex
(innum : single) { number to convert to hex string }
: string; overload; { hexadecimal notation }
function GreatestCommonDivisor
(v1, v2 : integer) { values to be processed }
: integer; overload; { greatest common divisor }
function GreatestCommonDivisor
(v1, v2 : double; { values to be processed }
Precision : integer) { number of decimal places to include }
: double; overload; { greatest common divisor }
function GreatestCommonDivisor
(values : TDoubleArray; { values to be processed }
Precision : integer) { number of decimal places to include }
: double; overload; { greatest common divisor }
function GreatestCommonDivisor
(values : TIntArray) { values to be processed }
: integer; overload; { greatest common divisor }
function HexToDouble
(instr : string) { hex string of 16 chars }
: double; overload;
function HexToDouble
(instr : string; { hex string of 16 chars }
bigendian : boolean) { endianess of string }
: double; overload;
function HexToSingle
(instr : string) { hex string of 8 chars }
: single; overload;
function HexToSingle
(instr : string; { hex string of 16 chars }
bigendian : boolean) { endianess of string }
: single; overload;
{$IFDEF WIN32}
function HexToExtended
(instr : string) { hex string of 20 chars }
: extended;
{$ENDIF}
function HistoBinRef
(XValue, { x value }
FirstBin, { reference value of first bin }
BinWidth : double; { bin width }
var resid : double) { residual }
: double; { corresponding histogram bin reference value }
procedure InsertIntoArray
(ArrayAdr : pointer; { pointer to array }
LengArray : longint; { length of array }
TypArray : TVarKind; { type of field }
value : pointer; { value to put into array }
index : longint); overload; { index }
{$ENDIF}
function InterpolTable
(Arg : double; { argument }
RangeLo, { argument of first pivot point }
RangeHi : double; { argument of last pivot point }
const Pivots : TDoubleArray) { array of regularly spaced pivots }
: double; overload; { interpolated value at the argument }
function InterpolTable
(Arg : double; { argument }
RangeLo, { argument of first pivot point }
RangeHi : double; { argument of last pivot point }
const Pivots : TIntArray) { array of regularly spaced pivots }
: double; overload; { interpolated value at the argument }
function InterpolXYTable
(arg : double; { argument }
const XYPivots : TDouble2DArray; { array of irregularly spaced pivots }
Extrapolate : boolean) { TRUE: out-of-range values are extrapolated}
: double; { interpolated value at the argument }
function InterpolZofXYRect
(z00,z01,
z10,z11 : double; { heights at corner points }
frac1,
frac2 : double): double; { fraction along x,y }
function IntPos
(InNum : double) { number to process }
: longint; { next integer greater/equal to InNum }
function IntNeg
(InNum : double) { number to process }
: longint; { next integer smaller/equal to InNum }
function IsPrime
(number : integer) { number to test for prime }
: boolean; { returns TRUE if number is prime }
function IsValidBin
(Instring : string) { string to test for validity }
: boolean; { TRUE if string is valid binary number }
function IsValidDecInt
(Instring : string) { string to test for validity }
: boolean; { TRUE if string is valid decimal number }
function IsValidDouble
(InString : string; { string to test for validity }
AllowExp : boolean; { TRUE: allow exponential notation }
DecSeparator : TDecPSep) { decimal separator }
: boolean; { returns TRUE if string is valid f.p. number }
function IsValidFPNum
(Instring : string; { string to test for validity }
DecSeparator : TDecPSep) { decimal separator }
: boolean; { TRUE if string is valid float. point number }
function IsValidHex
(Instring : string) { string to test for validity }
: boolean; { TRUE if string is valid hex number }
function IsValidOct
(Instring : string) { string to test for validity }
: boolean; { TRUE if string is valid octal number }
function lg
(x : double) { argument }
: double; { common logarithm }
function ld
(x : double) { argument }
: double; { logarithmus dualis }
function ListOfPrimes
(ix : integer) { index into list of primes }
: integer; { prime number taken from list }
function LongRand
(seed : longint) { if not equal 0 then init }
: double; { random value [0.0,1.0] }
function MakeEFormat
(x : double; { number to convert }
w,d : integer) { width, decimal places }
: string; { string in FORTRAN format }
function modr
(value : double; { value to be divided }
divisor : double) { divisor }
: double; { remainder }
function Octal
(innum : longint; { nr. to convert to octal string }
places : byte) { number of places }
: string; { octal notation }
function Polynomial
(Coeff : array of double; { coefficients of the polynomial }
NOrd : integer; { order of the polynomial }
X : double) { argument }
: double; { value of the polynomial at X }
function ProductConsecInts
(First, Last : integer){first and last number of concecutive integers }
: int64; { product }
function QuickSelect
(var Data : array of double; { data array to be analyzed }
k : integer; { k-th order statistic }
First, Last : integer) { range of data to be processed }
: double; overload; { value of the k-th smallest element }
function QuickSelect
(var Data : array of double; { data array to be analyzed }
k : integer; { k-th order statistic }
First, Last : integer; { range of data to be processed }
AbundantVal : double) { most abundant value }
: double; overload; { value of the k-th smallest element }
function Roman
(InNum : longint) { number to convert }
: string; { roman number }
function Round125
(InNum : double) { number to be rounded }
: double; { nearest number in the 1-2-5 system }
procedure RoundDegrees
(var Deg, { degrees }
Min, { minutes }
Sec : integer; { seconds }
RoundUp : boolean); { TRUE: round up, FALSE: round down }
function RoundLimit
(Value : double; { value to be rounded }
Min, Max : int64) { allowed minimum and maximum }
: int64; { rounded integer }
function RoundNeg125
(InNum : double) { number to be rounded }
: double; { number in the 125 system smaller/equal InNum }
function RoundPos125
(InNum : double) { number to be rounded }
: double; { number in the 125 system greater/equal InNum }
function ScanBin
(Instring : string; { string containing binary number }
var Idx : integer) { starting position of binary decoding }
: longint; { result }
function ScanDateTime
(InString, { string containing the date/time }
Format : string; { format of the date/time string }
Language : TLanguage; { language used }
var error : integer) { error flag }
: TDateTime; { result returns TDateTime of Instring }
function ScanDecimal
(Instring : string; { string containing decimal number }
var Idx : integer) { starting position of decimal decoding }
: longint; { result }
function ScanDegrees
(InString : string; { string containing the degrees }
var Idx : integer; { starting position of deg decoding }
ExpectGeo : boolean; { TRUE: geographic direction is expected }
var Error : integer) { error flag }
: double; { result returns degrees of Instring }
function ScanFPNum
(Instring : string; { string with floating point number }
AllowExp : boolean; { TRUE: allow exponential notation }
DecPChar : integer; { dec. point character }
var Idx : integer) { starting position of decimal decoding }
: double; { result }
function ScanHex
(Instring : string; { string containing hexadecimal number }
var Idx : integer) { starting position of hex decoding }
: longint; { result }
function ScanOctal
(Instring : string; { string containing octal number }
var Idx : integer) { starting position of octal decoding }
: longint; { result }
function SegmentsIntersect
(Seg1P1,Seg1P2, { endpoints of segment 1 }
Seg2P1,Seg2P2 : TpointDouble) { endpoints of segment 2 }
: boolean; { TRUE: segments intersect }
function Signum
(a : double) { input variable }
: integer; { signum(a) }
function sinh
(x : double) { angle in radians }
: double; { sinus hyperbolicus }
{$IFNDEF DOTNET}
procedure SortArray
(ArrayAdr : pointer; { pointer to array }
LengArray : longint; { length of array }
TypArray : TVarKind; { type of array }
Ascending : boolean); overload; { TRUE = ascending }
function SortIntoArray
(ArrayAdr : pointer; { pointer to array }
LengArray : longint; { length of array }
TypArray : TVarKind; { type of array }
value : pointer; { value to sort into }
Ascending : boolean; { TRUE = ascending }
Duplicates : boolean) { TRUE = duplicates allowed }
: longint; overload; { index of value }
{$ENDIF}
{$IFDEF LEVEL5} // Delphi 5 has bug with overloaded variable dynamic arrays
function SortIntoArrayInteger
(var SArray : array of integer;
value : integer;
Ascending : boolean;
Duplicates : boolean)
: longint;
function SortIntoArraySingle
(var SArray : array of single;
value : single;
Ascending : boolean;
Duplicates : boolean)
: longint;
function SortIntoArrayDouble
(var SArray : array of double;
value : double;
Ascending : boolean;
Duplicates : boolean)
: longint;
{$ELSE}
function SortIntoArray
(var SArray : array of integer;
value : integer;
Ascending : boolean;
Duplicates : boolean)
: longint; overload;
function SortIntoArray
(var SArray : array of single;
value : single;
Ascending : boolean;
Duplicates : boolean)
: longint; overload;
function SortIntoArray
(var SArray : array of double;
value : double;
Ascending : boolean;
Duplicates : boolean)
: longint; overload;
{$ENDIF}
function SortSwap
(var v1, v2 : double; { variables to be exchanged }
Ascending : boolean) { sort order }
: boolean; { TRUE if a swap occurred }
{$IFDEF LEVEL5} // Delphi 5 has bug with overloaded variable dynamic arrays
procedure InsertIntoArraySingle
(var SArray : array of single;
value : single;
index : longint);
procedure InsertIntoArrayDouble
(var SArray : array of double;
value : double;
index : longint);
procedure InsertIntoArrayInteger
(var SArray : array of integer;
value : integer;
index : longint);
{$ELSE}
procedure InsertIntoArray
(var SArray : array of single;
value : single;
index : longint); overload;
procedure InsertIntoArray
(var SArray : array of double;
value : double;
index : longint); overload;
procedure InsertIntoArray
(var SArray : array of integer;
value : integer;
index : longint); overload;
{$ENDIF}
{$IFDEF LEVEL5} // Delphi 5 has bug with overloaded variable dynamic arrays
procedure SortArrayDouble
(var SArray : array of double; { array to be sorted }
Ascending : boolean); { TRUE = ascending }
procedure SortArraySingle
(var SArray : array of single; { array to be sorted }
Ascending : boolean); { TRUE = ascending }
procedure SortArrayInteger
(var SArray : array of integer; { array to be sorted }
Ascending : boolean); { TRUE = ascending }
{$ELSE}
procedure SortArray
(var SArray : array of double; { array to be sorted }
Ascending : boolean); overload; { TRUE = ascending }
procedure SortArray
(var SArray : array of single; { array to be sorted }
Ascending : boolean); overload; { TRUE = ascending }
procedure SortArray
(var SArray : array of integer; { array to be sorted }
Ascending : boolean); overload; { TRUE = ascending }
{$ENDIF}
function Squash
(x : double; { argument }
offset : double; { offset along argument axis }
slope : double; { slope }
amplitude : double) { amplitude }
: double; { sigmoid function result }
function strf
(r : double; { number to convert }
FieldWidth : integer; { width of output field }
DecP : integer) { number of dec. places }
: string; { formatted string }
function StrToIntDefault
(InStr : string; { input string to be converted }
Def : integer) { default value if conversion fails }
: integer; { converted value }
function tg
(x : double) { angle in radians }
: double; { tangens }
function tgh
(x : double) { angle in radians }
: double; { tangens hyperbolicus }
function WithinBounds
(Inval : double; { value to compare }
Boundary1 : double; { boundary 1 of interval }
Boundary2 : double) { boundary 2 of interval }
: boolean; overload; { TRUE if Inval within bounds }
function WithinBounds
(Inval : double; { value to compare }
Boundary1 : double; { boundary 1 of interval }
Boundary2 : double; { boundary 2 of interval }
Margin : double) { margin to be added to the boundaries }
: boolean; overload; { TRUE if Inval within bounds }
function WithinRect
(Point : TPointDouble; { position to check }
BoundRect : TRectDouble) { bounding rectangle }
: boolean; { TRUE if point is within rectangle }
|