/
nmath.h
207 lines (167 loc) · 5.69 KB
/
nmath.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Mathlib : A C Library of Special Functions
* Copyright (C) 1998-2011 The R Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, a copy is available at
* http://www.r-project.org/Licenses/
*/
/* Private header file for use during compilation of Mathlib */
#ifndef MATHLIB_PRIVATE_H
#define MATHLIB_PRIVATE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/* Required by C99 but might be slow */
#ifdef HAVE_LONG_DOUBLE
# define LDOUBLE long double
#else
# define LDOUBLE double
#endif
#include <math.h>
#include <float.h> /* DBL_MIN etc */
#include <Rconfig.h>
#include <Rmath.h>
double Rf_d1mach(int);
#define gamma_cody Rf_gamma_cody
double gamma_cody(double);
#include <R_ext/RS.h>
/* possibly needed for debugging */
#include <R_ext/Print.h>
#ifndef MATHLIB_STANDALONE
#include <R_ext/Error.h>
# define MATHLIB_ERROR(fmt,x) error(fmt,x);
# define MATHLIB_WARNING(fmt,x) warning(fmt,x)
# define MATHLIB_WARNING2(fmt,x,x2) warning(fmt,x,x2)
# define MATHLIB_WARNING3(fmt,x,x2,x3) warning(fmt,x,x2,x3)
# define MATHLIB_WARNING4(fmt,x,x2,x3,x4) warning(fmt,x,x2,x3,x4)
#include <R_ext/Arith.h>
#define ML_POSINF R_PosInf
#define ML_NEGINF R_NegInf
#define ML_NAN R_NaN
void R_CheckUserInterrupt(void);
/* Ei-ji Nakama reported that AIX 5.2 has calloc as a macro and objected
to redefining it. Tests added for 2.2.1 */
#ifdef calloc
# undef calloc
#endif
#define calloc R_chk_calloc
#ifdef free
# undef free
#endif
#define free R_chk_free
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) gettext (String)
#else
#define _(String) (String)
#endif
#else
/* Mathlib standalone */
#include <stdio.h>
#include <stdlib.h> /* for exit */
#define MATHLIB_ERROR(fmt,x) { printf(fmt,x); exit(1); }
#define MATHLIB_WARNING(fmt,x) printf(fmt,x)
#define MATHLIB_WARNING2(fmt,x,x2) printf(fmt,x,x2)
#define MATHLIB_WARNING3(fmt,x,x2,x3) printf(fmt,x,x2,x3)
#define MATHLIB_WARNING4(fmt,x,x2,x3,x4) printf(fmt,x,x2,x3,x4)
#define ISNAN(x) (isnan(x)!=0)
#define R_FINITE(x) R_finite(x)
int R_finite(double);
#define ML_POSINF (1.0 / 0.0)
#define ML_NEGINF ((-1.0) / 0.0)
#define ML_NAN (0.0 / 0.0)
#define _(String) String
#endif /* standalone */
#define ML_VALID(x) (!ISNAN(x))
#define ME_NONE 0
/* no error */
#define ME_DOMAIN 1
/* argument out of domain */
#define ME_RANGE 2
/* value out of range */
#define ME_NOCONV 4
/* process did not converge */
#define ME_PRECISION 8
/* does not have "full" precision */
#define ME_UNDERFLOW 16
/* and underflow occured (important for IEEE)*/
#define ML_ERR_return_NAN { ML_ERROR(ME_DOMAIN, ""); return ML_NAN; }
/* For a long time prior to R 2.3.0 ML_ERROR did nothing.
We don't report ME_DOMAIN errors as the callers collect ML_NANs into
a single warning.
*/
#define ML_ERROR(x, s) { \
if(x > ME_DOMAIN) { \
char *msg = ""; \
switch(x) { \
case ME_DOMAIN: \
msg = _("argument out of domain in '%s'\n"); \
break; \
case ME_RANGE: \
msg = _("value out of range in '%s'\n"); \
break; \
case ME_NOCONV: \
msg = _("convergence failed in '%s'\n"); \
break; \
case ME_PRECISION: \
msg = _("full precision may not have been achieved in '%s'\n"); \
break; \
case ME_UNDERFLOW: \
msg = _("underflow occurred in '%s'\n"); \
break; \
} \
MATHLIB_WARNING(msg, s); \
} \
}
/* Wilcoxon Rank Sum Distribution */
#define WILCOX_MAX 50
#ifdef HAVE_VISIBILITY_ATTRIBUTE
# define attribute_hidden __attribute__ ((visibility ("hidden")))
#else
# define attribute_hidden
#endif
/* Formerly private part of Mathlib.h */
/* always remap internal functions */
#define bd0 Rf_bd0
#define chebyshev_eval Rf_chebyshev_eval
#define chebyshev_init Rf_chebyshev_init
#define gammalims Rf_gammalims
#define lfastchoose Rf_lfastchoose
#define lgammacor Rf_lgammacor
#define stirlerr Rf_stirlerr
/* in Rmath.h
#define gamma_cody Rf_gamma_cody
*/
/* Chebyshev Series */
int attribute_hidden chebyshev_init(double*, int, double);
double attribute_hidden chebyshev_eval(double, const double *, const int);
/* Gamma and Related Functions */
void attribute_hidden gammalims(double*, double*);
double attribute_hidden lgammacor(double); /* log(gamma) correction */
double attribute_hidden stirlerr(double); /* Stirling expansion "error" */
double attribute_hidden lfastchoose(double, double);
double attribute_hidden bd0(double, double);
double attribute_hidden dbinom_raw(double, double, double, double, int);
double attribute_hidden dpois_raw (double, double, int);
double attribute_hidden pnchisq_raw(double, double, double, double, double, int, Rboolean);
double attribute_hidden pgamma_raw(double, double, int, int);
double attribute_hidden pbeta_raw(double, double, double, int, int);
double attribute_hidden qchisq_appr(double, double, double, int, int, double tol);
LDOUBLE attribute_hidden pnbeta_raw(double, double, double, double, double);
double attribute_hidden pnbeta2(double, double, double, double, double, int, int);
int Rf_i1mach(int);
/* From toms708.c */
void attribute_hidden bratio(double a, double b, double x, double y,
double *w, double *w1, int *ierr, int log_p);
#endif /* MATHLIB_PRIVATE_H */