The R Project SVN R

Rev

Rev 77685 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 77685 Rev 88401
Line 28... Line 28...
28
 
28
 
29
#include "nmath.h"
29
#include "nmath.h"
30
#include "dpq.h"
30
#include "dpq.h"
31
 
31
 
32
double dgeom(double x, double p, int give_log)
32
double dgeom(double x, double p, int give_log)
33
{ 
33
{
34
    double prob;
-
 
35
 
-
 
36
#ifdef IEEE_754
34
#ifdef IEEE_754
37
    if (ISNAN(x) || ISNAN(p)) return x + p;
35
    if (ISNAN(x) || ISNAN(p)) return x + p;
38
#endif
36
#endif
39
 
37
 
40
    if (p <= 0 || p > 1) ML_WARN_return_NAN;
38
    if (p <= 0 || p > 1) ML_WARN_return_NAN;
Line 42... Line 40...
42
    R_D_nonint_check(x);
40
    R_D_nonint_check(x);
43
    if (x < 0 || !R_FINITE(x) || p == 0) return R_D__0;
41
    if (x < 0 || !R_FINITE(x) || p == 0) return R_D__0;
44
    x = R_forceint(x);
42
    x = R_forceint(x);
45
 
43
 
46
    /* prob = (1-p)^x, stable for small p */
44
    /* prob = (1-p)^x, stable for small p */
47
    prob = dbinom_raw(0.,x, p,1-p, give_log);
45
    double prob = dbinom_raw(0.,x, p,1-p, give_log);
48
 
46
 
49
    return((give_log) ? log(p) + prob : p*prob);
47
    return((give_log) ? log(p) + prob : p*prob);
50
}
48
}