1 // (C) Copyright John Maddock 2006.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP
7 #define BOOST_MATH_TEST_GAMMA_OTHER_HOOKS_HPP
8
9 #ifdef TEST_CEPHES
10 namespace other{
11 extern "C" {
12 double gamma(double);
13 float gammaf(float);
14 long double gammal(long double);
15 double lgam(double);
16 float lgamf(float);
17 long double lgaml(long double);
18 float igamf(float, float);
19 double igam(double, double);
20 long double igaml(long double, long double);
21 float igamcf(float, float);
22 double igamc(double, double);
23 long double igamcl(long double, long double);
24 }
tgamma(float x)25 inline float tgamma(float x)
26 { return gammaf(x); }
tgamma(double x)27 inline double tgamma(double x)
28 { return gamma(x); }
tgamma(long double x)29 inline long double tgamma(long double x)
30 {
31 #ifdef BOOST_MSVC
32 return gamma((double)x);
33 #else
34 return gammal(x);
35 #endif
36 }
lgamma(float x)37 inline float lgamma(float x)
38 { return lgamf(x); }
lgamma(double x)39 inline double lgamma(double x)
40 { return lgam(x); }
lgamma(long double x)41 inline long double lgamma(long double x)
42 {
43 #ifdef BOOST_MSVC
44 return lgam((double)x);
45 #else
46 return lgaml(x);
47 #endif
48 }
gamma_q(float x,float y)49 inline float gamma_q(float x, float y)
50 { return igamcf(x, y); }
gamma_q(double x,double y)51 inline double gamma_q(double x, double y)
52 { return igamc(x, y); }
gamma_q(long double x,long double y)53 inline long double gamma_q(long double x, long double y)
54 {
55 #ifdef BOOST_MSVC
56 return igamc((double)x, (double)y);
57 #else
58 return igamcl(x, y);
59 #endif
60 }
gamma_p(float x,float y)61 inline float gamma_p(float x, float y)
62 { return igamf(x, y); }
gamma_p(double x,double y)63 inline double gamma_p(double x, double y)
64 { return igam(x, y); }
gamma_p(long double x,long double y)65 inline long double gamma_p(long double x, long double y)
66 {
67 #ifdef BOOST_MSVC
68 return igam((double)x, (double)y);
69 #else
70 return igaml(x, y);
71 #endif
72 }
73 }
74 #define TEST_OTHER
75 #endif
76
77 #ifdef TEST_NATIVE
78 #include <math.h>
79 namespace other{
80 #if defined(__FreeBSD__)
81 // no float version:
tgamma(float x)82 inline float tgamma(float x)
83 { return ::tgamma(x); }
84 #else
85 inline float tgamma(float x)
86 { return ::tgammaf(x); }
87 #endif
tgamma(double x)88 inline double tgamma(double x)
89 { return ::tgamma(x); }
tgamma(long double x)90 inline long double tgamma(long double x)
91 {
92 #if defined(__CYGWIN__) || defined(__FreeBSD__)
93 // no long double versions:
94 return ::tgamma(x);
95 #else
96 return ::tgammal(x);
97 #endif
98 }
99 #if defined(__FreeBSD__)
lgamma(float x)100 inline float lgamma(float x)
101 { return ::lgamma(x); }
102 #else
lgamma(float x)103 inline float lgamma(float x)
104 { return ::lgammaf(x); }
105 #endif
lgamma(double x)106 inline double lgamma(double x)
107 { return ::lgamma(x); }
lgamma(long double x)108 inline long double lgamma(long double x)
109 {
110 #if defined(__CYGWIN__) || defined(__FreeBSD__)
111 // no long double versions:
112 return ::lgamma(x);
113 #else
114 return ::lgammal(x);
115 #endif
116 }
117 }
118 #define TEST_OTHER
119 #endif
120
121 #ifdef TEST_GSL
122 #define TEST_OTHER
123 #include <gsl/gsl_sf_gamma.h>
124
125 namespace other{
tgamma(float z)126 float tgamma(float z)
127 {
128 return (float)gsl_sf_gamma(z);
129 }
tgamma(double z)130 double tgamma(double z)
131 {
132 return gsl_sf_gamma(z);
133 }
tgamma(long double z)134 long double tgamma(long double z)
135 {
136 return gsl_sf_gamma(z);
137 }
lgamma(float z)138 float lgamma(float z)
139 {
140 return (float)gsl_sf_lngamma(z);
141 }
lgamma(double z)142 double lgamma(double z)
143 {
144 return gsl_sf_lngamma(z);
145 }
lgamma(long double z)146 long double lgamma(long double z)
147 {
148 return gsl_sf_lngamma(z);
149 }
gamma_q(float x,float y)150 inline float gamma_q(float x, float y)
151 { return (float)gsl_sf_gamma_inc_Q(x, y); }
gamma_q(double x,double y)152 inline double gamma_q(double x, double y)
153 { return gsl_sf_gamma_inc_Q(x, y); }
gamma_q(long double x,long double y)154 inline long double gamma_q(long double x, long double y)
155 { return gsl_sf_gamma_inc_Q(x, y); }
gamma_p(float x,float y)156 inline float gamma_p(float x, float y)
157 { return (float)gsl_sf_gamma_inc_P(x, y); }
gamma_p(double x,double y)158 inline double gamma_p(double x, double y)
159 { return gsl_sf_gamma_inc_P(x, y); }
gamma_p(long double x,long double y)160 inline long double gamma_p(long double x, long double y)
161 { return gsl_sf_gamma_inc_P(x, y); }
162 }
163 #endif
164
165 #ifdef TEST_DCDFLIB
166 #define TEST_OTHER
167 #include <dcdflib.h>
168
169 namespace other{
tgamma(float z)170 float tgamma(float z)
171 {
172 double v = z;
173 return (float)gamma_x(&v);
174 }
tgamma(double z)175 double tgamma(double z)
176 {
177 return gamma_x(&z);
178 }
tgamma(long double z)179 long double tgamma(long double z)
180 {
181 double v = z;
182 return gamma_x(&v);
183 }
lgamma(float z)184 float lgamma(float z)
185 {
186 double v = z;
187 return (float)gamma_log(&v);
188 }
lgamma(double z)189 double lgamma(double z)
190 {
191 double v = z;
192 return gamma_log(&v);
193 }
lgamma(long double z)194 long double lgamma(long double z)
195 {
196 double v = z;
197 return gamma_log(&v);
198 }
gamma_q(double x,double y)199 inline double gamma_q(double x, double y)
200 {
201 double ans, qans;
202 int i = 0;
203 gamma_inc (&x, &y, &ans, &qans, &i);
204 return qans;
205 }
gamma_q(float x,float y)206 inline float gamma_q(float x, float y)
207 {
208 return (float)gamma_q((double)x, (double)y);
209 }
gamma_q(long double x,long double y)210 inline long double gamma_q(long double x, long double y)
211 {
212 return gamma_q((double)x, (double)y);
213 }
gamma_p(double x,double y)214 inline double gamma_p(double x, double y)
215 {
216 double ans, qans;
217 int i = 0;
218 gamma_inc (&x, &y, &ans, &qans, &i);
219 return ans;
220 }
gamma_p(float x,float y)221 inline float gamma_p(float x, float y)
222 {
223 return (float)gamma_p((double)x, (double)y);
224 }
gamma_p(long double x,long double y)225 inline long double gamma_p(long double x, long double y)
226 {
227 return gamma_p((double)x, (double)y);
228 }
229
gamma_q_inv(double x,double y)230 inline double gamma_q_inv(double x, double y)
231 {
232 double ans, p, nul;
233 int i = 0;
234 p = 1 - y;
235 nul = 0;
236 gamma_inc_inv (&x, &ans, &nul, &p, &y, &i);
237 return ans;
238 }
gamma_q_inv(float x,float y)239 inline float gamma_q_inv(float x, float y)
240 {
241 return (float)gamma_q_inv((double)x, (double)y);
242 }
gamma_q_inv(long double x,long double y)243 inline long double gamma_q_inv(long double x, long double y)
244 {
245 return gamma_q_inv((double)x, (double)y);
246 }
gamma_p_inv(double x,double y)247 inline double gamma_p_inv(double x, double y)
248 {
249 double ans, p, nul;
250 int i = 0;
251 p = 1 - y;
252 nul = 0;
253 gamma_inc_inv (&x, &ans, &nul, &y, &p, &i);
254 return ans;
255 }
gamma_p_inv(float x,float y)256 inline float gamma_p_inv(float x, float y)
257 {
258 return (float)gamma_p_inv((double)x, (double)y);
259 }
gamma_p_inv(long double x,long double y)260 inline long double gamma_p_inv(long double x, long double y)
261 {
262 return gamma_p_inv((double)x, (double)y);
263 }
264
265 }
266 #endif
267
268 #ifdef TEST_OTHER
269 namespace other{
tgamma(boost::math::concepts::real_concept)270 boost::math::concepts::real_concept tgamma(boost::math::concepts::real_concept){ return 0; }
lgamma(boost::math::concepts::real_concept)271 boost::math::concepts::real_concept lgamma(boost::math::concepts::real_concept){ return 0; }
gamma_q(boost::math::concepts::real_concept,boost::math::concepts::real_concept)272 boost::math::concepts::real_concept gamma_q(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
gamma_p(boost::math::concepts::real_concept,boost::math::concepts::real_concept)273 boost::math::concepts::real_concept gamma_p(boost::math::concepts::real_concept, boost::math::concepts::real_concept){ return 0; }
gamma_p_inv(boost::math::concepts::real_concept x,boost::math::concepts::real_concept y)274 boost::math::concepts::real_concept gamma_p_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
gamma_q_inv(boost::math::concepts::real_concept x,boost::math::concepts::real_concept y)275 boost::math::concepts::real_concept gamma_q_inv(boost::math::concepts::real_concept x, boost::math::concepts::real_concept y){ return 0; }
276 }
277 #endif
278
279 #endif
280
281
282