Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / include / Rmath.h @ 2486

History | View | Annotate | Download (16.9 kB)

1
/* -*- C -*-
2
 *  Mathlib : A C Library of Special Functions
3
 *  Copyright (C) 1998-2013  The R Core Team
4
 *  Copyright (C) 2004       The R Foundation
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU Lesser General Public License as published by
8
 *  the Free Software Foundation; either version 2.1 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU Lesser General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Lesser General Public License
17
 *  along with this program; if not, a copy is available at
18
 *  http://www.r-project.org/Licenses/
19
 *
20

21
 * Rmath.h  should contain ALL headers from R's C code in `src/nmath'
22
   -------  such that ``the Math library'' can be used by simply
23

24
   ``#include <Rmath.h> ''
25

26
   and nothing else.
27

28
   It is part of the API and supports 'standalone Rmath'.
29

30
*/
31
#ifndef RMATH_H
32
#define RMATH_H
33

    
34
/* Note that on some systems we need to include math.h before the
35
   defines below. */
36
#ifndef NO_C_HEADERS
37
# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
38
# include <math.h>
39
#endif
40

    
41
/*-- Mathlib as part of R --  define this for standalone : */
42
/* #undef MATHLIB_STANDALONE */
43

    
44
#define R_VERSION_STRING "3.1.2"
45

    
46
#ifndef HAVE_EXPM1
47
# define HAVE_EXPM1 1
48
#endif
49

    
50
#ifndef HAVE_HYPOT
51
# define HAVE_HYPOT 1
52
#endif
53

    
54
#ifndef HAVE_LOG1P
55
# define HAVE_LOG1P 1
56
#endif
57

    
58
#ifndef HAVE_WORKING_LOG1P
59
# define HAVE_WORKING_LOG1P 1
60
#endif
61

    
62
#if defined(HAVE_LOG1P) && !defined(HAVE_WORKING_LOG1P)
63
/* remap to avoid problems with getting the right entry point */
64
double  Rlog1p(double);
65
#define log1p Rlog1p
66
#endif
67

    
68

    
69
        /* Undo SGI Madness */
70

    
71
#ifdef __sgi
72
# ifdef ftrunc
73
#  undef ftrunc
74
# endif
75
# ifdef qexp
76
#  undef qexp
77
# endif
78
# ifdef qgamma
79
#  undef qgamma
80
# endif
81
#endif
82

    
83

    
84
/* ----- The following constants and entry points are part of the R API ---- */
85

    
86
/* 30 Decimal-place constants */
87
/* Computed with bc -l (scale=32; proper round) */
88

    
89
/* SVID & X/Open Constants */
90
/* Names from Solaris math.h */
91

    
92
#ifndef M_E
93
#define M_E                2.718281828459045235360287471353        /* e */
94
#endif
95

    
96
#ifndef M_LOG2E
97
#define M_LOG2E                1.442695040888963407359924681002        /* log2(e) */
98
#endif
99

    
100
#ifndef M_LOG10E
101
#define M_LOG10E        0.434294481903251827651128918917        /* log10(e) */
102
#endif
103

    
104
#ifndef M_LN2
105
#define M_LN2                0.693147180559945309417232121458        /* ln(2) */
106
#endif
107

    
108
#ifndef M_LN10
109
#define M_LN10                2.302585092994045684017991454684        /* ln(10) */
110
#endif
111

    
112
#ifndef M_PI
113
#define M_PI                3.141592653589793238462643383280        /* pi */
114
#endif
115

    
116
#ifndef M_2PI
117
#define M_2PI                6.283185307179586476925286766559        /* 2*pi */
118
#endif
119

    
120
#ifndef M_PI_2
121
#define M_PI_2                1.570796326794896619231321691640        /* pi/2 */
122
#endif
123

    
124
#ifndef M_PI_4
125
#define M_PI_4                0.785398163397448309615660845820        /* pi/4 */
126
#endif
127

    
128
#ifndef M_1_PI
129
#define M_1_PI                0.318309886183790671537767526745        /* 1/pi */
130
#endif
131

    
132
#ifndef M_2_PI
133
#define M_2_PI                0.636619772367581343075535053490        /* 2/pi */
134
#endif
135

    
136
#ifndef M_2_SQRTPI
137
#define M_2_SQRTPI        1.128379167095512573896158903122        /* 2/sqrt(pi) */
138
#endif
139

    
140
#ifndef M_SQRT2
141
#define M_SQRT2                1.414213562373095048801688724210        /* sqrt(2) */
142
#endif
143

    
144
#ifndef M_SQRT1_2
145
#define M_SQRT1_2        0.707106781186547524400844362105        /* 1/sqrt(2) */
146
#endif
147

    
148
/* R-Specific Constants */
149

    
150
#ifndef M_SQRT_3
151
#define M_SQRT_3        1.732050807568877293527446341506        /* sqrt(3) */
152
#endif
153

    
154
#ifndef M_SQRT_32
155
#define M_SQRT_32        5.656854249492380195206754896838        /* sqrt(32) */
156
#endif
157

    
158
#ifndef M_LOG10_2
159
#define M_LOG10_2        0.301029995663981195213738894724        /* log10(2) */
160
#endif
161

    
162
#ifndef M_SQRT_PI
163
#define M_SQRT_PI        1.772453850905516027298167483341        /* sqrt(pi) */
164
#endif
165

    
166
#ifndef M_1_SQRT_2PI
167
#define M_1_SQRT_2PI        0.398942280401432677939946059934        /* 1/sqrt(2pi) */
168
#endif
169

    
170
#ifndef M_SQRT_2dPI
171
#define M_SQRT_2dPI        0.797884560802865355879892119869        /* sqrt(2/pi) */
172
#endif
173

    
174

    
175
#ifndef M_LN_2PI
176
#define M_LN_2PI        1.837877066409345483560659472811        /* log(2*pi) */
177
#endif
178

    
179
#ifndef M_LN_SQRT_PI
180
#define M_LN_SQRT_PI        0.572364942924700087071713675677        /* log(sqrt(pi))
181
                                                                   == log(pi)/2 */
