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 39... Line 39...
39
#include "nmath.h"
39
#include "nmath.h"
40
#include "dpq.h"
40
#include "dpq.h"
41
 
41
 
42
double dgamma(double x, double shape, double scale, int give_log)
42
double dgamma(double x, double shape, double scale, int give_log)
43
{
43
{
44
    double pr;
-
 
45
#ifdef IEEE_754
44
#ifdef IEEE_754
46
    if (ISNAN(x) || ISNAN(shape) || ISNAN(scale))
45
    if (ISNAN(x) || ISNAN(shape) || ISNAN(scale))
47
        return x + shape + scale;
46
        return x + shape + scale;
48
#endif
47
#endif
49
    if (shape < 0 || scale <= 0) ML_WARN_return_NAN;
48
    if (shape < 0 || scale <= 0) ML_WARN_return_NAN;
Line 56... Line 55...
56
	if (shape > 1) return R_D__0;
55
	if (shape > 1) return R_D__0;
57
	/* else */
56
	/* else */
58
	return give_log ? -log(scale) : 1 / scale;
57
	return give_log ? -log(scale) : 1 / scale;
59
    }
58
    }
60
 
59
 
-
 
60
    double pr;
61
    if (shape < 1) {
61
    if (shape < 1) {
62
	pr = dpois_raw(shape, x/scale, give_log);
62
	pr = dpois_raw(shape, x/scale, give_log);
63
	return (
63
	return (
64
	    give_log/* NB: currently *always*  shape/x > 0  if shape < 1:
64
	    give_log/* NB: currently *always*  shape/x > 0  if shape < 1:
65
		     * -- overflow to Inf happens, but underflow to 0 does NOT : */
65
		     * -- overflow to Inf happens, but underflow to 0 does NOT : */