The R Project SVN R

Rev

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

Rev 71411 Rev 77685
Line 31... Line 31...
31
#define expmax	(DBL_MAX_EXP * M_LN2)/* = log(DBL_MAX) */
31
#define expmax	(DBL_MAX_EXP * M_LN2)/* = log(DBL_MAX) */
32
 
32
 
33
double rbeta(double aa, double bb)
33
double rbeta(double aa, double bb)
34
{
34
{
35
    if (ISNAN(aa) || ISNAN(bb) || aa < 0. || bb < 0.)
35
    if (ISNAN(aa) || ISNAN(bb) || aa < 0. || bb < 0.)
36
	ML_ERR_return_NAN;
36
	ML_WARN_return_NAN;
37
    if (!R_FINITE(aa) && !R_FINITE(bb)) // a = b = Inf : all mass at 1/2
37
    if (!R_FINITE(aa) && !R_FINITE(bb)) // a = b = Inf : all mass at 1/2
38
	return 0.5;
38
	return 0.5;
39
    if (aa == 0. && bb == 0.) // point mass 1/2 at each of {0,1} :
39
    if (aa == 0. && bb == 0.) // point mass 1/2 at each of {0,1} :
40
	return (unif_rand() < 0.5) ? 0. : 1.;
40
	return (unif_rand() < 0.5) ? 0. : 1.;
41
    // now, at least one of a, b is finite and positive
41
    // now, at least one of a, b is finite and positive