• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_igamma.hpp"
8 
9 //
10 // DESCRIPTION:
11 // ~~~~~~~~~~~~
12 //
13 // This file tests the incomplete gamma functions tgamma,
14 // tgamma_lower, gamma_p and gamma_q. 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 
expected_results()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    // Linux:
54    //
55    // These should not really be needed, but on *some* Linux
56    // versions these error rates are quite large and appear to
57    // be related to the accuracy of powl and expl.  On Itanium
58    // or Xeon machines the error rates are much lower than this.
59    // Worst cases appear to be AMD64 machines.
60    //
61    add_expected_result(
62       "[^|]*",                          // compiler
63       "[^|]*",                          // stdlib
64       "linux",                          // platform
65       largest_type,                     // test type(s)
66       "[^|]*medium[^|]*",               // test data group
67       "[^|]*", 1300, 200);                 // test function
68    add_expected_result(
69       "[^|]*",                          // compiler
70       "[^|]*",                          // stdlib
71       ".*Solaris.*",                    // platform
72       "real_concept",                   // test type(s)
73       "[^|]*medium[^|]*",               // test data group
74       "[^|]*", 1000, 200);              // test function
75    add_expected_result(
76       "[^|]*",                          // compiler
77       "[^|]*",                          // stdlib
78       "linux",                          // platform
79       largest_type,                     // test type(s)
80       "[^|]*integer[^|]*",               // test data group
81       "[^|]*", 1300, 200);                 // test function
82    add_expected_result(
83       "[^|]*",                          // compiler
84       "[^|]*",                          // stdlib
85       "linux",                          // platform
86       "real_concept",                   // test type(s)
87       "[^|]*medium[^|]*",               // test data group
88       "[^|]*", 1300, 200);                // test function
89    add_expected_result(
90       "[^|]*",                          // compiler
91       "[^|]*",                          // stdlib
92       "linux",                          // platform
93       "real_concept",                   // test type(s)
94       "[^|]*integer[^|]*",               // test data group
95       "[^|]*", 600, 200);                // test function
96 
97    //
98    // Mac OS X:
99    // It's not clear why these should be required, but see notes above
100    // about Linux.
101    //
102    add_expected_result(
103       "[^|]*",                          // compiler
104       "[^|]*",                          // stdlib
105       "Mac OS",                          // platform
106       largest_type,                     // test type(s)
107       "[^|]*medium[^|]*",               // test data group
108       "[^|]*", 5000, 1000);                 // test function
109    add_expected_result(
110       "[^|]*",                          // compiler
111       "[^|]*",                          // stdlib
112       "Mac OS",                          // platform
113       largest_type,                     // test type(s)
114       "[^|]*small[^|]*",               // test data group
115       "[^|]*", 80, 40);                 // test function
116    add_expected_result(
117       "[^|]*",                          // compiler
118       "[^|]*",                          // stdlib
119       "Mac OS",                          // platform
120       largest_type,                     // test type(s)
121       "[^|]*integer[^|]*",               // test data group
122       "[^|]*", 2000, 300);                 // test function
123    add_expected_result(
124       "[^|]*",                          // compiler
125       "[^|]*",                          // stdlib
126       "Mac OS",                          // platform
127       "real_concept",                   // test type(s)
128       "[^|]*medium[^|]*",               // test data group
129       "[^|]*", 5000, 1000);                // test function
130    add_expected_result(
131       "[^|]*",                          // compiler
132       "[^|]*",                          // stdlib
133       "Mac OS",                          // platform
134       "real_concept",                     // test type(s)
135       "[^|]*small[^|]*",               // test data group
136       "[^|]*", 75, 15);                 // test function
137    add_expected_result(
138       "[^|]*",                          // compiler
139       "[^|]*",                          // stdlib
140       "Mac OS",                          // platform
141       "real_concept",                   // test type(s)
142       "[^|]*integer[^|]*",               // test data group
143       "[^|]*", 2000, 300);                // test function
144    //
145    // HP-UX:
146    //
147    add_expected_result(
148       "[^|]*",                          // compiler
149       "[^|]*",                          // stdlib
150       "HP-UX",                          // platform
151       largest_type,                     // test type(s)
152       "[^|]*medium[^|]*",               // test data group
153       "[^|]*", 500, 50);                 // test function
154    add_expected_result(
155       "[^|]*",                          // compiler
156       "[^|]*",                          // stdlib
157       "HP-UX",                          // platform
158       "real_concept",                   // test type(s)
159       "[^|]*medium[^|]*",               // test data group
160       "[^|]*", 500, 100);                // test function
161    //
162    // Sun OS:
163    //
164    add_expected_result(
165       "[^|]*",                          // compiler
166       "[^|]*",                          // stdlib
167       "Sun.*",                          // platform
168       largest_type,                     // test type(s)
169       "[^|]*medium[^|]*",               // test data group
170       "[^|]*", 500, 100);               // test function
171    add_expected_result(
172       "[^|]*",                          // compiler
173       "[^|]*",                          // stdlib
174       "Sun.*",                          // platform
175       largest_type,                     // test type(s)
176       "[^|]*integer[^|]*",              // test data group
177       "[^|]*", 100, 30);                // test function
178    add_expected_result(
179       "[^|]*",                          // compiler
180       "[^|]*",                          // stdlib
181       "Sun.*",                          // platform
182       "real_concept",                   // test type(s)
183       "[^|]*medium[^|]*",               // test data group
184       "[^|]*", 500, 100);                // test function
185    add_expected_result(
186       "[^|]*",                          // compiler
187       "[^|]*",                          // stdlib
188       "Sun.*",                          // platform
189       "real_concept",                   // test type(s)
190       "[^|]*integer[^|]*",               // test data group
191       "[^|]*", 100, 30);                // test function
192 
193    //
194    // Mac OS X:
195    //
196    add_expected_result(
197       "[^|]*",                          // compiler
198       "[^|]*",                          // stdlib
199       "Mac OS",                          // platform
200       largest_type,                     // test type(s)
201       "[^|]*medium[^|]*",               // test data group
202       "[^|]*", 100, 50);                 // test function
203 
204    //
205    // Minw:
206    //
207    add_expected_result(
208       "GNU[^|]*",                          // compiler
209       "[^|]*",                          // stdlib
210       "Win32[^|]*",                          // platform
211       "real_concept",                   // test type(s)
212       "[^|]*medium[^|]*",               // test data group
213       "[^|]*", 1300, 200);               // test function
214    add_expected_result(
215       "GNU[^|]*",                          // compiler
216       "[^|]*",                          // stdlib
217       "Win32[^|]*",                          // platform
218       largest_type,                     // test type(s)
219       "[^|]*medium[^|]*",               // test data group
220       "[^|]*", 700, 200);                 // test function
221    add_expected_result(
222       "GNU[^|]*",                          // compiler
223       "[^|]*",                          // stdlib
224       "Win32[^|]*",                          // platform
225       largest_type,                     // test type(s)
226       "[^|]*small[^|]*",                // test data group
227       "[^|]*", 100, 50);                  // test function
228    add_expected_result(
229       "GNU[^|]*",                          // compiler
230       "[^|]*",                          // stdlib
231       "Win32[^|]*",                          // platform
232       largest_type,                     // test type(s)
233       "[^|]*integer[^|]*",              // test data group
234       ".*", 120, 50);                   // test function
235    add_expected_result(
236       "GNU[^|]*",                          // compiler
237       "[^|]*",                          // stdlib
238       "Win32[^|]*",                          // platform
239       "real_concept",                   // test type(s)
240       "[^|]*integer[^|]*",              // test data group
241       ".*", 100, 50);                    // test function
242 
243    //
244    // Large exponent range causes more extreme test cases to be evaluated:
245    //
246    if(std::numeric_limits<long double>::max_exponent > std::numeric_limits<double>::max_exponent)
247    {
248       add_expected_result(
249          "[^|]*",                          // compiler
250          "[^|]*",                          // stdlib
251          "[^|]*",                          // platform
252          largest_type,                     // test type(s)
253          "[^|]*large[^|]*",                // test data group
254          ".*", 40000, 3000);  // test function
255    }
256 
257 
258    //
259    // Catch all cases come last:
260    //
261    add_expected_result(
262       "[^|]*",                          // compiler
263       "[^|]*",                          // stdlib
264       "[^|]*",                          // platform
265       largest_type,                     // test type(s)
266       "[^|]*medium[^|]*",               // test data group
267       "[^|]*", 50, 20);                 // test function
268    add_expected_result(
269       "[^|]*",                          // compiler
270       "[^|]*",                          // stdlib
271       "[^|]*",                          // platform
272       largest_type,                     // test type(s)
273       "[^|]*small[^|]*",                // test data group
274       "[^|]*", 20, 10);                  // test function
275    add_expected_result(
276       "[^|]*",                          // compiler
277       "[^|]*",                          // stdlib
278       "[^|]*",                          // platform
279       largest_type,                     // test type(s)
280       "[^|]*large[^|]*",                // test data group
281       "gamma_q", 500, 50);  // test function
282    add_expected_result(
283       "[^|]*",                          // compiler
284       "[^|]*",                          // stdlib
285       "Cygwin",                         // platform
286       largest_type,                     // test type(s)
287       "[^|]*large[^|]*",                // test data group
288       "gamma_p", 700, 50);  // test function
289    add_expected_result(
290       "[^|]*",                          // compiler
291       "[^|]*",                          // stdlib
292       "[^|]*",                          // platform
293       largest_type,                     // test type(s)
294       "[^|]*large[^|]*",                // test data group
295       "gamma_p", 350, 50);  // test function
296    add_expected_result(
297       "[^|]*",                          // compiler
298       "[^|]*",                          // stdlib
299       "[^|]*",                          // platform
300       largest_type,                     // test type(s)
301       "[^|]*integer[^|]*",              // test data group
302       ".*", 20, 10);                    // test function
303    add_expected_result(
304       "[^|]*",                          // compiler
305       "[^|]*",                          // stdlib
306       "[^|]*",                          // platform
307       "real_concept",                   // test type(s)
308       "[^|]*medium[^|]*",               // test data group
309       "[^|]*", 1500, 400);                // test function
310    add_expected_result(
311       "[^|]*",                          // compiler
312       "[^|]*",                          // stdlib
313       "[^|]*",                          // platform
314       "real_concept",                   // test type(s)
315       "[^|]*small[^|]*",                // test data group
316       ".*", 100, 20);                  // test function
317    add_expected_result(
318       "[^|]*",                          // compiler
319       "[^|]*",                          // stdlib
320       "[^|]*",                          // platform
321       "real_concept",                   // test type(s)
322       "[^|]*large[^|]*",                // test data group
323       ".*", 1000000, 100000);        // test function
324    add_expected_result(
325       "[^|]*",                          // compiler
326       "[^|]*",                          // stdlib
327       "[^|]*",                          // platform
328       "real_concept",                   // test type(s)
329       "[^|]*integer[^|]*",              // test data group
330       ".*", 200, 40);                    // test function
331 
332    //
333    // Finish off by printing out the compiler/stdlib/platform names,
334    // we do this to make it easier to mark up expected error rates.
335    //
336    std::cout << "Tests run with " << BOOST_COMPILER << ", "
337       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
338 }
339 
BOOST_AUTO_TEST_CASE(test_main)340 BOOST_AUTO_TEST_CASE( test_main )
341 {
342    expected_results();
343    BOOST_MATH_CONTROL_FP;
344 
345 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
346    test_spots(0.0F);
347 #endif
348    test_spots(0.0);
349 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
350    test_spots(0.0L);
351 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
352    test_spots(boost::math::concepts::real_concept(0.1));
353 #endif
354 #endif
355 
356 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
357    test_gamma(0.1F, "float");
358 #endif
359    test_gamma(0.1, "double");
360 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
361    test_gamma(0.1L, "long double");
362 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
363 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
364    test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
365 #endif
366 #endif
367 #else
368    std::cout << "<note>The long double tests have been disabled on this platform "
369       "either because the long double overloads of the usual math functions are "
370       "not available at all, or because they are too inaccurate for these tests "
371       "to pass.</note>" << std::endl;
372 #endif
373 
374 }
375 
376 
377 
378