182
#endif
183

    
184
#ifndef M_LN_SQRT_2PI
185
#define M_LN_SQRT_2PI        0.918938533204672741780329736406        /* log(sqrt(2*pi))
186
                                                                 == log(2*pi)/2 */
187
#endif
188

    
189
#ifndef M_LN_SQRT_PId2
190
#define M_LN_SQRT_PId2        0.225791352644727432363097614947        /* log(sqrt(pi/2))
191
                                                                   == log(pi/2)/2 */
192
#endif
193

    
194

    
195
#ifdef MATHLIB_STANDALONE
196
# ifndef R_EXT_BOOLEAN_H_
197
/* "copy-paste" R_ext/Boolean.h if not already included: */
198
 #define R_EXT_BOOLEAN_H_
199
 #undef FALSE
200
 #undef TRUE
201
 typedef enum { FALSE = 0, TRUE } Rboolean;
202
# endif
203
#else
204
# include <R_ext/Boolean.h>
205
#endif
206

    
207

    
208
#if !defined(MATHLIB_STANDALONE) && !defined(R_NO_REMAP_RMATH)
209
#define bessel_i        Rf_bessel_i
210
#define bessel_j        Rf_bessel_j
211
#define bessel_k        Rf_bessel_k
212
#define bessel_y        Rf_bessel_y
213
#define bessel_i_ex        Rf_bessel_i_ex
214
#define bessel_j_ex        Rf_bessel_j_ex
215
#define bessel_k_ex        Rf_bessel_k_ex
216
#define bessel_y_ex        Rf_bessel_y_ex
217
#define beta                Rf_beta
218
#define choose                Rf_choose
219
#define dbeta                Rf_dbeta
220
#define dbinom                Rf_dbinom
221
#define dcauchy                Rf_dcauchy
222
#define dchisq                Rf_dchisq
223
#define dexp                Rf_dexp
224
#define df                Rf_df
225
#define dgamma                Rf_dgamma
226
#define dgeom                Rf_dgeom
227
#define dhyper                Rf_dhyper
228
#define digamma                Rf_digamma
229
#define dlnorm                Rf_dlnorm
230
#define dlogis                Rf_dlogis
231
#define dnbeta                Rf_dnbeta
232
#define dnbinom                Rf_dnbinom
233
#define dnbinom_mu        Rf_dnbinom_mu
234
#define dnchisq                Rf_dnchisq
235
#define dnf                Rf_dnf
236
#define dnorm4                Rf_dnorm4
237
#define dnt                Rf_dnt
238
#define dpois                Rf_dpois
239
#define dpsifn                Rf_dpsifn
240
#define dsignrank        Rf_dsignrank
241
#define dt                Rf_dt
242
#define dtukey                Rf_dtukey
243
#define dunif                Rf_dunif
244
#define dweibull        Rf_dweibull
245
#define dwilcox                Rf_dwilcox
246
#define fmax2                Rf_fmax2
247
#define fmin2                Rf_fmin2
248
#define fprec                Rf_fprec
249
#define fround                Rf_fround
250
#define ftrunc                Rf_ftrunc
251
#define fsign                Rf_fsign
252
#define gammafn                Rf_gammafn
253
#define imax2                Rf_imax2
254
#define imin2                Rf_imin2
255
#define lbeta                Rf_lbeta
256
#define lchoose                Rf_lchoose
257
#define lgammafn        Rf_lgammafn
258
#define lgammafn_sign        Rf_lgammafn_sign
259
#define lgamma1p        Rf_lgamma1p
260
#define log1pmx                Rf_log1pmx
261
#define logspace_add        Rf_logspace_add
262
#define logspace_sub        Rf_logspace_sub
263
#define pbeta                Rf_pbeta
264
#define pbeta_raw        Rf_pbeta_raw
265
#define pbinom                Rf_pbinom
266
#define pcauchy                Rf_pcauchy
267
#define pchisq                Rf_pchisq
268
#define pentagamma        Rf_pentagamma
269
#define pexp                Rf_pexp
270
#define pf                Rf_pf
271
#define pgamma                Rf_pgamma
272
#define pgeom                Rf_pgeom
273
#define phyper                Rf_phyper
274
#define plnorm                Rf_plnorm
275
#define plogis                Rf_plogis
276
#define pnbeta                Rf_pnbeta
277
#define pnbinom                Rf_pnbinom
278
#define pnbinom_mu             Rf_pnbinom_mu
279
#define pnchisq                Rf_pnchisq
280
#define pnf                Rf_pnf
281
#define pnorm5                Rf_pnorm5
282
#define pnorm_both        Rf_pnorm_both
283
#define pnt                Rf_pnt
284
#define ppois                Rf_ppois
285
#define psignrank        Rf_psignrank
286
#define psigamma        Rf_psigamma
287
#define pt                Rf_pt
288
#define ptukey                Rf_ptukey
289
#define punif                Rf_punif
290
#define pythag                Rf_pythag
291
#define pweibull        Rf_pweibull
292
#define pwilcox                Rf_pwilcox
293
#define qbeta                Rf_qbeta
294
#define qbinom                Rf_qbinom
295
#define qcauchy                Rf_qcauchy
296
#define qchisq                Rf_qchisq
297
#define qchisq_appr        Rf_qchisq_appr
298
#define qexp                Rf_qexp
299
#define qf                Rf_qf
300
#define qgamma                Rf_qgamma
301
#define qgeom                Rf_qgeom
302
#define qhyper                Rf_qhyper
303
#define qlnorm                Rf_qlnorm
304
#define qlogis                Rf_qlogis
305
#define qnbeta                Rf_qnbeta
306
#define qnbinom                Rf_qnbinom
307
#define qnbinom_mu             Rf_qnbinom_mu
308
#define qnchisq                Rf_qnchisq
309
#define qnf                Rf_qnf
310
#define qnorm5                Rf_qnorm5
311
#define qnt                Rf_qnt
312
#define qpois                Rf_qpois
313
#define qsignrank        Rf_qsignrank
314
#define qt                Rf_qt
315
#define qtukey                Rf_qtukey
316
#define qunif                Rf_qunif
317
#define qweibull        Rf_qweibull
318
#define qwilcox                Rf_qwilcox
319
#define rbeta                Rf_rbeta
320
#define rbinom                Rf_rbinom
321
#define rcauchy                Rf_rcauchy
322
#define rchisq                Rf_rchisq
323
#define rexp                Rf_rexp
324
#define rf                Rf_rf
325
#define rgamma                Rf_rgamma
326
#define rgeom                Rf_rgeom
327
#define rhyper                Rf_rhyper
328
#define rlnorm                Rf_rlnorm
329
#define rlogis                Rf_rlogis
330
#define rnbeta                Rf_rnbeta
331
#define rnbinom                Rf_rnbinom
332
#define rnchisq                Rf_rnchisq
333
#define rnf                Rf_rnf
334
#define rnorm                Rf_rnorm
335
#define rnt                Rf_rnt
336
#define rpois                Rf_rpois
337
#define rsignrank        Rf_rsignrank
338
#define rt                Rf_rt
339
#define rtukey                Rf_rtukey
340
#define runif                Rf_runif
341
#define rweibull        Rf_rweibull
342
#define rwilcox                Rf_rwilcox
343
#define sign                Rf_sign
344
#define tetragamma        Rf_tetragamma
345
#define trigamma        Rf_trigamma
346
#endif
347

    
348
#define dnorm dnorm4
349
#define pnorm pnorm5
350
#define qnorm qnorm5
351

    
352
#ifdef  __cplusplus
353
extern "C" {
354
#endif
355
        /* R's versions with !R_FINITE checks */
356

    
357
double R_pow(double x, double y);
358
double R_pow_di(double, int);
359

    
360
        /* Random Number Generators */
361

    
362
double        norm_rand(void);
363
double        unif_rand(void);
364
double        exp_rand(void);
365
#ifdef MATHLIB_STANDALONE
366
void        set_seed(unsigned int, unsigned int);
367
void        get_seed(unsigned int *, unsigned int *);
368
#endif
369

    
370
        /* Normal Distribution */
371

    
372
double        dnorm(double, double, double, int);
373
double        pnorm(double, double, double, int, int);
374
double        qnorm(double, double, double, int, int);
375
double        rnorm(double, double);
376
void        pnorm_both(double, double *, double *, int, int);/* both tails */
377

    
378
        /* Uniform Distribution */
379

    
380
double        dunif(double, double, double, int);
381
double        punif(double, double, double, int, int);
382
double        qunif(double, double, double, int, int);
383
double        runif(double, double);
384

    
385
        /* Gamma Distribution */
386

    
387
double        dgamma(double, double, double, int);
388
double        pgamma(double, double, double, int, int);
389
double        qgamma(double, double, double, int, int);
390
double        rgamma(double, double);
391

    
392
double  log1pmx(double);
393
double  log1pexp(double); // <-- ../nmath/plogis.c
394
double  lgamma1p(double);
395
double  logspace_add(double, double);
396
double  logspace_sub(double, double);
397

    
398
        /* Beta Distribution */
399

    
400
double        dbeta(double, double, double, int);
401
double        pbeta(double, double, double, int, int);
402
double        qbeta(double, double, double, int, int);
403
double        rbeta(double, double);
404

    
405
        /* Lognormal Distribution */
406

    
407
double        dlnorm(double, double, double, int);
408
double        plnorm(double, double, double, int, int);
409
double        qlnorm(double, double, double, int, int);
410
double        rlnorm(double, double);
411

    
412
        /* Chi-squared Distribution */
413

    
414
double        dchisq(double, double, int);
415
double        pchisq(double, double, int, int);
416
double        qchisq(double, double, int, int);
417
double        rchisq(double);
418

    
419
        /* Non-central Chi-squared Distribution */
420

    
421
double        dnchisq(double, double, double, int);
422
double        pnchisq(double, double, double, int, int);
423
double        qnchisq(double, double, double, int, int);
424
double        rnchisq(double, double);
425

    
426
        /* F Distibution */
427

    
428
double        df(double, double, double, int);
429
double        pf(double, double, double, int, int);
430
double        qf(double, double, double, int, int);
431
double        rf(double, double);
432

    
433
        /* Student t Distibution */
434

    
435
double        dt(double, double, int);
436
double        pt(double, double, int, int);
437
double        qt(double, double, int, int);
438
double        rt(double);
439

    
440
        /* Binomial Distribution */
441

    
442
double        dbinom(double, double, double, int);
443
double        pbinom(double, double, double, int, int);
444
double        qbinom(double, double, double, int, int);
445
double        rbinom(double, double);
446

    
447
        /* Multnomial Distribution */
448

    
449
void        rmultinom(int, double*, int, int*);
450

    
451
        /* Cauchy Distribution */
452

    
453
double        dcauchy(double, double, double, int);
454
double        pcauchy(double, double, double, int, int);
455
double        qcauchy(double, double, double, int, int);
456
double        rcauchy(double, double);
457

    
458
        /* Exponential Distribution */
459

    
460
double        dexp(double, double, int);
461
double        pexp(double, double, int, int);
462
double        qexp(double, double, int, int);
463
double        rexp(double);
464

    
465
        /* Geometric Distribution */
466

    
467
double        dgeom(double, double, int);
468
double        pgeom(double, double, int, int);
469
double        qgeom(double, double, int, int);
470
double        rgeom(double);
471

    
472
        /* Hypergeometric Distibution */
473

    
474
double        dhyper(double, double, double, double, int);
475
double        phyper(double, double, double, double, int, int);
476
double        qhyper(double, double, double, double, int, int);
477
double        rhyper(double, double, double);
478

    
479
        /* Negative Binomial Distribution */
480

    
481
double        dnbinom(double, double, double, int);
482
double        pnbinom(double, double, double, int, int);
483
double        qnbinom(double, double, double, int, int);
484
double        rnbinom(double, double);
485

    
486
double        dnbinom_mu(double, double, double, int);
487
double        pnbinom_mu(double, double, double, int, int);
488
double        qnbinom_mu(double, double, double, int, int);
489
double        rnbinom_mu(double, double);
490

    
491
        /* Poisson Distribution */
492

    
493
double        dpois(double, double, int);
494
double        ppois(double, double, int, int);
495
double        qpois(double, double, int, int);
496
double        rpois(double);
497

    
498
        /* Weibull Distribution */
499

    
500
double        dweibull(double, double, double, int);
501
double        pweibull(double, double, double, int, int);
502
double        qweibull(double, double, double, int, int);
503
double        rweibull(double, double);
504

    
505
        /* Logistic Distribution */
506

    
507
double        dlogis(double, double, double, int);
508
double        plogis(double, double, double, int, int);
509
double        qlogis(double, double, double, int, int);
510
double        rlogis(double, double);
511

    
512
        /* Non-central Beta Distribution */
513

    
514
double        dnbeta(double, double, double, double, int);
515
double        pnbeta(double, double, double, double, int, int);
516
double        qnbeta(double, double, double, double, int, int);
517
double        rnbeta(double, double, double);
518

    
519
        /* Non-central F Distribution */
520

    
521
double  dnf(double, double, double, double, int);
522
double        pnf(double, double, double, double, int, int);
523
double        qnf(double, double, double, double, int, int);
524

    
525
        /* Non-central Student t Distribution */
526

    
527
double        dnt(double, double, double, int);
528
double        pnt(double, double, double, int, int);
529
double        qnt(double, double, double, int, int);
530

    
531
        /* Studentized Range Distribution */
532

    
533
double        ptukey(double, double, double, double, int, int);
534
double        qtukey(double, double, double, double, int, int);
535

    
536
        /* Wilcoxon Rank Sum Distribution */
537

    
538
double dwilcox(double, double, double, int);
539
double pwilcox(double, double, double, int, int);
540
double qwilcox(double, double, double, int, int);
541
double rwilcox(double, double);
542

    
543
        /* Wilcoxon Signed Rank Distribution */
544

    
545
double dsignrank(double, double, int);
546
double psignrank(double, double, int, int);
547
double qsignrank(double, double, int, int);
548
double rsignrank(double);
549

    
550
        /* Gamma and Related Functions */
551
double        gammafn(double);
552
double        lgammafn(double);
553
double        lgammafn_sign(double, int*);
554
void    dpsifn(double, int, int, int, double*, int*, int*);
555
double        psigamma(double, double);
556
double        digamma(double);
557
double        trigamma(double);
558
double        tetragamma(double);
559
double        pentagamma(double);
560

    
561
double        beta(double, double);
562
double        lbeta(double, double);
563

    
564
double        choose(double, double);
565
double        lchoose(double, double);
566

    
567
        /* Bessel Functions */
568

    
569
double        bessel_i(double, double, double);
570
double        bessel_j(double, double);
571
double        bessel_k(double, double, double);
572
double        bessel_y(double, double);
573
double        bessel_i_ex(double, double, double, double *);
574
double        bessel_j_ex(double, double, double *);
575
double        bessel_k_ex(double, double, double, double *);
576
double        bessel_y_ex(double, double, double *);
577

    
578

    
579
        /* General Support Functions */
580

    
581
#ifndef HAVE_HYPOT
582
double         hypot(double, double);
583
#endif
584
double         pythag(double, double);
585
#ifndef HAVE_EXPM1
586
double  expm1(double); /* = exp(x)-1 {care for small x} */
587
#endif
588
#ifndef HAVE_LOG1P
589
double  log1p(double); /* = log(1+x) {care for small x} */
590
#endif
591
int        imax2(int, int);
592
int        imin2(int, int);
593
double        fmax2(double, double);
594
double        fmin2(double, double);
595
double        sign(double);
596
double        fprec(double, double);
597
double        fround(double, double);
598
double        fsign(double, double);
599
double        ftrunc(double);
600

    
601
double  log1pmx(double); /* Accurate log(1+x) - x, {care for small x} */
602
double  lgamma1p(double);/* accurate log(gamma(x+1)), small x (0 < x < 0.5) */
603

    
604
/* More accurate cos(pi*x), sin(pi*x), tan(pi*x)
605

606
   In future these declarations could clash with system headers if
607
   someone had already included math.h with
608
   __STDC_WANT_IEC_60559_TYPES_EXT__ defined.
609
   We can add a check for that via the value of
610
   __STDC_IEC_60559_FUNCS__ (>= 201ymmL, exact value not yet known).
611
*/
612
double cospi(double);
613
double sinpi(double);
614
double tanpi(double);
615

    
616
/* Compute the log of a sum or difference from logs of terms, i.e.,
617
 *
618
 *     log (exp (logx) + exp (logy))
619
 * or  log (exp (logx) - exp (logy))
620
 *
621
 * without causing overflows or throwing away too much accuracy:
622
 */
623
double  logspace_add(double logx, double logy);
624
double  logspace_sub(double logx, double logy);
625

    
626

    
627
/* ----------------- Private part of the header file ------------------- */
628

    
629
        /* old-R Compatibility */
630

    
631
#ifdef OLD_RMATH_COMPAT
632
# define snorm        norm_rand
633
# define sunif        unif_rand
634
# define sexp        exp_rand
635
#endif
636

    
637
#if defined(MATHLIB_STANDALONE) && !defined(MATHLIB_PRIVATE_H)
638
/* second is defined by nmath.h */
639

    
640
/* If isnan is a macro, as C99 specifies, the C++
641
   math header will undefine it. This happens on OS X */
642
# ifdef __cplusplus
643
  int R_isnancpp(double); /* in mlutils.c */
644
#  define ISNAN(x)     R_isnancpp(x)
645
# else
646
#  define ISNAN(x)     (isnan(x)!=0)
647
# endif
648

    
649
# define R_FINITE(x)    R_finite(x)
650
int R_finite(double);
651

    
652
# ifdef _WIN32  /* not Win32 as no config information */
653
#  ifdef RMATH_DLL
654
#   define R_EXTERN extern __declspec(dllimport)
655
#  else
656
#   define R_EXTERN extern
657
#  endif
658
R_EXTERN double NA_REAL;
659
R_EXTERN double R_PosInf;
660
R_EXTERN double R_NegInf;
661
R_EXTERN int N01_kind;
662
#  undef R_EXTERN
663
#else
664
extern int N01_kind;
665
# endif
666

    
667
#endif /* MATHLIB_STANDALONE */
668

    
669
#ifdef  __cplusplus
670
}
671
#endif
672

    
673
#endif /* RMATH_H */