test_bessel_y.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // (C) Copyright John Maddock 2007.
  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. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  6. #include <boost/math/concepts/real_concept.hpp>
  7. #define BOOST_TEST_MAIN
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/tools/floating_point_comparison.hpp>
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/constants/constants.hpp>
  12. #include <boost/type_traits/is_floating_point.hpp>
  13. #include <boost/array.hpp>
  14. #include "functor.hpp"
  15. #include "handle_test_result.hpp"
  16. #include "table_type.hpp"
  17. #ifndef SC_
  18. # define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  19. #endif
  20. template <class Real, class T>
  21. void do_test_cyl_neumann_y(const T& data, const char* type_name, const char* test_name)
  22. {
  23. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_Y_FUNCTION_TO_TEST))
  24. typedef Real value_type;
  25. typedef value_type (*pg)(value_type, value_type);
  26. #ifdef BESSEL_Y_FUNCTION_TO_TEST
  27. pg funcp = BESSEL_Y_FUNCTION_TO_TEST;
  28. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  29. pg funcp = boost::math::cyl_neumann<value_type, value_type>;
  30. #else
  31. pg funcp = boost::math::cyl_neumann;
  32. #endif
  33. boost::math::tools::test_result<value_type> result;
  34. std::cout << "Testing " << test_name << " with type " << type_name
  35. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  36. //
  37. // test cyl_neumann against data:
  38. //
  39. result = boost::math::tools::test_hetero<Real>(
  40. data,
  41. bind_func<Real>(funcp, 0, 1),
  42. extract_result<Real>(2));
  43. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann", test_name);
  44. std::cout << std::endl;
  45. #endif
  46. }
  47. template <class T>
  48. T cyl_neumann_int_wrapper(T v, T x)
  49. {
  50. #ifdef BESSEL_YN_FUNCTION_TO_TEST
  51. return static_cast<T>(BESSEL_YN_FUNCTION_TO_TEST(boost::math::itrunc(v), x));
  52. #else
  53. return static_cast<T>(boost::math::cyl_neumann(boost::math::itrunc(v), x));
  54. #endif
  55. }
  56. template <class Real, class T>
  57. void do_test_cyl_neumann_y_int(const T& data, const char* type_name, const char* test_name)
  58. {
  59. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YN_FUNCTION_TO_TEST))
  60. typedef Real value_type;
  61. typedef value_type (*pg)(value_type, value_type);
  62. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  63. pg funcp = cyl_neumann_int_wrapper<value_type>;
  64. #else
  65. pg funcp = cyl_neumann_int_wrapper;
  66. #endif
  67. boost::math::tools::test_result<value_type> result;
  68. std::cout << "Testing " << test_name << " with type " << type_name
  69. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  70. //
  71. // test cyl_neumann against data:
  72. //
  73. result = boost::math::tools::test_hetero<Real>(
  74. data,
  75. bind_func<Real>(funcp, 0, 1),
  76. extract_result<Real>(2));
  77. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cyl_neumann (integer orders)", test_name);
  78. std::cout << std::endl;
  79. #endif
  80. }
  81. template <class Real, class T>
  82. void do_test_sph_neumann_y(const T& data, const char* type_name, const char* test_name)
  83. {
  84. #if !(defined(ERROR_REPORTING_MODE) && !defined(BESSEL_YS_FUNCTION_TO_TEST))
  85. typedef Real value_type;
  86. typedef value_type (*pg)(unsigned, value_type);
  87. #ifdef BESSEL_YS_FUNCTION_TO_TEST
  88. pg funcp = BESSEL_YS_FUNCTION_TO_TEST;
  89. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  90. pg funcp = boost::math::sph_neumann<value_type>;
  91. #else
  92. pg funcp = boost::math::sph_neumann;
  93. #endif
  94. boost::math::tools::test_result<value_type> result;
  95. std::cout << "Testing " << test_name << " with type " << type_name
  96. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  97. //
  98. // test sph_neumann against data:
  99. //
  100. result = boost::math::tools::test_hetero<Real>(
  101. data,
  102. bind_func_int1<Real>(funcp, 0, 1),
  103. extract_result<Real>(2));
  104. handle_test_result(result, data[result.worst()], result.worst(), type_name, "sph_neumann", test_name);
  105. std::cout << std::endl;
  106. #endif
  107. }
  108. template <class T>
  109. void test_bessel(T, const char* name)
  110. {
  111. //
  112. // The actual test data is rather verbose, so it's in a separate file
  113. //
  114. // The contents are as follows, each row of data contains
  115. // three items, input value a, input value b and erf(a, b):
  116. //
  117. // function values calculated on http://functions.wolfram.com/
  118. static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y0_data = {{
  119. {{ SC_(0.0), SC_(1.0), SC_(0.0882569642156769579829267660235151628278175230906755467110438) }},
  120. {{ SC_(0.0), SC_(2.0), SC_(0.510375672649745119596606592727157873268139227085846135571839) }},
  121. {{ SC_(0.0), SC_(4.0), SC_(-0.0169407393250649919036351344471532182404925898980149027169321) }},
  122. {{ SC_(0.0), SC_(8.0), SC_(0.223521489387566220527323400498620359274814930781423577578334) }},
  123. {{ SC_(0.0), SC_(1e-05), SC_(-7.40316028370197013259676050746759072070960287586102867247159) }},
  124. {{ SC_(0.0), SC_(1e-10), SC_(-14.7325162726972420426916696426209144888762342592762415255386) }},
  125. {{ SC_(0.0), SC_(1e-20), SC_(-29.3912282502857968601858410375186700783698345615477536431464) }},
  126. {{ SC_(0.0), SC_(1e+03), SC_(0.00471591797762281339977326146566525500985900489680197718528000) }},
  127. {{ SC_(0.0), SC_(1e+05), SC_(0.00184676615886506410434074102431546125884886798090392516843524) }}
  128. }};
  129. static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y1_data = {{
  130. {{ SC_(1.0), SC_(1.0), SC_(-0.781212821300288716547150000047964820549906390716444607843833) }},
  131. {{ SC_(1.0), SC_(2.0), SC_(-0.107032431540937546888370772277476636687480898235053860525795) }},
  132. {{ SC_(1.0), SC_(4.0), SC_(0.397925710557100005253979972450791852271189181622908340876586) }},
  133. {{ SC_(1.0), SC_(8.0), SC_(-0.158060461731247494255555266187483550327344049526705737651263) }},
  134. {{ SC_(1.0), SC_(1e-10), SC_(-6.36619772367581343150789184284462611709080831190542841855708e9) }},
  135. {{ SC_(1.0), SC_(1e-20), SC_(-6.36619772367581343075535053490057448139324059868649274367256e19) }},
  136. {{ SC_(1.0), SC_(1e+01), SC_(0.249015424206953883923283474663222803260416543069658461246944) }},
  137. {{ SC_(1.0), SC_(1e+03), SC_(-0.0247843312923517789148623560971412909386318548648705287583490) }},
  138. {{ SC_(1.0), SC_(1e+05), SC_(0.00171921035008825630099494523539897102954509504993494957572726) }}
  139. }};
  140. static const boost::array<boost::array<typename table_type<T>::type, 3>, 10> yn_data = {{
  141. {{ SC_(2.0), SC_(1e-20), SC_(-1.27323954473516268615107010698011489627570899691226996904849e40) }},
  142. {{ SC_(5.0), SC_(10.0), SC_(0.135403047689362303197029014762241709088405766746419538495983) }},
  143. {{ SC_(-5.0), SC_(1e+06), SC_(0.000331052088322609048503535570014688967096938338061796192422114) }},
  144. {{ SC_(10.0), SC_(10.0), SC_(-0.359814152183402722051986577343560609358382147846904467526222) }},
  145. {{ SC_(10.0), SC_(1e-10), SC_(-1.18280490494334933900960937719565669877576135140014365217993e108) }},
  146. {{ SC_(-10.0), SC_(1e+06), SC_(0.000725951969295187086245251366365393653610914686201194434805730) }},
  147. {{ SC_(1e+02), SC_(5.0), SC_(-5.08486391602022287993091563093082035595081274976837280338134e115) }},
  148. {{ SC_(1e+03), SC_(1e+05), SC_(0.00217254919137684037092834146629212647764581965821326561261181) }},
  149. {{ SC_(-1e+03), SC_(7e+02), SC_(-1.88753109980945889960843803284345261796244752396992106755091e77) }},
  150. {{ SC_(-25.0), SC_(8.0), SC_(3.45113613777297661997458045843868931827873456761831907587263e8) }}
  151. }};
  152. static const boost::array<boost::array<typename table_type<T>::type, 3>, 11> yv_data = {{
  153. //SC_(2.25), {{ SC_(1.0) / 1024, SC_(-1.01759203636941035147948317764932151601257765988969544340275e7) }},
  154. {{ SC_(0.5), SC_(9.5367431640625e-7) /* 1/(1024*1024)*/, SC_(-817.033790261762580469303126467917092806755460418223776544122) }},
  155. {{ SC_(5.5), SC_(3.125), SC_(-2.61489440328417468776474188539366752698192046890955453259866) }},
  156. {{ SC_(-5.5), SC_(3.125), SC_(-0.0274994493896489729948109971802244976377957234563871795364056) }},
  157. {{ SC_(-5.5), SC_(1e+04), SC_(-0.00759343502722670361395585198154817047185480147294665270646578) }},
  158. {{ SC_(-10.0002994537353515625) /* -10486074 / (1024*1024)*/, SC_(0.0009765625) /*1/1024*/, SC_(-1.50382374389531766117868938966858995093408410498915220070230e38) }},
  159. {{ SC_(-10.0002994537353515625) /* -10486074 / (1024*1024)*/, SC_(1e+02), SC_(0.0583041891319026009955779707640455341990844522293730214223545) }},
  160. {{ SC_(141.75), SC_(1e+02), SC_(-5.38829231428696507293191118661269920130838607482708483122068e9) }},
  161. {{ SC_(141.75), SC_(2e+04), SC_(-0.00376577888677186194728129112270988602876597726657372330194186) }},
  162. {{ SC_(-141.75), SC_(1e+02), SC_(-3.81009803444766877495905954105669819951653361036342457919021e9) }},
  163. {{ SC_(8.5), SC_(12.56637061435917295385057353311801153678867759750042328389) /*4Pi*/, SC_(0.257086543428224355151772807588810984369026142375675714560864) }},
  164. {{ SC_(-8.5), SC_(12.56637061435917295385057353311801153678867759750042328389) /*4Pi*/, SC_(0.0436807946352780974532519564114026730332781693877984686758680) }},
  165. }};
  166. static const boost::array<boost::array<typename table_type<T>::type, 3>, 7> yv_large_data = {{
  167. // Bug report https://svn.boost.org/trac/boost/ticket/5560:
  168. {{ SC_(0.5), SC_(1.24589936888719594193883785188809317368782599380894e-206) /*static_cast<T>(std::ldexp(0.5, -683))*/, SC_(-7.14823099969225685526188875418476476336424046896822867989728e102) }},
  169. {{ SC_(-0.5), SC_(1.24589936888719594193883785188809317368782599380894e-206) /*static_cast<T>(std::ldexp(0.5, -683))*/, SC_(8.90597649117647254543282704099383321071493400182381039079219e-104) }},
  170. {{ SC_(0.0), SC_(1.1102230246251565404236316680908203125e-16) /*static_cast<T>(std::ldexp(1.0, -53))*/, SC_(-23.4611779112897561252987257324561640034037313549011724328997) }},
  171. {{ SC_(1.0), SC_(1.1102230246251565404236316680908203125e-16) /*static_cast<T>(std::ldexp(1.0, -53))*/, SC_(-5.73416113922265864550047623401604244038331542638719289100990e15) }},
  172. {{ SC_(2.0), SC_(1.1102230246251565404236316680908203125e-16) /*static_cast<T>(std::ldexp(1.0, -53))*/, SC_(-1.03297463879542177245046832533417970379386617249046560049244e32) }},
  173. {{ SC_(3.0), SC_(1.1102230246251565404236316680908203125e-16) /*static_cast<T>(std::ldexp(1.0, -53))*/, SC_(-3.72168335868978735639260528876490232745489151562358712422544e48) }},
  174. {{ SC_(10.0), SC_(1.1102230246251565404236316680908203125e-16) /*static_cast<T>(std::ldexp(1.0, -53))*/, SC_(-4.15729476804920974669173904282420477878640623992500096231384e167) }},
  175. }};
  176. do_test_cyl_neumann_y<T>(y0_data, name, "Y0: Mathworld Data");
  177. do_test_cyl_neumann_y<T>(y1_data, name, "Y1: Mathworld Data");
  178. do_test_cyl_neumann_y<T>(yn_data, name, "Yn: Mathworld Data");
  179. do_test_cyl_neumann_y_int<T>(y0_data, name, "Y0: Mathworld Data (Integer Version)");
  180. do_test_cyl_neumann_y_int<T>(y1_data, name, "Y1: Mathworld Data (Integer Version)");
  181. do_test_cyl_neumann_y_int<T>(yn_data, name, "Yn: Mathworld Data (Integer Version)");
  182. do_test_cyl_neumann_y<T>(yv_data, name, "Yv: Mathworld Data");
  183. if(static_cast<T>(yv_large_data[0][1]) != 0)
  184. do_test_cyl_neumann_y<T>(yv_large_data, name, "Yv: Mathworld Data (large values)");
  185. #include "bessel_y01_data.ipp"
  186. do_test_cyl_neumann_y<T>(bessel_y01_data, name, "Y0 and Y1: Random Data");
  187. #include "bessel_yn_data.ipp"
  188. do_test_cyl_neumann_y<T>(bessel_yn_data, name, "Yn: Random Data");
  189. #include "bessel_yv_data.ipp"
  190. do_test_cyl_neumann_y<T>(bessel_yv_data, name, "Yv: Random Data");
  191. #include "sph_neumann_data.ipp"
  192. do_test_sph_neumann_y<T>(sph_neumann_data, name, "y: Random Data");
  193. }