~ubuntu-branches/ubuntu/precise/mricron/precise

« back to all changes in this revision

Viewing changes to fpmath/upoidist.pas

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-29 22:07:43 UTC
  • Revision ID: james.westby@ubuntu.com-20100729220743-q621ts2zj806gu0n
Tags: upstream-0.20100725.1~dfsg.1
ImportĀ upstreamĀ versionĀ 0.20100725.1~dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ ******************************************************************
 
2
  Poisson distribution
 
3
  ****************************************************************** }
 
4
 
 
5
unit upoidist;
 
6
 
 
7
interface
 
8
 
 
9
uses
 
10
  utypes;
 
11
 
 
12
function PPoisson(Mu : Float; K : Integer) : Float;
 
13
{ Probability of Poisson distrib. }
 
14
 
 
15
implementation
 
16
 
 
17
function PPoisson(Mu : Float; K : Integer) : Float;
 
18
var
 
19
  P : Float;
 
20
  I : Integer;
 
21
begin
 
22
  if (Mu <= 0.0) or (K < 0) then
 
23
    PPoisson := DefaultVal(FDomain, 0.0)
 
24
  else if (- Mu) < MinLog then
 
25
    PPoisson := DefaultVal(FUnderflow, 0.0)
 
26
  else if K = 0 then
 
27
    PPoisson := DefaultVal(FOk, Exp(- Mu))
 
28
  else
 
29
    begin
 
30
      P := Mu;
 
31
      for I := 2 to K do  { P = Mu^K / K! }
 
32
        P := P * Mu / I;
 
33
      PPoisson := Exp(- Mu) * P;
 
34
      SetErrCode(FOk);
 
35
    end;
 
36
end;
 
37
 
 
38
end.
 
 
b'\\ No newline at end of file'