summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/math/test/test_gamma_hooks.hpp
blob: b07c5b83a6a6fe925bab0069513bae0cea101e13 (plain)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//  (C) Copyright John Maddock 2006.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP
#define BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP

#ifdef TEST_CEPHES
namespace other{
extern "C" {
   double gamma(double);
   float gammaf(float);
   long double gammal(long double);
   double lgam(double);
   float lgamf(float);
   long double lgaml(long double);
   float igamf(float, float);
   double igam(double, double);
   long double igaml(long double, long double);
   float igamcf(float, float);
   double igamc(double, double);
   long double igamcl(long double, long double);
}
inline float tgamma(float x)
{ return gammaf(x); }
inline double tgamma(double x)
{ return gamma(x); }
inline long double tgamma(long double x)
{
#ifdef BOOST_MSVC
   return gamma((double)x); 
#else
   return gammal(x); 
#endif
}
inline float lgamma(float x)
{ return lgamf(x); }
inline double lgamma(double x)
{ return lgam(x); }
inline long double lgamma(long double x)
{
#ifdef BOOST_MSVC
   return lgam((double)x); 
#else
   return lgaml(x); 
#endif
}
inline float gamma_q(float x, float y)
{ return igamcf(x, y); }
inline double gamma_q(double x, double y)
{ return igamc(x, y); }
inline long double gamma_q(long double x, long double y)
{
#ifdef BOOST_MSVC
   return igamc((double)x, (double)y); 
#else
   return igamcl(x, y); 
#endif
}
inline float gamma_p(float x, float y)
{ return igamf(x, y); }
inline double gamma_p(double x, double y)
{ return igam(x, y); }
inline long double gamma_p(long double x, long double y)
{
#ifdef BOOST_MSVC
   return igam((double)x, (double)y); 
#else
   return igaml(x, y); 
#endif
}
}
#define TEST_OTHER
#endif

#ifdef TEST_NATIVE
#include <math.h>
namespace other{
#if defined(__FreeBSD__)
// no float version:
inline float tgamma(float x)
{ return ::tgamma(x); }
#else
inline float tgamma(float x)
{ return ::tgammaf(x); }
#endif
inline double tgamma(double x)
{ return ::tgamma(x); }
inline long double tgamma(long double x)
{ 
#if defined(__CYGWIN__) || defined(__FreeBSD__)
   // no long double versions:
   return ::tgamma(x);
#else
   return ::tgammal(x);
#endif
}
#if defined(__FreeBSD__)
inline float lgamma(float x)
{ return ::lgamma(x); }
#else
inline float lgamma(float x)
{ return ::lgammaf(x); }
#endif
inline double lgamma(double x)
{ return ::lgamma(x); }
inline long double lgamma(long double x)
{ 
#if defined(__CYGWIN__) || defined(__FreeBSD__) 
   // no long double versions:
   return ::lgamma(x); 
#else
   return ::lgammal(x); 
#endif
}
}
#define TEST_OTHER
#endif

#ifdef TEST_GSL
#define TEST_OTHER
#include <gsl/gsl_sf_gamma.h>

namespace other{
float tgamma(float z)
{
   return (float)gsl_sf_gamma(z);
}
double tgamma(double z)
{
   return gsl_sf_gamma(z);
}
long double tgamma(long double z)
{
   return gsl_sf_gamma(z);
}
float lgamma(float z)
{
   return (float)gsl_sf_lngamma(z);
}
double lgamma(double z)
{
   return gsl_sf_lngamma(z);
}
long double lgamma(long double z)
{
   return gsl_sf_lngamma(z);
}
inline float gamma_q(float x, float y)
{ return (float)gsl_sf_gamma_inc_Q(x, y); }
inline double gamma_q(double x, double y)
{ return gsl_sf_gamma_inc_Q(x, y); }
inline long double gamma_q(long double x, long double y)
{ return gsl_sf_gamma_inc_Q(x, y); }
inline float gamma_p(float x, float y)
{ return (float)gsl_sf_gamma_inc_P(x, y); }
inline double gamma_p(double x, double y)
{ return gsl_sf_gamma_inc_P(x, y); }
inline long double gamma_p(long double x, long double y)
{ return gsl_sf_gamma_inc_P(x, y); }
}
#endif

#ifdef TEST_DCDFLIB
#define TEST_OTHER
#include <dcdflib.h>

namespace other{
float tgamma(float z)
{
   double v = z;
   return (float)gamma_x(&v);
}
double tgamma(double z)
{
   return gamma_x(&z);
}
long double tgamma(long double z)
{
   double v = z;
   return gamma_x(&v);
}
float lgamma(float z)
{
   double v = z;
   return (float)gamma_log(&v);
}
double lgamma(double z)
{
   double v = z;
   return gamma_log(&v);
}
long double lgamma(long double z)
{
   double v = z;
   return gamma_log(&v);
}
inline double gamma_q(double x, double y)
{ 
   double ans, qans;
   int i = 0;
   gamma_inc (&x, &y, &ans, &qans, &i); 
   return qans;
}
inline float gamma_q(float x, float y)
{ 
   return (float)gamma_q((double)x, (double)y); 
}
inline long double gamma_q(long double x, long double y)
{ 
   return gamma_q((double)x, (double)y); 
}
inline double gamma_p(double x, double y)
{ 
   double ans, qans;
   int i = 0;
   gamma_inc (&x, &y, &ans, &qans, &i); 
   return ans;
}
inline float gamma_p(float x, float y)
{ 
   return (float)gamma_p((double)x, (double)y); 
}
inline long double gamma_p(long double x, long double y)
{ 
   return gamma_p((double)x, (double)y); 
}

inline double gamma_q_inv(double x, double y)
{ 
   double ans, p, nul;
   int i = 0;
   p = 1 - y;
   nul = 0;
   gamma_inc_inv (&x, &ans, &nul, &p, &y, &i); 
   return ans;
}
inline float gamma_q_inv(float x, float y)
{ 
   return (float)gamma_q_inv((double)x, (double)y); 
}
inline long double gamma_q_inv(long double x, long double y)
{ 
   return gamma_q_inv((double)x, (double)y); 
}
inline double gamma_p_inv(double x, double y)
{ 
   double ans, p, nul;
   int i = 0;
   p = 1 - y;
   nul = 0;
   gamma_inc_inv (&x, &ans, &nul, &y, &p, &i); 
   return ans;
}
inline float gamma_p_inv(float x, float y)
{ 
   return (float)gamma_p_inv((double)x, (double)y); 
}
inline long double gamma_p_inv(long double x, long double y)
{ 
   return gamma_p_inv((double)x, (double)y); 
}

}
#endif

#ifdef TEST_OTHER
namespace other{
   boost::math::concepts::real_concept tgamma(boost::math::concepts::real_concept){ return 0; }
   boost::math::concepts::real_concept lgamma(boost::math::concepts::real_concept){ return 0; }
   boost::math::concepts::real_concept gamma_q(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
   boost::math::concepts::real_concept gamma_p(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
   boost::math::concepts::real_concept gamma_p_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
   boost::math::concepts::real_concept gamma_q_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
}
#endif

#endif