Skip to content

Commit 68ca542

Browse files
author
maechler
committed
fix for standalone
git-svn-id: https://svn.r-project.org/R/trunk@80278 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 739038d commit 68ca542

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/nmath/qDiscrete_search.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@
5252

5353
#define P_DIST(Y_, ...) _pDIST_(Y_, __VA_ARGS__, lower_tail, log_p)
5454

55+
#ifdef MATHLIB_STANDALONE
56+
# define MAYBE_R_CheckUserInterrupt()
57+
#else
58+
# define MAYBE_R_CheckUserInterrupt() R_CheckUserInterrupt()
59+
#endif
60+
5561
static double DO_SEARCH_FUN(_dist_PARS_DECL_)
5662
{
57-
int iter = 0;
5863
Rboolean left = (lower_tail ? (*z >= p) : (*z < p));
5964
R_DBG_printf(" do_search(y=%g, z=%15.10g %s p = %15.10g) --> search to %s",
6065
y, *z, (lower_tail ? ">=" : "<"), p, (left ? "left" : "right"));
@@ -63,9 +68,11 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
6368
else R_DBG_printf("\n");
6469

6570
if(left) { // (lower_tail, *z >= p) or (upper tail, *z < p): search to the __left__
66-
for(;;) {
71+
for(int iter = 0; ; iter++) {
6772
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
6976
if(y > 0)
7077
newz = P_DIST(y - incr, _dist_PARS_);
7178
else if(y < 0)
@@ -82,8 +89,10 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
8289
}
8390
}
8491
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
8796
y += incr;
8897
#ifdef _dist_MAX_y
8998
if(y < _dist_MAX_y)
@@ -202,7 +211,7 @@ static double DO_SEARCH_FUN(_dist_PARS_DECL_)
202211
do { \
203212
oldincr = incr; \
204213
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(); \
206215
incr = fmax2(1, floor(incr / _iShrink_)); \
207216
} while(oldincr > 1 && incr > y * _relTol_); \
208217
R_DBG_printf(" \\--> oldincr=%.0f, after %d \"outer\" search() iterations\n", \

0 commit comments

Comments
 (0)