| 7727 |
ripley |
1 |
/*
|
|
|
2 |
* Mathlib : A C Library of Special Functions
|
|
|
3 |
* Copyright (C) 1998-2000 The R Development Core Team
|
|
|
4 |
*
|
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
8 |
* (at your option) any later version.
|
|
|
9 |
*
|
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
* GNU General Public License for more details.
|
|
|
14 |
*
|
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 |
*
|
|
|
19 |
|
|
|
20 |
* Mathlib.h should contain ALL headers from R's C code in `src/nmath'
|
|
|
21 |
--------- such that ``the Math library'' can be used by simply
|
|
|
22 |
|
|
|
23 |
``#include "Mathlib.h" ''
|
|
|
24 |
|
|
|
25 |
and nothing else.
|
|
|
26 |
*/
|
|
|
27 |
#ifndef MATHLIB_H
|
|
|
28 |
#define MATHLIB_H
|
|
|
29 |
|
| 8431 |
ripley |
30 |
/*-- Mathlib as part of R -- define this for standalone : */
|
|
|
31 |
/* #undef MATHLIB_STANDALONE */
|
| 7727 |
ripley |
32 |
|
| 8431 |
ripley |
33 |
#ifdef MATHLIB_STANDALONE
|
|
|
34 |
# define R_NO_REMAP 1
|
|
|
35 |
#endif
|
| 7727 |
ripley |
36 |
|
| 8431 |
ripley |
37 |
|
| 7727 |
ripley |
38 |
#ifdef FORTRAN_H
|
|
|
39 |
#error __MUST__include "Mathlib.h" _before_ "Fortran.h"
|
|
|
40 |
#endif
|
|
|
41 |
|
|
|
42 |
#include <errno.h>
|
|
|
43 |
#include <limits.h>
|
|
|
44 |
#include <float.h>
|
|
|
45 |
#include <math.h>
|
|
|
46 |
#include <stdlib.h>
|
|
|
47 |
|
| 8096 |
ripley |
48 |
/* Undo SGI Madness */
|
|
|
49 |
|
|
|
50 |
#ifdef ftrunc
|
|
|
51 |
# undef ftrunc
|
|
|
52 |
#endif
|
|
|
53 |
#ifdef qexp
|
|
|
54 |
# undef qexp
|
|
|
55 |
#endif
|
|
|
56 |
#ifdef qgamma
|
|
|
57 |
# undef qgamma
|
|
|
58 |
#endif
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/* ----- The following constants and entry points are part of the R API ---- */
|
|
|
62 |
|
| 7727 |
ripley |
63 |
/* 30 Decimal-place constants */
|
|
|
64 |
/* Computed with bc -l (scale=32; proper round) */
|
|
|
65 |
|
|
|
66 |
/* SVID & X/Open Constants */
|
|
|
67 |
/* Names from Solaris math.h */
|
|
|
68 |
|
|
|
69 |
#ifndef M_E
|
|
|
70 |
#define M_E 2.718281828459045235360287471353 /* e */
|
|
|
71 |
#endif
|
|
|
72 |
|
|
|
73 |
#ifndef M_LOG2E
|
|
|
74 |
#define M_LOG2E 1.442695040888963407359924681002 /* log2(e) */
|
|
|
75 |
#endif
|
|
|
76 |
|
|
|
77 |
#ifndef M_LOG10E
|
|
|
78 |
#define M_LOG10E 0.434294481903251827651128918917 /* log10(e) */
|
|
|
79 |
#endif
|
|
|
80 |
|
|
|
81 |
#ifndef M_LN2
|
|
|
82 |
#define M_LN2 0.693147180559945309417232121458 /* ln(2) */
|
|
|
83 |
#endif
|
|
|
84 |
|
|
|
85 |
#ifndef M_LN10
|
|
|
86 |
#define M_LN10 2.302585092994045684017991454684 /* ln(10) */
|
|
|
87 |
#endif
|
|
|
88 |
|
|
|
89 |
#ifndef M_PI
|
|
|
90 |
#define M_PI 3.141592653589793238462643383280 /* pi */
|
|
|
91 |
#endif
|
|
|
92 |
|
|
|
93 |
#ifndef M_PI_2
|
|
|
94 |
#define M_PI_2 1.570796326794896619231321691640 /* pi/2 */
|
|
|
95 |
#endif
|
|
|
96 |
|
|
|
97 |
#ifndef M_PI_4
|
|
|
98 |
#define M_PI_4 0.785398163397448309615660845820 /* pi/4 */
|
|
|
99 |
#endif
|
|
|
100 |
|
|
|
101 |
#ifndef M_1_PI
|
|
|
102 |
#define M_1_PI 0.318309886183790671537767526745 /* 1/pi */
|
|
|
103 |
#endif
|
|
|
104 |
|
|
|
105 |
#ifndef M_2_PI
|
|
|
106 |
#define M_2_PI 0.636619772367581343075535053490 /* 2/pi */
|
|
|
107 |
#endif
|
|
|
108 |
|
|
|
109 |
#ifndef M_2_SQRTPI
|
|
|
110 |
#define M_2_SQRTPI 1.128379167095512573896158903122 /* 2/sqrt(pi) */
|
|
|
111 |
#endif
|
|
|
112 |
|
|
|
113 |
#ifndef M_SQRT2
|
|
|
114 |
#define M_SQRT2 1.414213562373095048801688724210 /* sqrt(2) */
|
|
|
115 |
#endif
|
|
|
116 |
|
|
|
117 |
#ifndef M_SQRT1_2
|
|
|
118 |
#define M_SQRT1_2 0.707106781186547524400844362105 /* 1/sqrt(2) */
|
|
|
119 |
#endif
|
|
|
120 |
|
|
|
121 |
/* Other, R-Specific Constants */
|
|
|
122 |
|
| 10924 |
maechler |
123 |
#ifndef M_SQRT_3
|
|
|
124 |
#define M_SQRT_3 1.732050807568877293527446341506 /* sqrt(3) */
|
|
|
125 |
#endif
|
|
|
126 |
|
| 7727 |
ripley |
127 |
#ifndef M_SQRT_32
|
|
|
128 |
#define M_SQRT_32 5.656854249492380195206754896838 /* sqrt(32) */
|
|
|
129 |
#endif
|
|
|
130 |
|
|
|
131 |
#ifndef M_LOG10_2
|
|
|
132 |
#define M_LOG10_2 0.301029995663981195213738894724 /* log10(2) */
|
|
|
133 |
#endif
|
|
|
134 |
|
|
|
135 |
#ifndef M_SQRT_PI
|
|
|
136 |
#define M_SQRT_PI 1.772453850905516027298167483341 /* sqrt(pi) */
|
|
|
137 |
#endif
|
|
|
138 |
|
|
|
139 |
#ifndef M_1_SQRT_2PI
|
|
|
140 |
#define M_1_SQRT_2PI 0.398942280401432677939946059934 /* 1/sqrt(2pi) */
|
|
|
141 |
#endif
|
|
|
142 |
|
|
|
143 |
#ifndef M_SQRT_2dPI
|
|
|
144 |
#define M_SQRT_2dPI 0.797884560802865355879892119869 /* sqrt(2/pi) */
|
|
|
145 |
#endif
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
#ifndef M_LN_SQRT_PI
|
|
|
149 |
#define M_LN_SQRT_PI 0.572364942924700087071713675677 /* log(sqrt(pi)) */
|
|
|
150 |
#endif
|
|
|
151 |
|
|
|
152 |
#ifndef M_LN_SQRT_2PI
|
|
|
153 |
#define M_LN_SQRT_2PI 0.918938533204672741780329736406 /* log(sqrt(2*pi)) */
|
|
|
154 |
#endif
|
|
|
155 |
|
|
|
156 |
#ifndef M_LN_SQRT_PId2
|
|
|
157 |
#define M_LN_SQRT_PId2 0.225791352644727432363097614947 /* log(sqrt(pi/2)) */
|
|
|
158 |
#endif
|
|
|
159 |
|
| 10470 |
maechler |
160 |
#ifdef MATHLIB_STANDALONE
|
|
|
161 |
typedef enum { FALSE = 0, TRUE } Rboolean;
|
|
|
162 |
#else
|
| 10592 |
maechler |
163 |
# include "R_ext/Boolean.h"
|
| 10470 |
maechler |
164 |
|
|
|
165 |
/* for API back-compatibility -- DEPRECATED since R 1.2 -- */
|
|
|
166 |
#define LTRUE TRUE
|
|
|
167 |
#define LFALSE FALSE
|
|
|
168 |
#endif
|
|
|
169 |
|
|
|
170 |
|
| 9363 |
ripley |
171 |
/* always remap these two to avoid conflicts with Fortran versions */
|
|
|
172 |
#define d1mach Rf_d1mach
|
|
|
173 |
#define i1mach Rf_i1mach
|
|
|
174 |
|
| 7758 |
ripley |
175 |
#ifndef R_NO_REMAP
|
| 7754 |
ripley |
176 |
#define bessel_i Rf_bessel_i
|
|
|
177 |
#define bessel_j Rf_bessel_j
|
|
|
178 |
#define bessel_k Rf_bessel_k
|
|
|
179 |
#define bessel_y Rf_bessel_y
|
|
|
180 |
#define beta Rf_beta
|
|
|
181 |
#define chebyshev_eval Rf_chebyshev_eval
|
|
|
182 |
#define chebyshev_init Rf_chebyshev_init
|
|
|
183 |
#define choose Rf_choose
|
|
|
184 |
#define dbeta Rf_dbeta
|
|
|
185 |
#define dbinom Rf_dbinom
|
|
|
186 |
#define dcauchy Rf_dcauchy
|
|
|
187 |
#define dchisq Rf_dchisq
|
|
|
188 |
#define dexp Rf_dexp
|
|
|
189 |
#define df Rf_df
|
|
|
190 |
#define dgamma Rf_dgamma
|
|
|
191 |
#define dgeom Rf_dgeom
|
|
|
192 |
#define dhyper Rf_dhyper
|
|
|
193 |
#define digamma Rf_digamma
|
|
|
194 |
#define dlnorm Rf_dlnorm
|
|
|
195 |
#define dlogis Rf_dlogis
|
|
|
196 |
#define dnbeta Rf_dnbeta
|
|
|
197 |
#define dnbinom Rf_dnbinom
|
|
|
198 |
#define dnchisq Rf_dnchisq
|
|
|
199 |
#define dnf Rf_dnf
|
|
|
200 |
#define dnorm4 Rf_dnorm4
|
|
|
201 |
#define dnt Rf_dnt
|
|
|
202 |
#define dpois Rf_dpois
|
|
|
203 |
#define dpsifn Rf_dpsifn
|
|
|
204 |
#define dsignrank Rf_dsignrank
|
|
|
205 |
#define dt Rf_dt
|
|
|
206 |
#define dtukey Rf_dtukey
|
|
|
207 |
#define dunif Rf_dunif
|
|
|
208 |
#define dweibull Rf_dweibull
|
|
|
209 |
#define dwilcox Rf_dwilcox
|
|
|
210 |
#define fastchoose Rf_fastchoose
|
| 10743 |
maechler |
211 |
#define bd0 Rf_bd0
|
|
|
212 |
#define stirlerr Rf_stirlerr
|
| 7754 |
ripley |
213 |
#define fcube Rf_fcube
|
|
|
214 |
#define fmax2 Rf_fmax2
|
|
|
215 |
#define fmin2 Rf_fmin2
|
|
|
216 |
#define fmod Rf_fmod
|
|
|
217 |
#define fprec Rf_fprec
|
|
|
218 |
#define fround Rf_fround
|
|
|
219 |
#define fsign Rf_fsign
|
|
|
220 |
#define fsquare Rf_fsquare
|
|
|
221 |
#define ftrunc Rf_ftrunc
|
|
|
222 |
#define gammafn Rf_gammafn
|
|
|
223 |
#define gammalims Rf_gammalims
|
|
|
224 |
#define gamma_cody Rf_gamma_cody
|
|
|
225 |
#define imax2 Rf_imax2
|
|
|
226 |
#define imin2 Rf_imin2
|
|
|
227 |
#define I_bessel Rf_I_bessel
|
|
|
228 |
#define J_bessel Rf_J_bessel
|
|
|
229 |
#define K_bessel Rf_K_bessel
|
|
|
230 |
#define lbeta Rf_lbeta
|
|
|
231 |
#define lchoose Rf_lchoose
|
|
|
232 |
#define lfastchoose Rf_lfastchoose
|
|
|
233 |
#define lgammacor Rf_lgammacor
|
|
|
234 |
#define lgammafn Rf_lgammafn
|
| 8096 |
ripley |
235 |
#define log1p Rf_log1p
|
| 7754 |
ripley |
236 |
#define pbeta Rf_pbeta
|
|
|
237 |
#define pbeta_raw Rf_pbeta_raw
|
|
|
238 |
#define pbinom Rf_pbinom
|
|
|
239 |
#define pcauchy Rf_pcauchy
|
|
|
240 |
#define pchisq Rf_pchisq
|
|
|
241 |
#define pentagamma Rf_pentagamma
|
|
|
242 |
#define pexp Rf_pexp
|
|
|
243 |
#define pf Rf_pf
|
|
|
244 |
#define pgamma Rf_pgamma
|
|
|
245 |
#define pgeom Rf_pgeom
|
|
|
246 |
#define phyper Rf_phyper
|
|
|
247 |
#define plnorm Rf_plnorm
|
|
|
248 |
#define plogis Rf_plogis
|
|
|
249 |
#define pnbeta Rf_pnbeta
|
|
|
250 |
#define pnbinom Rf_pnbinom
|
|
|
251 |
#define pnchisq Rf_pnchisq
|
|
|
252 |
#define pnf Rf_pnf
|
|
|
253 |
#define pnorm5 Rf_pnorm5
|
|
|
254 |
#define pnorm_both Rf_pnorm_both
|
|
|
255 |
#define pnt Rf_pnt
|
|
|
256 |
#define ppois Rf_ppois
|
|
|
257 |
#define psignrank Rf_psignrank
|
|
|
258 |
#define pt Rf_pt
|
|
|
259 |
#define ptukey Rf_ptukey
|
|
|
260 |
#define punif Rf_punif
|
| 9417 |
ripley |
261 |
#define pythag Rf_pythag
|
| 7754 |
ripley |
262 |
#define pweibull Rf_pweibull
|
|
|
263 |
#define pwilcox Rf_pwilcox
|
|
|
264 |
#define qbeta Rf_qbeta
|
|
|
265 |
#define qbinom Rf_qbinom
|
|
|
266 |
#define qcauchy Rf_qcauchy
|
|
|
267 |
#define qchisq Rf_qchisq
|
|
|
268 |
#define qexp Rf_qexp
|
|
|
269 |
#define qf Rf_qf
|
|
|
270 |
#define qgamma Rf_qgamma
|
|
|
271 |
#define qgeom Rf_qgeom
|
|
|
272 |
#define qhyper Rf_qhyper
|
|
|
273 |
#define qlnorm Rf_qlnorm
|
|
|
274 |
#define qlogis Rf_qlogis
|
|
|
275 |
#define qnbeta Rf_qnbeta
|
|
|
276 |
#define qnbinom Rf_qnbinom
|
|
|
277 |
#define qnchisq Rf_qnchisq
|
|
|
278 |
#define qnf Rf_qnf
|
|
|
279 |
#define qnorm5 Rf_qnorm5
|
|
|
280 |
#define qnt Rf_qnt
|
|
|
281 |
#define qpois Rf_qpois
|
|
|
282 |
#define qsignrank Rf_qsignrank
|
|
|
283 |
#define qt Rf_qt
|
|
|
284 |
#define qtukey Rf_qtukey
|
|
|
285 |
#define qunif Rf_qunif
|
|
|
286 |
#define qweibull Rf_qweibull
|
|
|
287 |
#define qwilcox Rf_qwilcox
|
|
|
288 |
#define rbeta Rf_rbeta
|
|
|
289 |
#define rbinom Rf_rbinom
|
|
|
290 |
#define rcauchy Rf_rcauchy
|
|
|
291 |
#define rchisq Rf_rchisq
|
|
|
292 |
#define rexp Rf_rexp
|
|
|
293 |
#define rf Rf_rf
|
|
|
294 |
#define rgamma Rf_rgamma
|
|
|
295 |
#define rgeom Rf_rgeom
|
|
|
296 |
#define rhyper Rf_rhyper
|
|
|
297 |
#define rlnorm Rf_rlnorm
|
|
|
298 |
#define rlogis Rf_rlogis
|
|
|
299 |
#define rnbeta Rf_rnbeta
|
|
|
300 |
#define rnbinom Rf_rnbinom
|
|
|
301 |
#define rnchisq Rf_rnchisq
|
|
|
302 |
#define rnf Rf_rnf
|
|
|
303 |
#define rnorm Rf_rnorm
|
|
|
304 |
#define rnt Rf_rnt
|
|
|
305 |
#define rpois Rf_rpois
|
|
|
306 |
#define rsignrank Rf_rsignrank
|
|
|
307 |
#define rt Rf_rt
|
|
|
308 |
#define rtukey Rf_rtukey
|
|
|
309 |
#define runif Rf_runif
|
|
|
310 |
#define rweibull Rf_rweibull
|
|
|
311 |
#define rwilcox Rf_rwilcox
|
|
|
312 |
#define sign Rf_sign
|
|
|
313 |
#define tetragamma Rf_tetragamma
|
|
|
314 |
#define trigamma Rf_trigamma
|
|
|
315 |
#define Y_bessel Rf_Y_bessel
|
|
|
316 |
#endif
|
|
|
317 |
|
| 7727 |
ripley |
318 |
#define rround fround
|
|
|
319 |
#define prec fprec
|
|
|
320 |
#undef trunc
|
|
|
321 |
#define trunc ftrunc
|
|
|
322 |
|
| 11211 |
ripley |
323 |
#ifdef __cplusplus
|
|
|
324 |
extern "C" {
|
|
|
325 |
#endif
|
| 7727 |
ripley |
326 |
|
| 7867 |
ripley |
327 |
/* R's versions with !R_FINITE checks */
|
| 7727 |
ripley |
328 |
|
|
|
329 |
double R_log(double x);
|
|
|
330 |
double R_pow(double x, double y);
|
| 7867 |
ripley |
331 |
double R_pow_di(double, int);
|
| 7727 |
ripley |
332 |
|
|
|
333 |
/* Random Number Generators */
|
|
|
334 |
|
|
|
335 |
double norm_rand(void);
|
|
|
336 |
double unif_rand(void);
|
|
|
337 |
double exp_rand(void);
|
| 9363 |
ripley |
338 |
#ifdef MATHLIB_STANDALONE
|
|
|
339 |
void set_seed(unsigned int, unsigned int);
|
|
|
340 |
#endif
|
| 7727 |
ripley |
341 |
|
|
|
342 |
/* Normal Distribution */
|
|
|
343 |
|
| 7922 |
maechler |
344 |
/* These 3 will be re-defined in ./S_compat.h (when that is used) : */
|
| 7727 |
ripley |
345 |
#define pnorm pnorm5
|
|
|
346 |
#define qnorm qnorm5
|
|
|
347 |
#define dnorm dnorm4
|
|
|
348 |
|
|
|
349 |
double dnorm(double, double, double, int);
|
|
|
350 |
double pnorm(double, double, double, int, int);
|
|
|
351 |
double qnorm(double, double, double, int, int);
|
|
|
352 |
double rnorm(double, double);
|
|
|
353 |
void pnorm_both(double, double *, double *, int, int);/* both tails */
|
|
|
354 |
|
|
|
355 |
/* Uniform Distribution */
|
|
|
356 |
|
|
|
357 |
double dunif(double, double, double, int);
|
|
|
358 |
double punif(double, double, double, int, int);
|
|
|
359 |
double qunif(double, double, double, int, int);
|
|
|
360 |
double runif(double, double);
|
|
|
361 |
|
|
|
362 |
/* Gamma Distribution */
|
|
|
363 |
|
|
|
364 |
double dgamma(double, double, double, int);
|
|
|
365 |
double pgamma(double, double, double, int, int);
|
|
|
366 |
double qgamma(double, double, double, int, int);
|
|
|
367 |
double rgamma(double, double);
|
|
|
368 |
|
|
|
369 |
/* Beta Distribution */
|
|
|
370 |
|
|
|
371 |
double dbeta(double, double, double, int);
|
|
|
372 |
double pbeta(double, double, double, int, int);
|
|
|
373 |
double qbeta(double, double, double, int, int);
|
|
|
374 |
double rbeta(double, double);
|
|
|
375 |
double pbeta_raw(double, double, double, int);
|
|
|
376 |
|
|
|
377 |
/* Lognormal Distribution */
|
|
|
378 |
|
|
|
379 |
double dlnorm(double, double, double, int);
|
|
|
380 |
double plnorm(double, double, double, int, int);
|
|
|
381 |
double qlnorm(double, double, double, int, int);
|
|
|
382 |
double rlnorm(double, double);
|
|
|
383 |
|
|
|
384 |
/* Chi-squared Distribution */
|
|
|
385 |
|
|
|
386 |
double dchisq(double, double, int);
|
|
|
387 |
double pchisq(double, double, int, int);
|
|
|
388 |
double qchisq(double, double, int, int);
|
|
|
389 |
double rchisq(double);
|
|
|
390 |
|
|
|
391 |
/* Non-central Chi-squared Distribution */
|
|
|
392 |
|
|
|
393 |
double dnchisq(double, double, double, int);
|
|
|
394 |
double pnchisq(double, double, double, int, int);
|
|
|
395 |
double qnchisq(double, double, double, int, int);
|
|
|
396 |
double rnchisq(double, double);
|
|
|
397 |
|
|
|
398 |
/* F Distibution */
|
|
|
399 |
|
|
|
400 |
double df(double, double, double, int);
|
|
|
401 |
double pf(double, double, double, int, int);
|
|
|
402 |
double qf(double, double, double, int, int);
|
|
|
403 |
double rf(double, double);
|
|
|
404 |
|
|
|
405 |
/* Student t Distibution */
|
|
|
406 |
|
|
|
407 |
double dt(double, double, int);
|
|
|
408 |
double pt(double, double, int, int);
|
|
|
409 |
double qt(double, double, int, int);
|
|
|
410 |
double rt(double);
|
|
|
411 |
|
|
|
412 |
/* Binomial Distribution */
|
|
|
413 |
|
|
|
414 |
double dbinom(double, double, double, int);
|
|
|
415 |
double pbinom(double, double, double, int, int);
|
|
|
416 |
double qbinom(double, double, double, int, int);
|
|
|
417 |
double rbinom(double, double);
|
|
|
418 |
|
|
|
419 |
/* Cauchy Distribution */
|
|
|
420 |
|
|
|
421 |
double dcauchy(double, double, double, int);
|
|
|
422 |
double pcauchy(double, double, double, int, int);
|
|
|
423 |
double qcauchy(double, double, double, int, int);
|
|
|
424 |
double rcauchy(double, double);
|
|
|
425 |
|
|
|
426 |
/* Exponential Distribution */
|
|
|
427 |
|
|
|
428 |
double dexp(double, double, int);
|
|
|
429 |
double pexp(double, double, int, int);
|
|
|
430 |
double qexp(double, double, int, int);
|
|
|
431 |
double rexp(double);
|
|
|
432 |
|
|
|
433 |
/* Geometric Distribution */
|
|
|
434 |
|
|
|
435 |
double dgeom(double, double, int);
|
|
|
436 |
double pgeom(double, double, int, int);
|
|
|
437 |
double qgeom(double, double, int, int);
|
|
|
438 |
double rgeom(double);
|
|
|
439 |
|
|
|
440 |
/* Hypergeometric Distibution */
|
|
|
441 |
|
|
|
442 |
double dhyper(double, double, double, double, int);
|
|
|
443 |
double phyper(double, double, double, double, int, int);
|
|
|
444 |
double qhyper(double, double, double, double, int, int);
|
|
|
445 |
double rhyper(double, double, double);
|
|
|
446 |
|
|
|
447 |
/* Negative Binomial Distribution */
|
|
|
448 |
|
|
|
449 |
double dnbinom(double, double, double, int);
|
|
|
450 |
double pnbinom(double, double, double, int, int);
|
|
|
451 |
double qnbinom(double, double, double, int, int);
|
|
|
452 |
double rnbinom(double, double);
|
|
|
453 |
|
|
|
454 |
/* Poisson Distribution */
|
|
|
455 |
|
|
|
456 |
double dpois(double, double, int);
|
|
|
457 |
double ppois(double, double, int, int);
|
|
|
458 |
double qpois(double, double, int, int);
|
|
|
459 |
double rpois(double);
|
|
|
460 |
|
|
|
461 |
/* Weibull Distribution */
|
|
|
462 |
|
|
|
463 |
double dweibull(double, double, double, int);
|
|
|
464 |
double pweibull(double, double, double, int, int);
|
|
|
465 |
double qweibull(double, double, double, int, int);
|
|
|
466 |
double rweibull(double, double);
|
|
|
467 |
|
|
|
468 |
/* Logistic Distribution */
|
|
|
469 |
|
|
|
470 |
double dlogis(double, double, double, int);
|
|
|
471 |
double plogis(double, double, double, int, int);
|
|
|
472 |
double qlogis(double, double, double, int, int);
|
|
|
473 |
double rlogis(double, double);
|
|
|
474 |
|
|
|
475 |
/* Non-central Beta Distribution */
|
|
|
476 |
|
|
|
477 |
double dnbeta(double, double, double, double, int);
|
|
|
478 |
double pnbeta(double, double, double, double, int, int);
|
|
|
479 |
double qnbeta(double, double, double, double, int, int);
|
|
|
480 |
double rnbeta(double, double, double);
|
|
|
481 |
|
|
|
482 |
/* Non-central F Distribution */
|
|
|
483 |
|
| 8096 |
ripley |
484 |
/* double dnf(double, double, double, double, int); */
|
| 7727 |
ripley |
485 |
double pnf(double, double, double, double, int, int);
|
|
|
486 |
double qnf(double, double, double, double, int, int);
|
| 8096 |
ripley |
487 |
/* double rnf(double, double, double); */
|
| 7727 |
ripley |
488 |
|
|
|
489 |
/* Non-central Student t Distribution */
|
|
|
490 |
|
| 8096 |
ripley |
491 |
/* double dnt(double, double, double, int); */
|
| 7727 |
ripley |
492 |
double pnt(double, double, double, int, int);
|
|
|
493 |
double qnt(double, double, double, int, int);
|
| 8096 |
ripley |
494 |
/* double rnt(double, double); */
|
| 7727 |
ripley |
495 |
|
|
|
496 |
/* Studentized Range Distribution */
|
|
|
497 |
|
| 8096 |
ripley |
498 |
/* double dtukey(double, double, double, double, int); */
|
| 7727 |
ripley |
499 |
double ptukey(double, double, double, double, int, int);
|
|
|
500 |
double qtukey(double, double, double, double, int, int);
|
| 8096 |
ripley |
501 |
/* double rtukey(double, double, double); */
|
| 7727 |
ripley |
502 |
|
|
|
503 |
/* Wilcoxon Rank Sum Distribution */
|
|
|
504 |
|
|
|
505 |
double dwilcox(double, double, double, int);
|
|
|
506 |
double pwilcox(double, double, double, int, int);
|
|
|
507 |
double qwilcox(double, double, double, int, int);
|
|
|
508 |
double rwilcox(double, double);
|
|
|
509 |
|
|
|
510 |
/* Wilcoxon Signed Rank Distribution */
|
|
|
511 |
|
|
|
512 |
double dsignrank(double, double, int);
|
|
|
513 |
double psignrank(double, double, int, int);
|
|
|
514 |
double qsignrank(double, double, int, int);
|
|
|
515 |
double rsignrank(double);
|
|
|
516 |
|
| 9417 |
ripley |
517 |
/* General Support Functions */
|
| 8096 |
ripley |
518 |
|
| 9417 |
ripley |
519 |
double pythag(double, double);
|
|
|
520 |
double log1p(double); /* = log(1+x) {care for small x} */
|
|
|
521 |
int imax2(int, int);
|
|
|
522 |
int imin2(int, int);
|
|
|
523 |
double fmax2(double, double);
|
|
|
524 |
double fmin2(double, double);
|
|
|
525 |
double sign(double);
|
|
|
526 |
double fsign(double, double);
|
|
|
527 |
double fprec(double, double);
|
|
|
528 |
double fround(double, double);
|
|
|
529 |
|
|
|
530 |
|
| 8096 |
ripley |
531 |
/* ----------------- Private part of the header file ------------------- */
|
|
|
532 |
|
|
|
533 |
/* old-R Compatibility */
|
|
|
534 |
|
|
|
535 |
#define snorm norm_rand
|
|
|
536 |
#define sunif unif_rand
|
|
|
537 |
#define sexp exp_rand
|
|
|
538 |
|
|
|
539 |
/* Machine Characteristics */
|
|
|
540 |
|
|
|
541 |
double d1mach(int);
|
|
|
542 |
int i1mach(int);
|
|
|
543 |
|
|
|
544 |
/* General Support Functions */
|
|
|
545 |
|
|
|
546 |
double fmod(double, double);
|
|
|
547 |
double ftrunc(double);
|
|
|
548 |
double fsquare(double);
|
|
|
549 |
double fcube(double);
|
|
|
550 |
|
|
|
551 |
/* Chebyshev Series */
|
|
|
552 |
|
|
|
553 |
int chebyshev_init(double*, int, double);
|
|
|
554 |
double chebyshev_eval(double, double *, int);
|
|
|
555 |
|
|
|
556 |
/* Gamma and Related Functions */
|
|
|
557 |
|
|
|
558 |
void gammalims(double*, double*);
|
| 10743 |
maechler |
559 |
double lgammacor(double);/* log(gamma) correction */
|
| 11112 |
maechler |
560 |
double stirlerr(double);/* Stirling expansion "error" */
|
| 8096 |
ripley |
561 |
double gammafn(double);
|
|
|
562 |
double gamma_cody(double);
|
|
|
563 |
double lgammafn(double);
|
|
|
564 |
void dpsifn(double, int, int, int, double*, int*, int*);
|
|
|
565 |
double digamma(double);
|
|
|
566 |
double trigamma(double);
|
|
|
567 |
double tetragamma(double);
|
|
|
568 |
double pentagamma(double);
|
|
|
569 |
|
|
|
570 |
double choose(double, double);
|
|
|
571 |
double lchoose(double, double);
|
|
|
572 |
double fastchoose(double, double);
|
|
|
573 |
double lfastchoose(double, double);
|
|
|
574 |
|
| 10743 |
maechler |
575 |
|
|
|
576 |
double bd0(double, double);
|
|
|
577 |
|
| 8096 |
ripley |
578 |
/* Bessel Functions of All Kinds */
|
|
|
579 |
|
|
|
580 |
double bessel_i(double, double, double);
|
|
|
581 |
double bessel_j(double, double);
|
|
|
582 |
double bessel_k(double, double, double);
|
|
|
583 |
double bessel_y(double, double);
|
|
|
584 |
void I_bessel(double*, double*, long*, long*, double*, long*);
|
|
|
585 |
void J_bessel(double*, double*, long*, double*, long*);
|
|
|
586 |
void K_bessel(double*, double*, long*, long*, double*, long*);
|
|
|
587 |
void Y_bessel(double*, double*, long*, double*, long*);
|
|
|
588 |
|
|
|
589 |
/* Beta and Related Functions */
|
|
|
590 |
|
|
|
591 |
double beta(double, double);
|
|
|
592 |
double lbeta(double, double);
|
|
|
593 |
|
| 9363 |
ripley |
594 |
|
|
|
595 |
#ifdef MATHLIB_STANDALONE
|
|
|
596 |
#ifndef MATHLIB_PRIVATE_H
|
|
|
597 |
|
|
|
598 |
#define ISNAN(x) R_IsNaNorNA(x)
|
|
|
599 |
#define R_FINITE(x) R_finite(x)
|
|
|
600 |
int R_IsNaNorNA(double);
|
|
|
601 |
int R_finite(double);
|
|
|
602 |
|
|
|
603 |
#ifdef WIN32
|
| 11211 |
ripley |
604 |
# define NA_REAL (*_imp__NA_REAL)
|
|
|
605 |
# define R_NegInf (*_imp__R_NegInf)
|
|
|
606 |
# define R_PosInf (*_imp__R_PosInf)
|
|
|
607 |
# define N01_kind (*_imp__N01_kind)
|
|
|
608 |
# endif
|
| 9363 |
ripley |
609 |
|
| 11211 |
ripley |
610 |
#endif /* not MATHLIB_PRIVATE_H */
|
|
|
611 |
#endif /* MATHLIB_STANDALONE */
|
| 9363 |
ripley |
612 |
|
|
|
613 |
#ifdef MATHLIB_STANDALONE
|
| 11211 |
ripley |
614 |
# define REprintf fprintf(stderr,
|
| 9363 |
ripley |
615 |
#else
|
| 11211 |
ripley |
616 |
# ifndef PRTUTIL_H_
|
| 9363 |
ripley |
617 |
void REprintf(char*, ...);
|
| 11211 |
ripley |
618 |
# endif
|
| 9363 |
ripley |
619 |
#endif
|
| 11211 |
ripley |
620 |
|
|
|
621 |
#ifdef __cplusplus
|
|
|
622 |
}
|
| 9363 |
ripley |
623 |
#endif
|
|
|
624 |
|
| 11211 |
ripley |
625 |
#endif /* MATHLIB_H */
|