]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_gamma.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / test / test_gamma.cpp
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 #include <pch_light.hpp>
7 #include "test_gamma.hpp"
8
9 //
10 // DESCRIPTION:
11 // ~~~~~~~~~~~~
12 //
13 // This file tests the functions tgamma and lgamma, and the
14 // function tgamma1pm1. There are two sets of tests, spot
15 // tests which compare our results with selected values computed
16 // using the online special function calculator at
17 // functions.wolfram.com, while the bulk of the accuracy tests
18 // use values generated with NTL::RR at 1000-bit precision
19 // and our generic versions of these functions.
20 //
21 // Note that when this file is first run on a new platform many of
22 // these tests will fail: the default accuracy is 1 epsilon which
23 // is too tight for most platforms. In this situation you will
24 // need to cast a human eye over the error rates reported and make
25 // a judgement as to whether they are acceptable. Either way please
26 // report the results to the Boost mailing list. Acceptable rates of
27 // error are marked up below as a series of regular expressions that
28 // identify the compiler/stdlib/platform/data-type/test-data/test-function
29 // along with the maximum expected peek and RMS mean errors for that
30 // test.
31 //
32
33 void expected_results()
34 {
35 //
36 // Define the max and mean errors expected for
37 // various compilers and platforms.
38 //
39 const char* largest_type;
40 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
41 if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
42 {
43 largest_type = "(long\\s+)?double";
44 }
45 else
46 {
47 largest_type = "long double";
48 }
49 #else
50 largest_type = "(long\\s+)?double";
51 #endif
52 //
53 // G++ on Darwin: results are just slightly worse than we might hope for
54 // but still pretty good:
55 //
56 add_expected_result(
57 ".*", // compiler
58 ".*", // stdlib
59 "Mac OS", // platform
60 largest_type, // test type(s)
61 "factorials", // test data group
62 "tgamma", 100, 15); // test function
63 //
64 // G++ On Win32:
65 //
66 add_expected_result(
67 "GNU.*", // compiler
68 ".*", // stdlib
69 "Win32.*", // platform
70 largest_type, // test type(s)
71 "factorials", // test data group
72 "tgamma", 100, 15); // test function
73 add_expected_result(
74 "GNU.*", // compiler
75 ".*", // stdlib
76 "Win32.*", // platform
77 "real_concept", // test type(s)
78 "factorials", // test data group
79 "tgamma", 600, 200); // test function
80 add_expected_result(
81 "GNU.*", // compiler
82 ".*", // stdlib
83 "Win32.*", // platform
84 "real_concept", // test type(s)
85 "near.*", // test data group
86 "tgamma", 200, 100); // test function
87 //
88 // G++ on Linux, result vary a bit by processor type,
89 // on Itanium results are *much* better than listed here,
90 // but x86 appears to have much less accurate std::pow
91 // that throws off the results:
92 //
93 add_expected_result(
94 ".*", // compiler
95 ".*", // stdlib
96 "linux", // platform
97 largest_type, // test type(s)
98 "factorials", // test data group
99 "tgamma", 600, 200); // test function
100 add_expected_result(
101 ".*", // compiler
102 ".*", // stdlib
103 "linux", // platform
104 largest_type, // test type(s)
105 "factorials", // test data group
106 "lgamma", 30, 10); // test function
107 add_expected_result(
108 ".*", // compiler
109 ".*", // stdlib
110 "linux", // platform
111 largest_type, // test type(s)
112 "near (1|2|-10)", // test data group
113 "tgamma", 10, 5); // test function
114 add_expected_result(
115 ".*", // compiler
116 ".*", // stdlib
117 "linux", // platform
118 largest_type, // test type(s)
119 "near (1|2|-10)", // test data group
120 "lgamma", 50, 50); // test function
121 add_expected_result(
122 ".*", // compiler
123 ".*", // stdlib
124 "linux", // platform
125 largest_type, // test type(s)
126 "tgamma1pm1.*", // test data group
127 "tgamma1pm1", 50, 15); // test function
128 add_expected_result(
129 ".*", // compiler
130 ".*", // stdlib
131 "linux", // platform
132 "real_concept", // test type(s)
133 "factorials", // test data group
134 "tgamma", 600, 100); // test function
135 add_expected_result(
136 ".*", // compiler
137 ".*", // stdlib
138 "linux", // platform
139 "real_concept", // test type(s)
140 "near (0|-55)", // test data group
141 "(t|l)gamma", 300, 150); // test function
142 add_expected_result(
143 ".*", // compiler
144 ".*", // stdlib
145 "linux", // platform
146 "real_concept", // test type(s)
147 "tgamma1pm1.*", // test data group
148 "tgamma1pm1", 40, 10); // test function
149 //
150 // HP-UX results:
151 //
152 add_expected_result(
153 ".*", // compiler
154 ".*", // stdlib
155 "HP-UX", // platform
156 largest_type, // test type(s)
157 "factorials", // test data group
158 "tgamma", 5, 4); // test function
159 add_expected_result(
160 ".*", // compiler
161 ".*", // stdlib
162 "HP-UX", // platform
163 largest_type, // test type(s)
164 "near (0|-55)", // test data group
165 "tgamma", 10, 5); // test function
166 add_expected_result(
167 ".*", // compiler
168 ".*", // stdlib
169 "HP-UX", // platform
170 largest_type, // test type(s)
171 "near (1|2|-10)", // test data group
172 "lgamma", 250, 200); // test function
173 add_expected_result(
174 ".*", // compiler
175 ".*", // stdlib
176 "HP-UX", // platform
177 "real_concept", // test type(s)
178 "factorials", // test data group
179 "lgamma", 50, 20); // test function
180 add_expected_result(
181 ".*", // compiler
182 ".*", // stdlib
183 "HP-UX", // platform
184 "real_concept", // test type(s)
185 "tgamma1pm1.*", // test data group
186 "tgamma1pm1", 200, 80); // test function
187 //
188 // Tru64:
189 //
190 add_expected_result(
191 ".*Tru64.*", // compiler
192 ".*", // stdlib
193 ".*", // platform
194 "real_concept", // test type(s)
195 "factorials", // test data group
196 "lgamma", 50, 20); // test function
197 //
198 // Sun OS:
199 //
200 add_expected_result(
201 ".*", // compiler
202 ".*", // stdlib
203 "Sun.*", // platform
204 largest_type, // test type(s)
205 "factorials", // test data group
206 "tgamma", 450, 100); // test function
207 add_expected_result(
208 ".*", // compiler
209 ".*", // stdlib
210 ".*Solaris.*", // platform
211 "real_concept", // test type(s)
212 "factorials", // test data group
213 "tgamma", 450, 150); // test function
214
215 //
216 // Catch all cases come last:
217 //
218 add_expected_result(
219 ".*", // compiler
220 ".*", // stdlib
221 ".*", // platform
222 largest_type, // test type(s)
223 "factorials", // test data group
224 "tgamma", 4, 1); // test function
225 add_expected_result(
226 ".*", // compiler
227 ".*", // stdlib
228 ".*", // platform
229 largest_type, // test type(s)
230 "factorials", // test data group
231 "lgamma", 9, 1); // test function
232 add_expected_result(
233 ".*", // compiler
234 ".*", // stdlib
235 ".*", // platform
236 largest_type, // test type(s)
237 "near (0|-55)", // test data group
238 "(t|l)gamma", 200, 100); // test function
239 add_expected_result(
240 ".*", // compiler
241 ".*", // stdlib
242 ".*", // platform
243 largest_type, // test type(s)
244 "near (1|2|-10)", // test data group
245 "tgamma", 10, 5); // test function
246 add_expected_result(
247 ".*", // compiler
248 ".*", // stdlib
249 ".*", // platform
250 largest_type, // test type(s)
251 "near (1|2|-10)", // test data group
252 "lgamma", 14, 7); // test function
253 add_expected_result(
254 ".*", // compiler
255 ".*", // stdlib
256 ".*", // platform
257 largest_type, // test type(s)
258 "tgamma1pm1.*", // test data group
259 "tgamma1pm1", 30, 9); // test function
260
261 add_expected_result(
262 ".*", // compiler
263 ".*", // stdlib
264 ".*", // platform
265 "real_concept", // test type(s)
266 "factorials", // test data group
267 "tgamma", 600, 100); // test function
268 add_expected_result(
269 ".*", // compiler
270 ".*", // stdlib
271 ".*", // platform
272 "real_concept", // test type(s)
273 "factorials", // test data group
274 "lgamma", 200, 20); // test function
275 add_expected_result(
276 ".*", // compiler
277 ".*", // stdlib
278 ".*", // platform
279 "real_concept", // test type(s)
280 "near.*", // test data group
281 "tgamma", 300, 100); // test function
282 add_expected_result(
283 ".*", // compiler
284 ".*", // stdlib
285 ".*", // platform
286 "real_concept", // test type(s)
287 "near.*", // test data group
288 "lgamma", 40000000, 10000000); // test function
289 add_expected_result(
290 ".*", // compiler
291 ".*", // stdlib
292 ".*", // platform
293 "real_concept", // test type(s)
294 "tgamma1pm1.*", // test data group
295 "tgamma1pm1", 20, 5); // test function
296
297 //
298 // Finish off by printing out the compiler/stdlib/platform names,
299 // we do this to make it easier to mark up expected error rates.
300 //
301 std::cout << "Tests run with " << BOOST_COMPILER << ", "
302 << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
303 }
304
305 BOOST_AUTO_TEST_CASE( test_main )
306 {
307 expected_results();
308 BOOST_MATH_CONTROL_FP;
309
310 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
311 test_spots(0.0F, "float");
312 #endif
313 test_spots(0.0, "double");
314 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
315 test_spots(0.0L, "long double");
316 test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
317 #endif
318
319 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
320 test_gamma(0.1F, "float");
321 #endif
322 test_gamma(0.1, "double");
323 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
324 test_gamma(0.1L, "long double");
325 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
326 #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
327 test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
328 #endif
329 #endif
330 #else
331 std::cout << "<note>The long double tests have been disabled on this platform "
332 "either because the long double overloads of the usual math functions are "
333 "not available at all, or because they are too inaccurate for these tests "
334 "to pass.</note>" << std::endl;
335 #endif
336
337 }
338
339
340