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_tgamma_ratio.hpp"
8
9 //
10 // DESCRIPTION:
11 // ~~~~~~~~~~~~
12 //
13 // This file tests the gamma ratio functions tgamma_ratio,
14 // and tgamma_delta_ratio. The accuracy tests
15 // use values generated with NTL::RR at 1000-bit precision
16 // and our generic versions of these functions.
17 //
18 // Note that when this file is first run on a new platform many of
19 // these tests will fail: the default accuracy is 1 epsilon which
20 // is too tight for most platforms. In this situation you will
21 // need to cast a human eye over the error rates reported and make
22 // a judgement as to whether they are acceptable. Either way please
23 // report the results to the Boost mailing list. Acceptable rates of
24 // error are marked up below as a series of regular expressions that
25 // identify the compiler/stdlib/platform/data-type/test-data/test-function
26 // along with the maximum expected peek and RMS mean errors for that
27 // test.
28 //
29
expected_results()30 void expected_results()
31 {
32 //
33 // Define the max and mean errors expected for
34 // various compilers and platforms.
35 //
36 const char* largest_type;
37 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
38 if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
39 {
40 largest_type = "(long\\s+)?double";
41 }
42 else
43 {
44 largest_type = "long double";
45 }
46 #else
47 largest_type = "(long\\s+)?double";
48 #endif
49 //
50 // HP-UX
51 // This is a weird one, HP-UX and Mac OS X show up errors at float
52 // precision, that don't show up on other platforms.
53 // There appears to be some kind of rounding issue going on (not enough
54 // precision in the input to get the answer right):
55 //
56 add_expected_result(
57 "[^|]*", // compiler
58 "[^|]*", // stdlib
59 "HP-UX|Mac OS|linux|.*(bsd|BSD).*", // platform
60 "float", // test type(s)
61 "[^|]*", // test data group
62 "tgamma_ratio[^|]*", 35, 8); // test function
63 //
64 // Linux AMD x86em64 has slightly higher rates:
65 //
66 add_expected_result(
67 "[^|]*", // compiler
68 "[^|]*", // stdlib
69 "linux.*", // platform
70 largest_type, // test type(s)
71 "[^|]*", // test data group
72 "tgamma_ratio[^|]*", 300, 100); // test function
73 add_expected_result(
74 "[^|]*", // compiler
75 "[^|]*", // stdlib
76 "linux.*", // platform
77 "real_concept", // test type(s)
78 "[^|]*", // test data group
79 "tgamma_ratio[^|]*", 300, 100); // test function
80
81 add_expected_result(
82 "GNU.*", // compiler
83 "[^|]*", // stdlib
84 "Win32.*", // platform
85 largest_type, // test type(s)
86 "[^|]*", // test data group
87 "tgamma_ratio[^|]*", 300, 100); // test function
88 //
89 // Solaris:
90 //
91 add_expected_result(
92 "[^|]*", // compiler
93 "[^|]*", // stdlib
94 ".*Solaris.*", // platform
95 largest_type, // test type(s)
96 "[^|]*", // test data group
97 "tgamma_ratio[^|]*", 200, 100); // test function
98 //
99 // Catch all cases come last:
100 //
101 add_expected_result(
102 "[^|]*", // compiler
103 "[^|]*", // stdlib
104 "[^|]*", // platform
105 largest_type, // test type(s)
106 "[^|]*", // test data group
107 "tgamma_delta_ratio[^|]*", 30, 20); // test function
108 add_expected_result(
109 "[^|]*", // compiler
110 "[^|]*", // stdlib
111 "[^|]*", // platform
112 largest_type, // test type(s)
113 "[^|]*", // test data group
114 "tgamma_ratio[^|]*", 100, 50); // test function
115 add_expected_result(
116 "[^|]*", // compiler
117 "[^|]*", // stdlib
118 "[^|]*", // platform
119 "real_concept", // test type(s)
120 "[^|]*", // test data group
121 "tgamma_delta_ratio[^|]*", 50, 20); // test function
122 add_expected_result(
123 "[^|]*", // compiler
124 "[^|]*", // stdlib
125 "[^|]*", // platform
126 "real_concept", // test type(s)
127 "[^|]*", // test data group
128 "[^|]*", 250, 150); // test function
129
130 //
131 // Finish off by printing out the compiler/stdlib/platform names,
132 // we do this to make it easier to mark up expected error rates.
133 //
134 std::cout << "Tests run with " << BOOST_COMPILER << ", "
135 << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
136 }
137
BOOST_AUTO_TEST_CASE(test_main)138 BOOST_AUTO_TEST_CASE( test_main )
139 {
140 BOOST_MATH_CONTROL_FP;
141 expected_results();
142
143 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
144 test_tgamma_ratio(0.1F, "float");
145 #endif
146 test_tgamma_ratio(0.1, "double");
147 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
148 test_tgamma_ratio(0.1L, "long double");
149 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
150 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
151 test_tgamma_ratio(boost::math::concepts::real_concept(0.1), "real_concept");
152 #endif
153 #endif
154 #else
155 std::cout << "<note>The long double tests have been disabled on this platform "
156 "either because the long double overloads of the usual math functions are "
157 "not available at all, or because they are too inaccurate for these tests "
158 "to pass.</note>" << std::endl;
159 #endif
160
161 #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
162 test_spots(0.1F, "float");
163 #endif
164 test_spots(0.1, "double");
165 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
166 test_spots(0.1L, "long double");
167 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
168 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
169 test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
170 #endif
171 #endif
172 #else
173 std::cout << "<note>The long double tests have been disabled on this platform "
174 "either because the long double overloads of the usual math functions are "
175 "not available at all, or because they are too inaccurate for these tests "
176 "to pass.</note>" << std::endl;
177 #endif
178 }
179
180
181