52
52
53
53
#define P_DIST (Y_ , ...) _pDIST_(Y_, __VA_ARGS__, lower_tail, log_p)
54
54
55
+ #ifdef MATHLIB_STANDALONE
56
+ # define MAYBE_R_CheckUserInterrupt ()
57
+ #else
58
+ # define MAYBE_R_CheckUserInterrupt () R_CheckUserInterrupt()
59
+ #endif
60
+
55
61
static double DO_SEARCH_FUN (_dist_PARS_DECL_ )
56
62
{
57
- int iter = 0 ;
58
63
Rboolean left = (lower_tail ? (* z >= p ) : (* z < p ));
59
64
R_DBG_printf (" do_search(y=%g, z=%15.10g %s p = %15.10g) --> search to %s" ,
60
65
y , * z , (lower_tail ? ">=" : "<" ), p , (left ? "left" : "right" ));
@@ -63,9 +68,11 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
63
68
else R_DBG_printf ("\n" );
64
69
65
70
if (left ) { // (lower_tail, *z >= p) or (upper tail, *z < p): search to the __left__
66
- for (;; ) {
71
+ for (int iter = 0 ; ; iter ++ ) {
67
72
double newz = -1. ; // -Wall
68
- if (++ iter % 10000 == 0 ) R_CheckUserInterrupt ();// have seen inf.loops
73
+ #ifndef MATHLIB_STANDALONE
74
+ if (iter % 10000 == 0 ) R_CheckUserInterrupt ();// have seen inf.loops
75
+ #endif
69
76
if (y > 0 )
70
77
newz = P_DIST (y - incr , _dist_PARS_ );
71
78
else if (y < 0 )
@@ -82,8 +89,10 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
82
89
}
83
90
}
84
91
else { // (lower_tail, *z < p) or (upper tail, *z >= p): search to the __right__
85
- for (;;) {
86
- if (++ iter % 10000 == 0 ) R_CheckUserInterrupt ();
92
+ for (int iter = 0 ; ; iter ++ ) {
93
+ #ifndef MATHLIB_STANDALONE
94
+ if (iter % 10000 == 0 ) R_CheckUserInterrupt ();
95
+ #endif
87
96
y += incr ;
88
97
#ifdef _dist_MAX_y
89
98
if (y < _dist_MAX_y )
@@ -202,7 +211,7 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
202
211
do { \
203
212
oldincr = incr ; \
204
213
y = DO_SEARCH_ (y , incr , _dist_PARS_ ); /* also updating *z */ \
205
- if (++ qIt % 10000 == 0 ) R_CheckUserInterrupt (); \
214
+ if (++ qIt % 10000 == 0 ) MAYBE_R_CheckUserInterrupt (); \
206
215
incr = fmax2 (1 , floor (incr / _iShrink_ )); \
207
216
} while (oldincr > 1 && incr > y * _relTol_ ); \
208
217
R_DBG_printf (" \\--> oldincr=%.0f, after %d \"outer\" search() iterations\n" , \
0 commit comments