Error Function In Delphi
Contents |
one of the most known continuous distributions. Strictly speaking, there is a erfinv c++ set of normal distributions which differs in scale
Inverse Error Function
and shift. Hereinafter, by "normal distribution" we imply so called standard normal distribution - normal distribution having mean equal to 0 and standard deviation equal to 1. Probability density of such normal distribution is: Cumulative distribution function is expressed using the special function erf(x): Algorithms Erf and ErfC subroutines are used to calculate the values of the special function erf(x) and its own complement. Inverse erf function is calculated by using the InvErf subroutine. Normal distribution's cumulative distribution function is calculated using the NormalDistribution subroutine. Inverse cumulative distribution function is calculated by using the InvNormalDistribution subroutine. This article is intended for personal use only.Download ALGLIB C# C# source. Downloads page C++ C++ source. Downloads page C++, multiple precision arithmetic C++ source. MPFR/GMP is used. GMP source is available from gmplib.org. MPFR source is available from www.mpfr.org. Downloads page FreePascal FreePascal version. Downloads page Delphi Delphi version. Downloads page VB.NETVB.NET version. Downloads page VBAVBA version. Downloads page PythonPython version (CPython and IronPython are supported). Downloads page ALGLIB - numerical analysis library, 1999-2016. ALGLIB is a registered trademark of the ALGLIB Project. Policies for this site: privacy policy, trademark policy.
On {Name :} Exception type Do Statement {Else Statement} End; Description The try keyword is used to mark the start of a block of statements that have error trapping. If an error occurs, the program is not terminated. Instead, control is passed to either a Finally or Except section. try is used in a number of ways. Version 1 In a Try-Finally construct, the Finally statement is guaranteed to be executed absolutely regardless of what happens in the try clause. However, the Finally clause does http://www.alglib.net/specialfunctions/distributions/normal.php not actually handle any exceptions - the program will terminate if no Except clause is found (see notes below). Try-Finally is normally used by a routine to allow cleanup processing to take place, such as freeing resources, with the exception being correctly passed to the caller to handle. Version 2 In this version, only if the try http://www.delphibasics.co.uk/RTL.asp?Name=try clause generates an exception will the Except clause be executed. This is used to take alternative action when something unexpected goes wrong. The except clause cannot determine the error type however. Version 3 This is similar to version 2, but specifies different actions for different exception types, such as EInOutError. An Else clause can be used as a catch all for unexpected exception types. The general exception type Exception can be used to catch all exception types. By assigning a Name to the exception, the message text of the exception (Name.Message) can be obtained for display or other uses. When an exception is raised in a version 3 setup, if the exception is not acted upon by On or Else statements, then a check is made to see if we are in a nested Try block. If so, the Except clause of this parent Try is processed. If no On or Else clause is found, the program terminates. The Else clause is not really necessary - it is better to use On E:Ex
Delphi code, Val converts the string value S http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_Val.html to its numeric representation, as if it were read from a text file with Read. S is a string-type expression; it must http://www.fchart.com/ees/eeshelp/13aj7j6.htm be a sequence of characters that form a signed real number. V is an integer-type or real-type variable. If V is an error function integer-type variable, S must form a whole number. Code is a variable of type Integer. If the string is invalid, the index of the offending character is stored in Code; otherwise, Code is set to zero. For a null-terminated string, the error position returned in error function in Code is one larger than the actual zero-based index of the character in error. Delphi Examples: Copy Code { This example uses the System Val function to convert a string to an integer. Enter an integer in the text edit and then click the button. An error will occur if the value entered is not an integer. } procedure TForm1.Button1Click(Sender: TObject); var I, Code: Integer; mystr: string; begin { Get text from TEdit control } mystr := Edit1.Text; Val(mystr, I, Code); { Error during conversion to integer? } if Code <> 0 then MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk) else Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I)); end; See Also Str Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved. What do you think about this topic? Send feedback!
will not be any unit error checking when this function is called. ______________________________________________________ library PWFP; const doExample = -1; type CharString = array[0..255] of char; ParamRecPtr=^ParamRec; ParamRec=record Value:double; next:ParamRecPtr; end; function CountValues (P: ParamRecPtr): integer; var N: integer; begin N := 0; while (P <> nil) do begin N := N + 1; P := P^.next end; CountValues := N; end; {CountValues} function PWF(var S:CharString; var Mode:integer; Inputs:ParamRecPtr):double; export; stdcall; var P: ParamRecPtr; V: double; function CountValues (P: ParamRecPtr): integer; var N: integer; begin N := 0; while (P <> nil) do begin N := N + 1; P := P^.next end; CountValues := N; end; {CountValues} function PWFCalc: double; var NArgs: integer; interest, discount, periods: double; begin PWFCalc:=0; {in case of error exit} S := ''; P := Inputs; Periods := P^.value; if (Periods < 0) then begin S := 'The number of periods for the PWF function must be >0.'; exit; end; P := P^.next; interest := P^.value; if (interest >= 1) or (interest < 0) then begin S := 'The interest rate is a fraction and must be between 0 and 1.'; exit; end; P := P^.next; discount := P^.value; if (discount >= 1) or (discount < 0) then begin S := 'The discount rate is a fraction and must be between 0 and 1.'; exit; end; if (interest <> discount) then PWFCalc := 1 / (discount - interest) * (1 - exp(Periods * ln((1 + interest) / (1 + discount)))) else PWFCalc := Periods / (1 + interest); end; {PWF} begin PWF:=1; if (Mode = doExample) then begin S := 'PWF(Periods,Interest,Discount)'; exit; end; if (CountValues(Inputs)<>3) then S := 'Wrong number of arguments for PWF function.' else begin PWF:=PWFCalc; end; end; {PWF} exports PWF; begin {no initiation code needed} end. This file was compiled using DELPHI 5.0. After building the file, it is necessary to rename it to PWF.DLF.