• 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/type_traits/is_floating_point.hpp>
13 #include <boost/array.hpp>
14 #include "functor.hpp"
15 
16 #include "handle_test_result.hpp"
17 #include "table_type.hpp"
18 
19 #ifndef SC_
20 #  define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
21 #endif
22 
23 template <class T>
cyl_bessel_i_prime_int_wrapper(T v,T x)24 T cyl_bessel_i_prime_int_wrapper(T v, T x)
25 {
26 #ifdef BESSEL_IPN_FUNCTION_TO_TEST
27    return static_cast<T>(
28       BESSEL_IPN_FUNCTION_TO_TEST(
29       boost::math::itrunc(v), x));
30 #else
31    return static_cast<T>(
32       boost::math::cyl_bessel_i_prime(
33       boost::math::itrunc(v), x));
34 #endif
35 }
36 
37 template <class Real, class T>
do_test_cyl_bessel_i_prime(const T & data,const char * type_name,const char * test_name)38 void do_test_cyl_bessel_i_prime(const T& data, const char* type_name, const char* test_name)
39 {
40 #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_IP_FUNCTION_TO_TEST))
41    typedef Real                   value_type;
42 
43    typedef value_type (*pg)(value_type, value_type);
44 #ifdef BESSEL_IP_FUNCTION_TO_TEST
45    pg funcp = BESSEL_IP_FUNCTION_TO_TEST;
46 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
47    pg funcp = boost::math::cyl_bessel_i_prime<value_type, value_type>;
48 #else
49    pg funcp = boost::math::cyl_bessel_i_prime;
50 #endif
51 
52    boost::math::tools::test_result<value_type> result;
53 
54    std::cout << "Testing " << test_name << " with type " << type_name
55       << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
56 
57    //
58    // test cyl_bessel_i_prime against data:
59    //
60    result = boost::math::tools::test_hetero<Real>(
61       data,
62       bind_func<Real>(funcp, 0, 1),
63       extract_result<Real>(2));
64    handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_bessel_i_prime", test_name);
65    std::cout << std::endl;
66 #endif
67 }
68 
69 template <class Real, class T>
do_test_cyl_bessel_i_prime_int(const T & data,const char * type_name,const char * test_name)70 void do_test_cyl_bessel_i_prime_int(const T& data, const char* type_name, const char* test_name)
71 {
72 #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_IPN_FUNCTION_TO_TEST))
73    typedef Real                   value_type;
74 
75    typedef value_type (*pg)(value_type, value_type);
76 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
77    pg funcp = cyl_bessel_i_prime_int_wrapper<value_type>;
78 #else
79    pg funcp = cyl_bessel_i_prime_int_wrapper;
80 #endif
81 
82    boost::math::tools::test_result<value_type> result;
83 
84    std::cout << "Testing " << test_name << " with type " << type_name
85       << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
86 
87    //
88    // test cyl_bessel_i_prime against data:
89    //
90    result = boost::math::tools::test_hetero<Real>(
91       data,
92       bind_func<Real>(funcp, 0, 1),
93       extract_result<Real>(2));
94    handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_bessel_i_prime (integer orders)", test_name);
95    std::cout << std::endl;
96 #endif
97 }
98 
99 template <class T>
test_bessel(T,const char * name)100 void test_bessel(T, const char* name)
101 {
102     BOOST_MATH_STD_USING
103     // function values calculated on wolframalpha.com
104     static const boost::array<boost::array<T, 3>, 10> i0_prime_data = {{
105         {{ SC_(0.0), SC_(0.0), SC_(0.0) }},
106         {{ SC_(0.0), SC_(1.0), SC_(0.565159103992485027207696027609863307328899621621) }},
107         {{ SC_(0.0), SC_(-2.0), SC_(-1.590636854637329063382254424999666247954478159496) }},
108         {{ SC_(0.0), SC_(4.0), SC_(9.75946515370444990947519256731268090005597033325) }},
109         {{ SC_(0.0), SC_(-7.0), SC_(-156.039092869955453462390580660711155630031052042) }},
110         {{ SC_(0.0), T(1) / 1024, SC_(0.000488281308207663226432087816784315537514225208473395) }},
111         {{ SC_(0.0), T(SC_(1.0)) / (1024*1024), SC_(4.76837158203179210108624277276025646653133998635957e-7) }},
112         {{ SC_(0.0), SC_(-1.0), SC_(-0.565159103992485027207696027609863307328899621621) }},
113         {{ SC_(0.0), SC_(100.0), SC_(1.068369390338162481206145763224295265446122844056e42) }},
114         {{ SC_(0.0), SC_(200.0), SC_(2.034581549332062703427427977139069503896611616811e85) }},
115     }};
116     static const boost::array<boost::array<T, 3>, 10> i1_prime_data = {{
117         {{ SC_(1.0), SC_(0.0), SC_(0.5) }},
118         {{ SC_(1.0), SC_(1.0), SC_(0.700906773759523308390548597604854230278770689734) }},
119         {{ SC_(1.0), SC_(-2.0), SC_(1.484266875017402735746077228311700229308602023038) }},
120         {{ SC_(1.0), SC_(4.0), SC_(8.86205566371021801898747204138893227239862401112) }},
121         {{ SC_(1.0), SC_(-8.0), SC_(377.579973623984772900011405549855040764360549303) }},
122         {{ SC_(1.0), T(SC_(1.0))/1024, SC_(0.500000178813946168551133736709856567600996119560422) }},
123         {{ SC_(1.0), T(SC_(1.0))/(1024*1024), SC_(0.500000000000170530256582434815189962442052310320626) }},
124         {{ SC_(1.0), SC_(-10.0), SC_(2548.6177980961290060357079567493748381638767230173) }},
125         {{ SC_(1.0), SC_(100.0), SC_(1.063068013227692198707659399971251708633941964885e42) }},
126         {{ SC_(1.0), SC_(200.0), SC_(2.029514265663064306024535986893764274813192678064e85) }},
127     }};
128     static const boost::array<boost::array<T, 3>, 11> in_prime_data = {{
129         {{ SC_(-2.0), SC_(0.0), SC_(0.0) }},
130         {{ SC_(2.0), T(SC_(1.0))/(1024*1024), SC_(2.38418579101598640072416185021877537269848820467704e-7) }},
131         {{ SC_(5.0), SC_(10.0), SC_(837.8963945578616177877239800250165373153505679130) }},
132         {{ SC_(-5.0), SC_(100.0), SC_(9.434574089052212641696648538570565739509851953166e41) }},
133         {{ SC_(-5.0), SC_(-1.0), SC_(0.001379804441262006949232714689824343061461150959112) }},
134         {{ SC_(10.0), SC_(20.0), SC_(3.887291476282816593964936516887942731146400030466e6) }},
135         {{ SC_(10.0), SC_(-5.0), SC_(-0.0101556299784624552653083645193223022003797137770) }},
136         {{ SC_(1e+02), SC_(9.0), SC_(3.0600487816519872979909028718737622834061708443e-92) }},
137         {{ SC_(1e+02), SC_(80.0), SC_(7.43545006374466980237328068214707549314834217923e8) }},
138         {{ SC_(-100.0), SC_(-200.0), SC_(-4.8578174816088978115191937982677942557681326349558e74) }},
139         {{ SC_(10.0), SC_(1e-100), SC_(2.6911444554673721340388007054673721340e-909) }},
140     }};
141     static const boost::array<boost::array<T, 3>, 10> iv_prime_data = {{
142         {{ SC_(2.25), T(1)/(1024*1024), SC_(5.5296993766970839641084373853875345330202883e-9) }},
143         {{ SC_(5.5), SC_(3.125), SC_(0.11607917746126037030394881599790144677553715606) }},
144         {{ T(-5) + T(1)/1024, SC_(2.125), SC_(0.0001131925559871199041270456478317398625046249903864372470342210384462922281) }},
145         {{ SC_(-5.5), SC_(10.0), SC_(659.1902595786901927596924259811320437384361101) }},
146         {{ SC_(-5.5), SC_(100.0), SC_(9.191476042191556775282339209385028823905941708e41) }},
147         {{ T(-10486074)/(1024*1024), T(1)/1024, SC_(-1.44873720736417608945635957884937466861026978539e39) }},
148         {{ T(-10486074)/(1024*1024), SC_(50.0), SC_(1.082410021443599516897183930739816215073642812109e20) }},
149         {{ T(144794)/1024, SC_(100.0), SC_(3575.11008553328328036816705258135747714241715202) }},
150         {{ T(144794)/1024, SC_(200.0), SC_(2.7358895637426974377937620224627094172800852276956e64) }},
151         {{ T(-144794)/1024, SC_(100.0), SC_(3575.11008700037933897402396449269857968451879323) }},
152     }};
153     static const boost::array<boost::array<T, 3>, 5> iv_prime_large_data = {{
154         {{ SC_(-1.0), static_cast<T>(ldexp(0.5, -512)), SC_(0.5) }},
155         {{ SC_(1.0),  static_cast<T>(ldexp(0.5, -512)), SC_(0.5) }},
156         {{ SC_(1.125),  static_cast<T>(ldexp(0.5, -512)), SC_(2.42025162605150606399395900489934587657244145536315936432966315563638e-20) }},
157         {{ SC_(0.5), static_cast<T>(ldexp(0.5, -683)), SC_(3.5741154998461284276309443770923823816821202344841143399486401387635e102) }},
158 #if LDBL_MAX_10_EXP > 326
159         {{ SC_(-1.125), static_cast<T>(ldexp(0.5, -512)), SC_(4.0715272050947359203430409041001937149343363573066460226173390878707e327) }},
160 #else
161         { { SC_(-1.125), static_cast<T>(ldexp(0.5, -512)), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>() } },
162 #endif
163     }};
164 
165     do_test_cyl_bessel_i_prime<T>(i0_prime_data, name, "Bessel I'0: Mathworld Data");
166     do_test_cyl_bessel_i_prime<T>(i1_prime_data, name, "Bessel I'1: Mathworld Data");
167     do_test_cyl_bessel_i_prime<T>(in_prime_data, name, "Bessel I'n: Mathworld Data");
168 
169     do_test_cyl_bessel_i_prime_int<T>(i0_prime_data, name, "Bessel I'0: Mathworld Data (Integer Version)");
170     do_test_cyl_bessel_i_prime_int<T>(i1_prime_data, name, "Bessel I'1: Mathworld Data (Integer Version)");
171     do_test_cyl_bessel_i_prime_int<T>(in_prime_data, name, "Bessel I'n: Mathworld Data (Integer Version)");
172 
173     do_test_cyl_bessel_i_prime<T>(iv_prime_data, name, "Bessel I'v: Mathworld Data");
174 
175 #include "bessel_i_prime_int_data.ipp"
176     do_test_cyl_bessel_i_prime<T>(bessel_i_prime_int_data, name, "Bessel I'n: Random Data");
177 #include "bessel_i_prime_data.ipp"
178     do_test_cyl_bessel_i_prime<T>(bessel_i_prime_data, name, "Bessel I'v: Random Data");
179 
180     if(0 != static_cast<T>(ldexp(static_cast<T>(0.5), -700)))
181       do_test_cyl_bessel_i_prime<T>(iv_prime_large_data, name, "Bessel I'v: Mathworld Data (large values)");
182 }
183 
184