Skip to content

Commit c64e4b5

Browse files
author
ripley
committed
start cleaning up use of Rboolean
git-svn-id: https://svn.r-project.org/R/trunk@87773 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent d7090f2 commit c64e4b5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/nmath/pnchisq.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
* distribution function. Appl.Statist., 41, 478-482.
1212
1313
* Other parts
14-
* Copyright (C) 2000-2019 The R Core Team
14+
* Copyright (C) 2000-2025 The R Core Team
1515
* Copyright (C) 2003-2015 The R Foundation
1616
*/
1717

1818

1919

20-
#include "nmath.h"
20+
#include "nmath.h" // declares pnchisq_raw
2121
#include "dpq.h"
2222

2323
/*----------- DEBUGGING -------------
@@ -42,7 +42,7 @@
4242
static const double _dbl_min_exp = M_LN2 * DBL_MIN_EXP;
4343
/*= -708.3964 for IEEE double precision */
4444

45-
45+
/* This is the public interface in Rmath.h, so has to use 'int' */
4646
double pnchisq(double x, double df, double ncp, int lower_tail, int log_p)
4747
{
4848
double ans;
@@ -55,7 +55,8 @@ double pnchisq(double x, double df, double ncp, int lower_tail, int log_p)
5555

5656
if (df < 0. || ncp < 0.) ML_WARN_return_NAN;
5757

58-
ans = pnchisq_raw(x, df, ncp, 1e-12, 8*DBL_EPSILON, 1000000, lower_tail, log_p);
58+
ans = pnchisq_raw(x, df, ncp, 1e-12, 8*DBL_EPSILON, 1000000,
59+
(Rboolean) lower_tail, (Rboolean) log_p);
5960

6061
if (x <= 0. || x == ML_POSINF)
6162
return ans; // because it's perfect
@@ -86,6 +87,7 @@ double pnchisq(double x, double df, double ncp, int lower_tail, int log_p)
8687
}
8788
}
8889

90+
// Used in this file and in qnchisq.c
8991
double attribute_hidden
9092
pnchisq_raw(double x, double f, double theta /* = ncp */,
9193
double errmax, double reltol, int itrmax,

src/nmath/qbeta.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
3-
* Copyright (C) 1998--2022 The R Core Team
3+
* Copyright (C) 1998--2025 The R Core Team
44
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
55
* based on code (C) 1979 and later Royal Statistical Society
66
*
@@ -53,9 +53,11 @@
5353

5454
//attribute_hidden
5555
static void
56-
qbeta_raw(double alpha, double p, double q, int lower_tail, int log_p,
56+
qbeta_raw(double alpha, double p, double q,
57+
Rboolean lower_tail, Rboolean log_p,
5758
int swap_01, double log_q_cut, int n_N, double* qb);
5859

60+
/* This is the public interface in Rmath.h, so has to use 'int' */
5961
double qbeta(double alpha, double p, double q, int lower_tail, int log_p)
6062
{
6163

@@ -109,8 +111,12 @@ static const double
109111
#define const4 0.04481
110112

111113
// Returns both qbeta() and its "mirror" 1-qbeta(). Useful notably when qbeta() ~= 1
112-
attribute_hidden void
113-
qbeta_raw(double alpha, double p, double q, int lower_tail, int log_p,
114+
// This was hidden, but it is only used in this file so could be static
115+
// and be simplifed as swap_01 is always NA.
116+
// attribute_hidden void
117+
static void
118+
qbeta_raw(double alpha, double p, double q,
119+
Rboolean lower_tail, Rboolean log_p,
114120
int swap_01, // {TRUE, NA, FALSE}: if NA, algorithm decides swap_tail
115121
double log_q_cut, /* if == Inf: return log(qbeta(..));
116122
otherwise, if finite: the bound for
@@ -189,7 +195,8 @@ qbeta_raw(double alpha, double p, double q, int lower_tail, int log_p,
189195
// Conceptually, 0 < p_ < 1 (but can be 0 or 1 because of cancellation!)
190196
logbeta = lbeta(p, q);
191197

192-
swap_tail = (swap_choose) ? (p_ > 0.5) : swap_01;
198+
// this is only ever called with swap_choose = TRUE
199+
swap_tail = (swap_choose) ? (p_ > 0.5) : (Rboolean) swap_01;
193200

194201
R_ifDEBUG_printf(
195202
"qbeta(%g, %g, %g, lower_t=%d, log_p=%d, swap_01=%d, log_q_cut=%g, n_N=%d):%s\n"
@@ -402,7 +409,7 @@ qbeta_raw(double alpha, double p, double q, int lower_tail, int log_p,
402409
tx = 0.;
403410
u_n = ML_NEGINF;
404411
}
405-
use_log_x = log_p; add_N_step = FALSE; goto L_return;
412+
use_log_x = (Rboolean) log_p; add_N_step = FALSE; goto L_return;
406413
}
407414
else {
408415
R_ifDEBUG_printf(" pbeta(%g, %g, %g, T, log) = %g <= %g (= %s) --> continuing\n",

0 commit comments

Comments
 (0)