当前位置:文档之家› delphi数学模块函数、过程大全

delphi数学模块函数、过程大全

function ArcCos(const X : Extended) : Extended; overload;function ArcCos(const X : Double) : Double; overload;function ArcCos(const X : Single) : Single; overload;function ArcSin(const X : Extended) : Extended; overload;function ArcSin(const X : Double) : Double; overload;function ArcSin(const X : Single) : Single; overload;function ArcTan2(const Y, X: Extended): Extended;procedure SinCos(const Theta: Extended; var Sin, Cos: Extended) register;function Tan(const X: Extended): Extended;function Cotan(const X: Extended): Extended; { 1 / tan(X), X <> 0 }function Secant(const X: Extended): Extended; { 1 / cos(X) }function Cosecant(const X: Extended): Extended; { 1 / sin(X) }function Hypot(const X, Y: Extended): Extended; { Sqrt(X**2 + Y**2) }function RadToDeg(const Radians: Extended): Extended; inline; { Degrees := Radians * 180 / PI }function RadToGrad(const Radians: Extended): Extended; inline; { Grads := Radians * 200 / PI }function RadToCycle(const Radians: Extended): Extended; inline; { Cycles := Radians / 2PI } function DegToRad(const Degrees: Extended): Extended; inline; { Radians := Degrees * PI / 180}function DegToGrad(const Degrees: Extended): Extended;function DegToCycle(const Degrees: Extended): Extended;function GradToRad(const Grads: Extended): Extended; inline; { Radians := Grads * PI / 200 }function GradToDeg(const Grads: Extended): Extended;function GradToCycle(const Grads: Extended): Extended;function CycleToRad(const Cycles: Extended): Extended; inline; { Radians := Cycles * 2PI } function CycleToDeg(const Cycles: Extended): Extended;function CycleToGrad(const Cycles: Extended): Extended;{ Hyperbolic functions and inverses }function Cot(const X: Extended): Extended; inline; { alias for Cotan }function Sec(const X: Extended): Extended; inline; { alias for Secant }function Csc(const X: Extended): Extended; inline; { alias for Cosecant }function Cosh(const X: Extended): Extended;function Sinh(const X: Extended): Extended;function Tanh(const X: Extended): Extended;function CotH(const X: Extended): Extended; inline;function SecH(const X: Extended): Extended; inline;function CscH(const X: Extended): Extended; inline;function ArcCot(const X: Extended): Extended; { IN: X <> 0 }function ArcSec(const X: Extended): Extended; { IN: X <> 0 }function ArcCsc(const X: Extended): Extended; { IN: X <> 0 }function ArcCosh(const X: Extended): Extended; { IN: X >= 1 }function ArcSinh(const X: Extended): Extended;function ArcTanh(const X: Extended): Extended; { IN: |X| <= 1 }function ArcCotH(const X: Extended): Extended; { IN: X <> 0 }function ArcSecH(const X: Extended): Extended; { IN: X <> 0 }function ArcCscH(const X: Extended): Extended; { IN: X <> 0 }{ Logarithmic functions }function LnXP1(const X: Extended): Extended; { Ln(X + 1), accurate for X near zero } function Log10(const X: Extended): Extended; { Log base 10 of X } function Log2(const X: Extended): Extended; { Log base 2 of X } function LogN(const Base, X: Extended): Extended; { Log base N of X } { Exponential functions }{ IntPower: Raise base to an integral power. Fast. }function IntPower(const Base: Extended; const Exponent: Integer): Extended register;{ Power: Raise base to any power.For fractional exponents, or |exponents| > MaxInt, base must be > 0. }function Power(const Base, Exponent: Extended): Extended; overload;function Power(const Base, Exponent: Double): Double; overload;function Power(const Base, Exponent: Single): Single; overload;{ Miscellaneous Routines }{ Frexp: Separates the mantissa and exponent of X. }procedure Frexp(const X: Extended; var Mantissa: Extended; var Exponent: Integer) register; { Ldexp: returns X*2**P }function Ldexp(const X: Extended; const P: Integer): Extended register;{ Ceil: Smallest integer >= X, |X| < MaxInt }function Ceil(const X: Extended):Integer;{ Floor: Largest integer <= X, |X| < MaxInt }function Floor(const X: Extended): Integer;function Sum(const Data: array of Double): Extended register;function SumInt(const Data: array of Integer): Integer register;function SumOfSquares(const Data: array of Double): Extended;procedure SumsAndSquares(const Data: array of Double;var Sum, SumOfSquares: Extended) register;{ MinValue: Returns the smallest signed value in the data array (MIN) }function MinValue(const Data: array of Double): Double;function MinIntValue(const Data: array of Integer): Integer;function Min(const A, B: Integer): Integer; overload; inline;function Min(const A, B: Int64): Int64; overload; inline;function Min(const A, B: Single): Single; overload; inline;function Min(const A, B: Double): Double; overload; inline;function Min(const A, B: Extended): Extended; overload; inline;{ MaxValue: Returns the largest signed value in the data array (MAX) }function MaxValue(const Data: array of Double): Double;function MaxIntValue(const Data: array of Integer): Integer;function Max(const A, B: Integer): Integer; overload; inline;function Max(const A, B: Int64): Int64; overload; inline;function Max(const A, B: Single): Single; overload; inline;function Max(const A, B: Double): Double; overload; inline;function Max(const A, B: Extended): Extended; overload; inline;{ Standard Deviation (STD): Sqrt(Variance). aka Sample Standard Deviation }function StdDev(const Data: array of Double): Extended;{ MeanAndStdDev calculates Mean and StdDev in one call. }procedure MeanAndStdDev(const Data: array of Double; var Mean, StdDev: Extended);{ Population Standard Deviation (STDP): Sqrt(PopnVariance).Used in some business and financial calculations. }function PopnStdDev(const Data: array of Double): Extended;{ Variance (V ARS): TotalVariance / (N-1). aka Sample Variance }function Variance(const Data: array of Double): Extended;{ Population Variance (V AR or V ARP): TotalVariance/ N }function PopnVariance(const Data: array of Double): Extended;{ Total Variance: SUM(i=1,N)[(X(i) - Mean)**2] }function TotalVariance(const Data: array of Double): Extended;{ Norm: The Euclidean L2-norm. Sqrt(SumOfSquares) }function Norm(const Data: array of Double): Extended;procedure MomentSkewKurtosis(const Data: array of Double;var M1, M2, M3, M4, Skew, Kurtosis: Extended);{ RandG produces random numbers with Gaussian distribution about the mean.Useful for simulating data with sampling errors. }function RandG(Mean, StdDev: Extended): Extended;function IsNan(const AValue: Double): Boolean; overload;function IsNan(const AValue: Single): Boolean; overload;function IsNan(const AValue: Extended): Boolean; overload;function IsInfinite(const A Value: Double): Boolean;function Sign(const A Value: Integer): TValueSign; overload;function Sign(const A Value: Int64): TValueSign; overload;function Sign(const A Value: Double): TValueSign; overload;function CompareValue(const A, B: Extended; Epsilon: Extended = 0): TValueRelationship; overload;function CompareValue(const A, B: Double; Epsilon: Double = 0): TValueRelationship; overload; function CompareValue(const A, B: Single; Epsilon: Single = 0): TValueRelationship; overload; function CompareValue(const A, B: Integer): TValueRelationship; overload;function CompareValue(const A, B: Int64): TValueRelationship; overload;function SameValue(const A, B: Extended; Epsilon: Extended = 0): Boolean; overload;function SameValue(const A, B: Double; Epsilon: Double = 0): Boolean; overload;function SameValue(const A, B: Single; Epsilon: Single = 0): Boolean; overload;{ IsZero: These will return true if the given value is zero (or very very veryclose to it). }function IsZero(const A: Extended; Epsilon: Extended = 0): Boolean; overload;function IsZero(const A: Double; Epsilon: Double = 0): Boolean; overload;function IsZero(const A: Single; Epsilon: Single = 0): Boolean; overload;{ Easy to use conditional functions }function IfThen(AValue: Boolean; const A True: Integer; const AFalse: Integer = 0): Integer; overload;function IfThen(A Value: Boolean; const A True: Int64; const AFalse: Int64 = 0): Int64; overload; function IfThen(A Value: Boolean; const ATrue: Double; const AFalse: Double = 0.0): Double; overload;{ Various random functions }function RandomRange(const AFrom, ATo: Integer): Integer;function RandomFrom(const A Values: array of Integer): Integer; overload;function RandomFrom(const A Values: array of Int64): Int64; overload;function RandomFrom(const A Values: array of Double): Double; overload;{ Range testing functions }function InRange(const A Value, AMin, AMax: Integer): Boolean; overload;function InRange(const A Value, AMin, AMax: Int64): Boolean; overload;function InRange(const A Value, AMin, AMax: Double): Boolean; overload;{ Range truncation functions }function EnsureRange(const A Value, AMin, AMax: Integer): Integer; overload;function EnsureRange(const A Value, AMin, AMax: Int64): Int64; overload;function EnsureRange(const A Value, AMin, AMax: Double): Double; overload;{ 16 bit unsigned integer division and remainder in one operation }procedure DivMod(Dividend: Cardinal; Divisor: Word;var Result, Remainder: Word);function RoundTo(const A Value: Double; const ADigit: TRoundToRange): Double;function SimpleRoundTo(const A V alue: Double; const ADigit: TRoundToRange = -2): Double; function DoubleDecliningBalance(const Cost, Salvage: Extended;Life, Period: Integer): Extended;function FutureValue(const Rate: Extended; NPeriods: Integer; const Payment, PresentValue: Extended; PaymentTime: TPaymentTime): Extended;function InterestPayment(const Rate: Extended; Period, NPeriods: Integer;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended; function InterestRate(NPeriods: Integer; const Payment, PresentValue,FutureValue: Extended; PaymentTime: TPaymentTime): Extended;function InternalRateOfReturn(const Guess: Extended;const CashFlows: array of Double): Extended;{ Number of Periods (NPER) }function NumberOfPeriods(const Rate: Extended; Payment: Extended;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;{ Net Present Value. (NPV) Needs array of cash flows. }function NetPresentValue(const Rate: Extended; const CashFlows: array of Double; PaymentTime: TPaymentTime): Extended;{ Payment (PAYMT) }function Payment(Rate: Extended; NPeriods: Integer; const PresentValue,FutureValue: Extended; PaymentTime: TPaymentTime): Extended;{ Period Payment (PPAYMT) }function PeriodPayment(const Rate: Extended; Period, NPeriods: Integer;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended; { Present Value (PV AL) }function PresentValue(const Rate: Extended; NPeriods: Integer;const Payment, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;{ Straight Line depreciation (SLN) }function SLNDepreciation(const Cost, Salvage: Extended; Life: Integer): Extended;{ Sum-of-Years-Digits depreciation (SYD) }function SYDDepreciation(const Cost, Salvage: Extended; Life, Period: Integer): Extended; function GetRoundMode: TFPURoundingMode;{ Set the rounding mode and return the old mode }function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode; function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode; function GetExceptionMask: TFPUExceptionMask;{ Set a new exception mask and return the old one }function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;{ Clear any pending exception bits in the status word }procedure ClearExceptions(RaisePending: Boolean = True);function RoundTo(const A Value: Double; const ADigit: TRoundToRange): Double;function SimpleRoundTo(const A V alue: Double; const ADigit: TRoundToRange = -2): Double; function Annuity2(const R: Extended; N: Integer; PaymentTime: TPaymentTime;var CompoundRN: Extended): Extended; Forward;function Compound(const R: Extended; N: Integer): Extended; Forward;function RelSmall(const X, Y: Extended): Boolean; Forward;procedure ArgError(const Msg: string);function DegToRad(const Degrees: Extended): Extended; { Radians := Degrees * PI / 180 } function RadToDeg(const Radians: Extended): Extended; { Degrees := Radians * 180 / PI } function GradToRad(const Grads: Extended): Extended; { Radians := Grads * PI / 200 } function RadToGrad(const Radians: Extended): Extended; { Grads := Radians * 200 / PI} function CycleToRad(const Cycles: Extended): Extended; { Radians := Cycles * 2PI } function RadToCycle(const Radians: Extended): Extended;{ Cycles := Radians / 2PI } function DegToGrad(const Degrees: Extended): Extended;function DegToCycle(const Degrees: Extended): Extended;function GradToDeg(const Grads: Extended): Extended;function GradToCycle(const Grads: Extended): Extended;function CycleToDeg(const Cycles: Extended): Extended;function CycleToGrad(const Cycles: Extended): Extended;function LnXP1(const X: Extended): Extended;function IntPower(const Base: Extended; const Exponent: Integer): Extended;function Compound(const R: Extended; N: Integer): Extended;{ Return (1 + R)**N. }procedure PolyX(const A: array of Double; X: Extended; var Poly: TPoly);{ Compute A[0] + A[1]*X + ... + A[N]*X**N and X * its derivative.Accumulate positive and negative terms separately. }function RelSmall(const X, Y: Extended): Boolean;function ArcCos(const X : Extended) : Extended; overload;function ArcCos(const X : Double) : Double; overload;function ArcCos(const X : Single) : Single; overload;function ArcSin(const X : Extended) : Extended; overload;function ArcSin(const X : Double) : Double; overload;function ArcSin(const X : Single) : Single; overload;function ArcTan2(const Y, X: Extended): Extended;function Tan(const X: Extended): Extended;{ Tan := Sin(X) / Cos(X) }function CoTan(const X: Extended): Extended;{ CoTan := Cos(X) / Sin(X) = 1 / Tan(X) }function Secant(const X: Extended): Extended;{ Secant := 1 / Cos(X) }function Cosecant(const X: Extended): Extended;{ Cosecant := 1 / Sin(X) }function Hypot(const X, Y: Extended): Extended;{ formula: Sqrt(X*X + Y*Y)implemented as: |Y|*Sqrt(1+Sqr(X/Y)), |X| < |Y| for greater precisionvarTemp: Extended;beginX := Abs(X);Y := Abs(Y);if X > Y thenbeginTemp := X;X := Y;Y := Temp;end;if X = 0 thenResult := Yelse // Y > X, X <> 0, so Y > 0Result := Y * Sqrt(1 + Sqr(X/Y));end;}procedure SinCos(const Theta: Extended; var Sin, Cos: Extended);{ Extract exponent and mantissa from X }procedure Frexp(const X: Extended; var Mantissa: Extended; var Exponent: Integer); { Mantissa ptr in EAX, Exponent ptr in EDX }function Ldexp(const X: Extended; const P: Integer): Extended;{ Result := X * (2^P) }function Ceil(const X: Extended): Integer;function Log10(const X: Extended): Extended;{ Log.10(X) := Log.2(X) * Log.10(2) }function LogN(const Base, X: Extended): Extended;{ Log.N(X) := Log.2(X) / Log.2(N) }function Poly(const X: Extended; const Coefficients: array of Double): Extended; function Power(const Base, Exponent: Extended): Extended;function Power(const Base, Exponent: Double): Double; overload;function Power(const Base, Exponent: Single): Single; overload;function Cosh(const X: Extended): Extended;function Sinh(const X: Extended): Extended;function Tanh(const X: Extended): Extended;function ArcCosh(const X: Extended): Extended;function ArcSinh(const X: Extended): Extended;function ArcTanh(const X: Extended): Extended;function Cot(const X: Extended): Extended;function Sec(const X: Extended): Extended;function Csc(const X: Extended): Extended;function CotH(const X: Extended): Extended;function SecH(const X: Extended): Extended;function CscH(const X: Extended): Extended;function ArcCot(const X: Extended): Extended;function ArcSec(const X: Extended): Extended;function ArcCsc(const X: Extended): Extended;function ArcCotH(const X: Extended): Extended;function ArcSecH(const X: Extended): Extended;function ArcCscH(const X: Extended): Extended;function IsNan(const AValue: Single): Boolean;function IsNan(const AValue: Double): Boolean;function IsNan(const AValue: Extended): Boolean;function IsInfinite(const A Value: Double): Boolean;function Mean(const Data: array of Double): Extended;function MinValue(const Data: array of Double): Double;function MinIntValue(const Data: array of Integer): Integer;function Min(const A, B: Integer): Integer;function Min(const A, B: Int64): Int64;function Min(const A, B: Single): Single;function Min(const A, B: Double): Double;function Min(const A, B: Extended): Extended;function MaxValue(const Data: array of Double): Double;varI: Integer;beginResult := Data[Low(Data)];for I := Low(Data) + 1 to High(Data) doif Result < Data[I] thenResult := Data[I];end;function MaxIntValue(const Data: array of Integer): Integer;function Max(const A, B: Integer): Integer;function Max(const A, B: Int64): Int64;function Max(const A, B: Single): Single;function Max(const A, B: Double): Double;function Max(const A, B: Extended): Extended;function Sign(const A Value: Integer): TValueSign;beginResult := ZeroValue;if A Value < 0 thenResult := NegativeValueelse if A Value > 0 thenResult := PositiveValue;end;function Sign(const A Value: Int64): TValueSign;function Sign(const A Value: Double): TValueSign;function CompareValue(const A, B: Extended; Epsilon: Extended): TValueRelationship; beginif SameValue(A, B, Epsilon) thenResult := EqualsValueelse if A < B thenResult := LessThanValueelseResult := GreaterThanV alue;end;function CompareValue(const A, B: Double; Epsilon: Double): TValueRelationship; function CompareValue(const A, B: Single; Epsilon: Single): TValueRelationship; function CompareValue(const A, B: Integer): TValueRelationship;function CompareValue(const A, B: Int64): TValueRelationship;function SameValue(const A, B: Extended; Epsilon: Extended): Boolean;beginif Epsilon = 0 thenEpsilon := Max(Min(Abs(A), Abs(B)) * ExtendedResolution, ExtendedResolution); if A > B thenResult := (A - B) <= EpsilonelseResult := (B - A) <= Epsilon;end;function SameValue(const A, B: Double; Epsilon: Double): Boolean;function SameValue(const A, B: Single; Epsilon: Single): Boolean;function IsZero(const A: Extended; Epsilon: Extended): Boolean;beginif Epsilon = 0 thenEpsilon := ExtendedResolution;Result := Abs(A) <= Epsilon;end;function IsZero(const A: Double; Epsilon: Double): Boolean;function IsZero(const A: Single; Epsilon: Single): Boolean;function IfThen(A Value: Boolean; const A True: Integer; const AFalse: Integer): Integer; beginif A Value thenResult := ATrueelseResult := AFalse;end;function IfThen(A Value: Boolean; const A True: Int64; const AFalse: Int64): Int64; function IfThen(A Value: Boolean; const A True: Double; const AFalse: Double): Double; function RandomRange(const AFrom, ATo: Integer): Integer;beginif AFrom > ATo thenResult := Random(AFrom - ATo) + AToelseResult := Random(ATo - AFrom) + AFrom;end;function RandomFrom(const A Values: array of Integer): Integer;beginResult := A Values[Random(High(A Values) + 1)];end;function RandomFrom(const A Values: array of Int64): Int64;function RandomFrom(const A Values: array of Double): Double;function InRange(const A Value, AMin, AMax: Integer): Boolean;varA,B: Boolean;beginA := (AValue >= AMin);B := (AValue <= AMax);Result := B and A;end;function InRange(const A Value, AMin, AMax: Int64): Boolean;function InRange(const A Value, AMin, AMax: Double): Boolean;function EnsureRange(const A Value, AMin, AMax: Integer): Integer;beginResult := A Value;assert(AMin <= AMax);if Result < AMin thenResult := AMin;if Result > AMax thenResult := AMax;end;function EnsureRange(const A Value, AMin, AMax: Int64): Int64;function EnsureRange(const A Value, AMin, AMax: Double): Double;procedure MeanAndStdDev(const Data: array of Double; var Mean, StdDev: Extended); varS: Extended;N,I: Integer;beginN := High(Data)- Low(Data) + 1;if N = 1 thenbeginMean := Data[0];StdDev := Data[0];Exit;end;Mean := Sum(Data) / N;S := 0; // sum differences from the mean, for greater accuracyfor I := Low(Data) to High(Data) doS := S + Sqr(Mean - Data[I]);StdDev := Sqrt(S / (N - 1));end;procedure MomentSkewKurtosis(const Data: array of Double;var M1, M2, M3, M4, Skew, Kurtosis: Extended);function Norm(const Data: array of Double): Extended;beginResult := Sqrt(SumOfSquares(Data));end;function PopnStdDev(const Data: array of Double): Extended;beginResult := Sqrt(PopnVariance(Data))end;function PopnVariance(const Data: array of Double): Extended;beginResult := TotalVariance(Data) / (High(Data) - Low(Data) + 1)end;function RandG(Mean, StdDev: Extended): Extended;function StdDev(const Data: array of Double): Extended;beginResult := Sqrt(Variance(Data))end;procedure RaiseOverflowError; forward;function SumInt(const Data: array of Integer): Integer;procedure RaiseOverflowError;function SumOfSquares(const Data: array of Double): Extended;function TotalVariance(const Data: array of Double): Extended;function Variance(const Data: array of Double): Extended;function DoubleDecliningBalance(const Cost, Salvage: Extended; Life, Period: Integer): Extended;function SLNDepreciation(const Cost, Salvage: Extended; Life: Integer): Extended;function SYDDepreciation(const Cost, Salvage: Extended; Life, Period: Integer): Extended; function InternalRateOfReturn(const Guess: Extended; const CashFlows: array of Double): Extended;function NetPresentValue(const Rate: Extended; const CashFlows: array of Double; PaymentTime: TPaymentTime): Extended;function PaymentParts(Period, NPeriods: Integer; Rate, PresentValue,FutureValue: Extended; PaymentTime: TPaymentTime; var IntPmt: Extended):Extended;function FutureValue(const Rate: Extended; NPeriods: Integer; const Payment, PresentValue: Extended; PaymentTime: TPaymentTime): Extended;function InterestPayment(const Rate: Extended; Period, NPeriods: Integer;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended; function InterestRate(NPeriods: Integer; const Payment, PresentValue,FutureValue: Extended; PaymentTime: TPaymentTime): Extended;function NumberOfPeriods(const Rate: Extended; Payment: Extended;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended; function Payment(Rate: Extended; NPeriods: Integer; const PresentValue,FutureValue: Extended; PaymentTime: TPaymentTime): Extended;function PeriodPayment(const Rate: Extended; Period, NPeriods: Integer;const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended; function PresentValue(const Rate: Extended; NPeriods: Integer; const Payment, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;function GetRoundMode: TFPURoundingMode;function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode; function GetPrecisionMode: TFPUPrecisionMode;function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode; function GetExceptionMask: TFPUExceptionMask;function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask; procedure ClearExceptions(RaisePending: Boolean);。

相关主题