The R Project SVN R

Rev

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

Rev 90307 Rev 90310
Line 16... Line 16...
16
 *  along with this program; if not, a copy is available at
16
 *  along with this program; if not, a copy is available at
17
 *  https://www.R-project.org/Licenses/
17
 *  https://www.R-project.org/Licenses/
18
 *
18
 *
19
 */
19
 */
20
 
20
 
21
 
-
 
22
// Checking rbinom() --  wrt RNGkind(normal.kind = *)
21
// Checking rbinom() --  wrt RNGkind(binom.kind = *)
23
#include <R_ext/Random.h>
22
#include <R_ext/Random.h>
24
// and redefine it for here
-
 
25
static Binomtype my_binom_kind = BTPE;
-
 
26
Binomtype R_binom_kind (void) { return my_binom_kind; }
-
 
27
 
23
 
28
#define MATHLIB_STANDALONE 1
24
#define MATHLIB_STANDALONE 1
29
#include <Rmath.h>
25
#include <Rmath.h>
30
 
26
 
31
#include <stdio.h>
27
#include <stdio.h>
32
 
28
 
-
 
29
// defined in ../rbinom.c , and used in its (..STANDALONE..) R_binom_kind()
-
 
30
extern Binomtype ML_Binom_kind;
33
 
31
 
34
int
32
int
35
main(int argc, char** argv)
33
main(int argc, char** argv)
36
{
34
{
37
/* something to force the library to be included */
35
/* something to force the library to be included */
Line 50... Line 48...
50
    set_seed(428, 1234);
48
    set_seed(428, 1234);
51
#define MAX_N 7
49
#define MAX_N 7
52
    int N = MAX_N, i, max_i = 20000;
50
    int N = MAX_N, i, max_i = 20000;
53
    for(i = 1; i <= max_i; i++) {
51
    for(i = 1; i <= max_i; i++) {
54
	unsigned int si_1, si_2;
52
	unsigned int si_1, si_2;
55
	get_seed(&si_1, &si_2); my_binom_kind = BTPE;       double B1 = rbinom(320., 0.25);
53
	get_seed(&si_1, &si_2); ML_Binom_kind = BTPE;       double B1 = rbinom(320., 0.25);
56
	set_seed( si_1,  si_2); my_binom_kind = BUGGY_BTPE; double B2 = rbinom(320., 0.25);
54
	set_seed( si_1,  si_2); ML_Binom_kind = BUGGY_BTPE; double B2 = rbinom(320., 0.25);
57
	if(B1 != B2) {
55
	if(B1 != B2) {
58
	    printf("rbinom(320, 0.25) difference at i=%5d, w/ seeds (%u, %u)\n", i, si_1, si_2);
56
	    printf("rbinom(320, 0.25) difference at i=%5d, w/ seeds (%u, %u)\n", i, si_1, si_2);
59
	    printf(" B{ BTPE } =%4.0f,\n B{Buggy..}=%4.0f\n", B1, B2);
57
	    printf(" B{ BTPE } =%4.0f,\n B{Buggy..}=%4.0f\n", B1, B2);
60
	    N--; if(!N) break;
58
	    N--; if(!N) break;
61
	}
59
	}