The R Project SVN R

Rev

Rev 68947 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68947 Rev 71411
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 2000--2010 The R Core Team
4
 *  Copyright (C) 2000--2016 The R Core Team
5
 *  Copyright (C) 2000, 2010 The R Foundation
5
 *  Copyright (C) 2001--2016 The R Foundation
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
10
 *  (at your option) any later version.
Line 30... Line 30...
30
 
30
 
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 (aa < 0. || bb < 0.)
35
    if (ISNAN(aa) || ISNAN(bb) || aa < 0. || bb < 0.)
36
	ML_ERR_return_NAN;
36
	ML_ERR_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.;