]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright John Maddock 2006. |
2 | // Copyright Paul A. Bristow 2007, 2009 | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifdef _MSC_VER | |
8 | # pragma warning (disable : 4756) // overflow in constant arithmetic | |
9 | #endif | |
10 | ||
11 | #include <boost/math/concepts/real_concept.hpp> | |
12 | #define BOOST_TEST_MAIN | |
13 | #include <boost/test/unit_test.hpp> | |
14 | #include <boost/test/floating_point_comparison.hpp> | |
15 | #include <boost/math/special_functions/math_fwd.hpp> | |
16 | #include <boost/math/constants/constants.hpp> | |
17 | #include <boost/array.hpp> | |
18 | #include "functor.hpp" | |
19 | ||
20 | #include "handle_test_result.hpp" | |
21 | #include "table_type.hpp" | |
22 | ||
23 | #ifndef SC_ | |
24 | #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L)) | |
25 | #endif | |
26 | ||
27 | template <class Real, class T> | |
28 | void do_test_legendre_p(const T& data, const char* type_name, const char* test_name) | |
29 | { | |
30 | typedef Real value_type; | |
31 | ||
32 | typedef value_type (*pg)(int, value_type); | |
33 | pg funcp; | |
34 | ||
35 | #if !(defined(ERROR_REPORTING_MODE) && !defined(LEGENDRE_P_FUNCTION_TO_TEST)) | |
36 | #ifdef LEGENDRE_P_FUNCTION_TO_TEST | |
37 | funcp = LEGENDRE_P_FUNCTION_TO_TEST; | |
38 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
39 | funcp = boost::math::legendre_p<value_type>; | |
40 | #else | |
41 | funcp = boost::math::legendre_p; | |
42 | #endif | |
43 | ||
44 | boost::math::tools::test_result<value_type> result; | |
45 | ||
46 | std::cout << "Testing " << test_name << " with type " << type_name | |
47 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
48 | ||
49 | // | |
50 | // test legendre_p against data: | |
51 | // | |
52 | result = boost::math::tools::test_hetero<Real>( | |
53 | data, | |
54 | bind_func_int1<Real>(funcp, 0, 1), | |
55 | extract_result<Real>(2)); | |
56 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "legendre_p", test_name); | |
57 | #endif | |
58 | ||
59 | typedef value_type (*pg2)(unsigned, value_type); | |
60 | #if !(defined(ERROR_REPORTING_MODE) && !defined(LEGENDRE_Q_FUNCTION_TO_TEST)) | |
61 | #ifdef LEGENDRE_Q_FUNCTION_TO_TEST | |
62 | pg2 funcp2 = LEGENDRE_Q_FUNCTION_TO_TEST; | |
63 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
64 | pg2 funcp2 = boost::math::legendre_q<value_type>; | |
65 | #else | |
66 | pg2 funcp2 = boost::math::legendre_q; | |
67 | #endif | |
68 | ||
69 | // | |
70 | // test legendre_q against data: | |
71 | // | |
72 | result = boost::math::tools::test_hetero<Real>( | |
73 | data, | |
74 | bind_func_int1<Real>(funcp2, 0, 1), | |
75 | extract_result<Real>(3)); | |
76 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "legendre_q", test_name); | |
77 | ||
78 | std::cout << std::endl; | |
79 | #endif | |
80 | } | |
81 | ||
82 | template <class Real, class T> | |
83 | void do_test_assoc_legendre_p(const T& data, const char* type_name, const char* test_name) | |
84 | { | |
85 | #if !(defined(ERROR_REPORTING_MODE) && !defined(LEGENDRE_PA_FUNCTION_TO_TEST)) | |
86 | typedef Real value_type; | |
87 | ||
88 | typedef value_type (*pg)(int, int, value_type); | |
89 | #ifdef LEGENDRE_PA_FUNCTION_TO_TEST | |
90 | pg funcp = LEGENDRE_PA_FUNCTION_TO_TEST; | |
91 | #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) | |
92 | pg funcp = boost::math::legendre_p<value_type>; | |
93 | #else | |
94 | pg funcp = boost::math::legendre_p; | |
95 | #endif | |
96 | ||
97 | boost::math::tools::test_result<value_type> result; | |
98 | ||
99 | std::cout << "Testing " << test_name << " with type " << type_name | |
100 | << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; | |
101 | ||
102 | // | |
103 | // test legendre_p against data: | |
104 | // | |
105 | result = boost::math::tools::test_hetero<Real>( | |
106 | data, | |
107 | bind_func_int2<Real>(funcp, 0, 1, 2), | |
108 | extract_result<Real>(3)); | |
109 | handle_test_result(result, data[result.worst()], result.worst(), type_name, "legendre_p (associated)", test_name); | |
110 | std::cout << std::endl; | |
111 | #endif | |
112 | } | |
113 | ||
114 | template <class T> | |
115 | void test_legendre_p(T, const char* name) | |
116 | { | |
117 | // | |
118 | // The actual test data is rather verbose, so it's in a separate file | |
119 | // | |
120 | // The contents are as follows, each row of data contains | |
121 | // three items, input value a, input value b and erf(a, b): | |
122 | // | |
123 | # include "legendre_p.ipp" | |
124 | ||
125 | do_test_legendre_p<T>(legendre_p, name, "Legendre Polynomials: Small Values"); | |
126 | ||
127 | # include "legendre_p_large.ipp" | |
128 | ||
129 | do_test_legendre_p<T>(legendre_p_large, name, "Legendre Polynomials: Large Values"); | |
130 | ||
131 | # include "assoc_legendre_p.ipp" | |
132 | ||
133 | do_test_assoc_legendre_p<T>(assoc_legendre_p, name, "Associated Legendre Polynomials: Small Values"); | |
134 | ||
135 | } | |
136 | ||
137 | template <class T> | |
138 | void test_spots(T, const char* t) | |
139 | { | |
140 | std::cout << "Testing basic sanity checks for type " << t << std::endl; | |
141 | // | |
142 | // basic sanity checks, tolerance is 100 epsilon: | |
143 | // | |
144 | T tolerance = boost::math::tools::epsilon<T>() * 100; | |
145 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance); | |
146 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-1, static_cast<T>(0.5L)), static_cast<T>(1L), tolerance); | |
147 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, static_cast<T>(0.5L)), static_cast<T>(-0.2890625000000000000000000000000000000000L), tolerance); | |
148 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, static_cast<T>(0.5L)), static_cast<T>(-0.4375000000000000000000000000000000000000L), tolerance); | |
149 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, static_cast<T>(0.5L)), static_cast<T>(0.2231445312500000000000000000000000000000L), tolerance); | |
150 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, static_cast<T>(0.5L)), static_cast<T>(0.3232421875000000000000000000000000000000L), tolerance); | |
151 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, static_cast<T>(0.5L)), static_cast<T>(-0.09542943523261546936538467572384923220258L), tolerance); | |
152 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, static_cast<T>(0.5L)), static_cast<T>(-0.1316993126940266257030910566308990611306L), tolerance); | |
153 | ||
154 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance); | |
155 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(0.5L)), static_cast<T>(5.625000000000000000000000000000000000000L), tolerance); | |
156 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance); | |
157 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance); | |
158 | if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent) | |
159 | { | |
160 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance); | |
161 | } | |
162 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(0.5L)), static_cast<T>(4.966634149702370788037088925152355134665e30L), tolerance); | |
163 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(-0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance); | |
164 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(-0.5L)), static_cast<T>(-5.625000000000000000000000000000000000000L), tolerance); | |
165 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(-0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance); | |
166 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(-0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance); | |
167 | if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent) | |
168 | { | |
169 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(-0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance); | |
170 | } | |
171 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(-0.5L)), static_cast<T>(-4.966634149702370788037088925152355134665e30L), tolerance); | |
172 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, -2, static_cast<T>(0.5L)), static_cast<T>(0.01171875000000000000000000000000000000000L), tolerance); | |
173 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, -2, static_cast<T>(0.5L)), static_cast<T>(0.04687500000000000000000000000000000000000L), tolerance); | |
174 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, -5, static_cast<T>(0.5L)), static_cast<T>(0.00002378609812640364935569308025139290054701L), tolerance); | |
175 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, -4, static_cast<T>(0.5L)), static_cast<T>(0.0002563476562500000000000000000000000000000L), tolerance); | |
176 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, -30, static_cast<T>(0.5L)), static_cast<T>(-2.379819988646847616996471299410611801239e-48L), tolerance); | |
177 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, -20, static_cast<T>(0.5L)), static_cast<T>(4.356454600748202401657099008867502679122e-33L), tolerance); | |
178 | ||
179 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(1, static_cast<T>(0.5L)), static_cast<T>(-0.7253469278329725771511886907693685738381L), tolerance); | |
180 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(4, static_cast<T>(0.5L)), static_cast<T>(0.4401745259867706044988642951843745400835L), tolerance); | |
181 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(7, static_cast<T>(0.5L)), static_cast<T>(-0.3439152932669753451878700644212067616780L), tolerance); | |
182 | BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(40, static_cast<T>(0.5L)), static_cast<T>(0.1493671665503550095010454949479907886011L), tolerance); | |
183 | } | |
184 |