• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2013 Anton Bikineev
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 #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
7 #include <boost/math/concepts/real_concept.hpp>
8 #define BOOST_TEST_MAIN
9 #include <boost/test/unit_test.hpp>
10 #include <boost/test/tools/floating_point_comparison.hpp>
11 #include <boost/math/special_functions/math_fwd.hpp>
12 #include <boost/math/constants/constants.hpp>
13 #include <boost/type_traits/is_floating_point.hpp>
14 #include <boost/array.hpp>
15 #include "functor.hpp"
16 #include <boost/math/concepts/real_concept.hpp>
17 
18 #include "handle_test_result.hpp"
19 #include "table_type.hpp"
20 
21 #ifndef SC_
22 #  define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
23 #endif
24 
25 template <class Real, class T>
do_test_cyl_neumann_y_prime(const T & data,const char * type_name,const char * test_name)26 void do_test_cyl_neumann_y_prime(const T& data, const char* type_name, const char* test_name)
27 {
28 #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YP_FUNCTION_TO_TEST))
29    typedef Real                   value_type;
30 
31    typedef value_type (*pg)(value_type, value_type);
32 #ifdef BESSEL_YP_FUNCTION_TO_TEST
33    pg funcp = BESSEL_YP_FUNCTION_TO_TEST;
34 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
35    pg funcp = boost::math::cyl_neumann_prime<value_type, value_type>;
36 #else
37    pg funcp = boost::math::cyl_neumann_prime;
38 #endif
39 
40    boost::math::tools::test_result<value_type> result;
41 
42    std::cout << "Testing " << test_name << " with type " << type_name
43       << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
44 
45 #include <boost/math/concepts/real_concept.hpp>
46    //
47    // test cyl_neumann against data:
48    //
49    result = boost::math::tools::test_hetero<Real>(
50       data,
51       bind_func<Real>(funcp, 0, 1),
52       extract_result<Real>(2));
53    handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann_prime", test_name);
54    std::cout << std::endl;
55 #endif
56 }
57 
58 template <class T>
cyl_neumann_prime_int_wrapper(T v,T x)59 T cyl_neumann_prime_int_wrapper(T v, T x)
60 {
61 #ifdef BESSEL_YNP_FUNCTION_TO_TEST
62    return static_cast<T>(BESSEL_YNP_FUNCTION_TO_TEST(boost::math::itrunc(v), x));
63 #else
64    return static_cast<T>(boost::math::cyl_neumann_prime(boost::math::itrunc(v), x));
65 #endif
66 }
67 
68 template <class Real, class T>
do_test_cyl_neumann_y_prime_int(const T & data,const char * type_name,const char * test_name)69 void do_test_cyl_neumann_y_prime_int(const T& data, const char* type_name, const char* test_name)
70 {
71 #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YNP_FUNCTION_TO_TEST))
72    typedef Real                   value_type;
73 
74    typedef value_type (*pg)(value_type, value_type);
75 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
76    pg funcp = cyl_neumann_prime_int_wrapper<value_type>;
77 #else
78    pg funcp = cyl_neumann_prime_int_wrapper;
79 #endif
80 
81    boost::math::tools::test_result<value_type> result;
82 
83    std::cout << "Testing " << test_name << " with type " << type_name
84       << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
85 
86    //
87    // test cyl_neumann derivative against data:
88    //
89    result = boost::math::tools::test_hetero<Real>(
90       data,
91       bind_func<Real>(funcp, 0, 1),
92       extract_result<Real>(2));
93    handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann_prime (integer orders)", test_name);
94    std::cout << std::endl;
95 #endif
96 }
97 
98 template <class Real, class T>
do_test_sph_neumann_y_prime(const T & data,const char * type_name,const char * test_name)99 void do_test_sph_neumann_y_prime(const T& data, const char* type_name, const char* test_name)
100 {
101 #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YSP_FUNCTION_TO_TEST))
102    typedef Real                   value_type;
103 
104    typedef value_type (*pg)(unsigned, value_type);
105 #ifdef BESSEL_YPS_FUNCTION_TO_TEST
106    pg funcp = BESSEL_YPS_FUNCTION_TO_TEST;
107 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
108    pg funcp = boost::math::sph_neumann_prime<value_type>;
109 #else
110    pg funcp = boost::math::sph_neumann_prime;
111 #endif
112 
113    boost::math::tools::test_result<value_type> result;
114 
115    std::cout << "Testing " << test_name << " with type " << type_name
116       << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
117 
118    //
119    // test sph_neumann against data:
120    //
121    result = boost::math::tools::test_hetero<Real>(
122       data,
123       bind_func_int1<Real>(funcp, 0, 1),
124       extract_result<Real>(2));
125    handle_test_result(result, data[result.worst()], result.worst(), type_name, "sph_neumann_prime", test_name);
126    std::cout << std::endl;
127 #endif
128 }
129 
130 template <class T>
test_bessel_prime(T,const char * name)131 void test_bessel_prime(T, const char* name)
132 {
133    //
134    // The actual test data is rather verbose, so it's in a separate file
135    //
136    // The contents are as follows, each row of data contains
137    // three items, input value a, input value b and Y'(a, b):
138    //
139     // function values calculated on wolframalpha.com
140     static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y0_prime_data = {{
141         {{ SC_(0.0), SC_(1.0), SC_(0.7812128213002887165471500000479648205499063907164) }},
142         {{ SC_(0.0), SC_(2.0), SC_(0.1070324315409375468883707722774766366874808982351) }},
143         {{ SC_(0.0), SC_(4.0), SC_(-0.397925710557100005253979972450791852271189181623) }},
144         {{ SC_(0.0), SC_(8.0), SC_(0.15806046173124749425555526618748355032734404952671) }},
145         {{ SC_(0.0), SC_(1e-05), SC_(63661.97727536548515747484843924772510915025447869) }},
146         {{ SC_(0.0), SC_(1e-10), SC_(6.366197723675813431507891842844626117090808311905e9) }},
147         {{ SC_(0.0), SC_(1e-20), SC_(6.366197723675813430755350534900574482790569176554e19) }},
148         {{ SC_(0.0), SC_(1e+03), SC_(0.0247843312923517789148623560971412909386318548649) }},
149         {{ SC_(0.0), SC_(1e+05), SC_(-0.00171921035008825630099494523539897102954509505) }}
150     }};
151     static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y1_prime_data = {{
152         {{ SC_(1.0), SC_(1.0), SC_(0.8694697855159656745300767660714799833777239138071) }},
153         {{ SC_(1.0), SC_(2.0), SC_(0.5638918884202138930407919788658961916118796762034) }},
154         {{ SC_(1.0), SC_(4.0), SC_(-0.116422166964339993217130127559851181308289885304) }},
155         {{ SC_(1.0), SC_(8.0), SC_(0.24327904710397215730926780877205580306573293697226) }},
156         {{ SC_(1.0), SC_(1e-10), SC_(6.366197723675813430034640215574901912821641347643e19) }},
157         {{ SC_(1.0), SC_(1e-20), SC_(6.366197723675813430755350534900574481363849370436e39) }},
158         {{ SC_(1.0), SC_(1e+01), SC_(0.030769624862904003032131529943867767819086460209939) }},
159         {{ SC_(1.0), SC_(1e+03), SC_(0.004740702308915165178688123821762396300797636752) }},
160         {{ SC_(1.0), SC_(1e+05), SC_(0.00184674896676156322177773107486310726913857253) }}
161     }};
162     static const boost::array<boost::array<typename table_type<T>::type, 3>, 10> yn_prime_data = {{
163         {{ SC_(2.0), SC_(1e-20), SC_(2.546479089470325372302140213960229792551354331847e60) }},
164         {{ SC_(5.0), SC_(10.0), SC_(-0.21265103571277493482623417349611996600573875672875) }},
165         {{ SC_(-5.0), SC_(1e+06), SC_(0.00072596421871030053058120610033601018452750251) }},
166         {{ SC_(10.0), SC_(10.0), SC_(0.16051488637815838440809874678012991818716553338993) }},
167         {{ SC_(10.0), SC_(1e-10), SC_(1.1828049049433493390095436658120487349235941485975e119) }},
168         {{ SC_(-10.0), SC_(1e+06), SC_(-0.00033107967471992097725245404942310474516318425) }},
169         {{ SC_(1e+02), SC_(5.0), SC_(1.0156878983956300357005118672219842696133568692723e117) }},
170         {{ SC_(1e+03), SC_(1e+05), SC_(0.00128310308817651270517132752369325022363869159) }},
171         {{ SC_(-1e+03), SC_(7e+02), SC_(1.9243675144213106227065036295645482241938721428442e77) }},
172         {{ SC_(-25.0), SC_(8.0), SC_(-1.0191840913424144032043561764980932223038174827996e9) }}
173     }};
174     static const boost::array<boost::array<T, 3>, 11> yv_prime_data = {{
175         {{ SC_(0.5), T(1) / (1024*1024), SC_(4.283610118295381639304989276580713877375759e8) }},
176         {{ SC_(5.5), SC_(3.125), SC_(3.46903134947470280592767672475643312107258) }},
177         {{ SC_(-5.5), SC_(3.125), SC_(-0.04142495199637659623440832639970224440469) }},
178         {{ SC_(-5.5), SC_(1e+04), SC_(0.00245022241637437956702428797044365092097074) }},
179         {{ T(-10486074) / (1024*1024), T(1)/1024, SC_(1.539961618935582531021699399508514975292038639e42) }},
180         {{ T(-10486074) / (1024*1024), SC_(1e+02), SC_(-0.054782042073650048917092191171177791880141278121) }},
181         {{ SC_(141.75), SC_(1e+02), SC_(5.3859930471571245788582581390871501852536045509e9) }},
182         {{ SC_(141.75), SC_(2e+04), SC_(-0.0042010736481689878858599823347897260616269998902) }},
183         {{ SC_(-141.75), SC_(1e+02), SC_(3.8084722070683992315593455637944657331085673830e9) }},
184         {{ SC_(8.5), boost::math::constants::pi<T>() * 4, SC_(0.014516314554743677558496402742690038592727861) }},
185         {{ SC_(-8.5), boost::math::constants::pi<T>() * 4, SC_(-0.194590144622675911618596506265006877277073804) }},
186     }};
187     static const boost::array<boost::array<T, 3>, 7> yv_prime_large_data = {{
188 #if LDBL_MAX_10_EXP > 326
189         {{ SC_(0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(2.868703194735890254207338863894358862705699335892099e308) }},
190 #else
191         {{ SC_(0.5), static_cast<T>(std::ldexp(0.5, -400)), SC_(4.6822269214637968690651040333526494618220547616350e180) }},
192 #endif
193         {{ SC_(-0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(3.5741154998461284276309443770923823816821202344841e102) }},
194         {{ SC_(0.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(5.73416113922265864550047623401604244038331542638719289e15) }},
195         {{ SC_(1.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(5.164873193977108862252341626669725460073766e31) }},
196         {{ SC_(2.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(1.8608416793448936781963026443824482966468761e48) }},
197         {{ SC_(3.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(1.0056583072431781406772110820260315331263726e65) }},
198         {{ SC_(10.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(3.74455823365114672304576809031094538692683400e184) }},
199     }};
200 
201     do_test_cyl_neumann_y_prime<T>(y0_prime_data, name, "Y'0: Mathworld Data");
202     do_test_cyl_neumann_y_prime<T>(y1_prime_data, name, "Y'1: Mathworld Data");
203     do_test_cyl_neumann_y_prime<T>(yn_prime_data, name, "Y'n: Mathworld Data");
204     do_test_cyl_neumann_y_prime_int<T>(y0_prime_data, name, "Y'0: Mathworld Data (Integer Version)");
205     do_test_cyl_neumann_y_prime_int<T>(y1_prime_data, name, "Y'1: Mathworld Data (Integer Version)");
206     do_test_cyl_neumann_y_prime_int<T>(yn_prime_data, name, "Y'n: Mathworld Data (Integer Version)");
207     do_test_cyl_neumann_y_prime<T>(yv_prime_data, name, "Y'v: Mathworld Data");
208     if(yv_prime_large_data[0][1] != 0)
209       do_test_cyl_neumann_y_prime<T>(yv_prime_large_data, name, "Y'v: Mathworld Data (large values)");
210 
211 #include "bessel_y01_prime_data.ipp"
212     do_test_cyl_neumann_y_prime<T>(bessel_y01_prime_data, name, "Y'0 and Y'1: Random Data");
213 #include "bessel_yn_prime_data.ipp"
214     do_test_cyl_neumann_y_prime<T>(bessel_yn_prime_data, name, "Y'n: Random Data");
215 #include "bessel_yv_prime_data.ipp"
216     do_test_cyl_neumann_y_prime<T>(bessel_yv_prime_data, name, "Y'v: Random Data");
217 
218 #include "sph_neumann_prime_data.ipp"
219     do_test_sph_neumann_y_prime<T>(sph_neumann_prime_data, name, "y': Random Data");
220 }
221 
222