test_bessel_j.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. #include <pch_light.hpp>
  6. #include "test_bessel_j.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the bessel functions. There are two sets of tests, spot
  12. // tests which compare our results with selected values computed
  13. // using the online special function calculator at
  14. // functions.wolfram.com, while the bulk of 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. void expected_results()
  30. {
  31. //
  32. // Define the max and mean errors expected for
  33. // various compilers and platforms.
  34. //
  35. const char* largest_type;
  36. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  37. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  38. {
  39. largest_type = "(long\\s+)?double|real_concept";
  40. }
  41. else
  42. {
  43. largest_type = "long double|real_concept";
  44. }
  45. #else
  46. largest_type = "(long\\s+)?double";
  47. #endif
  48. //
  49. // HP-UX specific rates:
  50. //
  51. // Error rate for double precision are limited by the accuracy of
  52. // the approximations use, which bracket rather than preserve the root.
  53. //
  54. add_expected_result(
  55. ".*", // compiler
  56. ".*", // stdlib
  57. "HP-UX", // platform
  58. largest_type, // test type(s)
  59. ".*J0.*Tricky.*", // test data group
  60. ".*", 80000000000LL, 80000000000LL); // test function
  61. add_expected_result(
  62. ".*", // compiler
  63. ".*", // stdlib
  64. "HP-UX", // platform
  65. largest_type, // test type(s)
  66. ".*J1.*Tricky.*", // test data group
  67. ".*", 3000000, 2000000); // test function
  68. add_expected_result(
  69. ".*", // compiler
  70. ".*", // stdlib
  71. "HP-UX", // platform
  72. "double", // test type(s)
  73. ".*Tricky.*", // test data group
  74. ".*", 100000, 100000); // test function
  75. add_expected_result(
  76. ".*", // compiler
  77. ".*", // stdlib
  78. "HP-UX", // platform
  79. largest_type, // test type(s)
  80. ".*J.*Tricky.*", // test data group
  81. ".*", 3000, 500); // test function
  82. //
  83. // HP Tru64:
  84. //
  85. add_expected_result(
  86. ".*Tru64.*", // compiler
  87. ".*", // stdlib
  88. ".*", // platform
  89. "double", // test type(s)
  90. ".*Tricky.*", // test data group
  91. ".*", 100000, 100000); // test function
  92. add_expected_result(
  93. ".*Tru64.*", // compiler
  94. ".*", // stdlib
  95. ".*", // platform
  96. largest_type, // test type(s)
  97. ".*Tricky large.*", // test data group
  98. ".*", 3000, 1000); // test function
  99. //
  100. // Solaris specific rates:
  101. //
  102. // Error rate for double precision are limited by the accuracy of
  103. // the approximations use, which bracket rather than preserve the root.
  104. //
  105. add_expected_result(
  106. ".*", // compiler
  107. ".*", // stdlib
  108. "Sun Solaris", // platform
  109. largest_type, // test type(s)
  110. "Bessel J: Random Data.*Tricky.*", // test data group
  111. ".*", 3000, 500); // test function
  112. add_expected_result(
  113. ".*", // compiler
  114. ".*", // stdlib
  115. "Sun Solaris", // platform
  116. "double", // test type(s)
  117. ".*Tricky.*", // test data group
  118. ".*", 200000, 100000); // test function
  119. add_expected_result(
  120. ".*", // compiler
  121. ".*", // stdlib
  122. "Sun Solaris", // platform
  123. largest_type, // test type(s)
  124. ".*J.*tricky.*", // test data group
  125. ".*", 400000000, 200000000); // test function
  126. //
  127. // Mac OS X:
  128. //
  129. add_expected_result(
  130. ".*", // compiler
  131. ".*", // stdlib
  132. "Mac OS", // platform
  133. largest_type, // test type(s)
  134. ".*J0.*Tricky.*", // test data group
  135. ".*", 400000000, 400000000); // test function
  136. add_expected_result(
  137. ".*", // compiler
  138. ".*", // stdlib
  139. "Mac OS", // platform
  140. largest_type, // test type(s)
  141. ".*J1.*Tricky.*", // test data group
  142. ".*", 3000000, 2000000); // test function
  143. add_expected_result(
  144. ".*", // compiler
  145. ".*", // stdlib
  146. "Mac OS", // platform
  147. largest_type, // test type(s)
  148. "Bessel JN.*", // test data group
  149. ".*", 40000, 20000); // test function
  150. add_expected_result(
  151. ".*", // compiler
  152. ".*", // stdlib
  153. "Mac OS", // platform
  154. largest_type, // test type(s)
  155. "Bessel J:.*", // test data group
  156. ".*", 50000, 20000); // test function
  157. //
  158. // Linux specific results:
  159. //
  160. // sin and cos appear to have only double precision for large
  161. // arguments on some linux distros:
  162. //
  163. add_expected_result(
  164. ".*", // compiler
  165. ".*", // stdlib
  166. "linux", // platform
  167. largest_type, // test type(s)
  168. ".*J:.*", // test data group
  169. ".*", 40000, 30000); // test function
  170. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  171. if((std::numeric_limits<double>::digits != std::numeric_limits<long double>::digits)
  172. && (std::numeric_limits<long double>::digits < 90))
  173. {
  174. // some errors spill over into type double as well:
  175. add_expected_result(
  176. ".*", // compiler
  177. ".*", // stdlib
  178. ".*", // platform
  179. "double", // test type(s)
  180. ".*J0.*Tricky.*", // test data group
  181. ".*", 400000, 400000); // test function
  182. add_expected_result(
  183. ".*", // compiler
  184. ".*", // stdlib
  185. ".*", // platform
  186. "double", // test type(s)
  187. ".*J1.*Tricky.*", // test data group
  188. ".*", 5000, 5000); // test function
  189. add_expected_result(
  190. ".*", // compiler
  191. ".*", // stdlib
  192. ".*", // platform
  193. "double", // test type(s)
  194. ".*(JN|j).*|.*Tricky.*", // test data group
  195. ".*", 50, 50); // test function
  196. add_expected_result(
  197. ".*", // compiler
  198. ".*", // stdlib
  199. ".*", // platform
  200. "double", // test type(s)
  201. ".*", // test data group
  202. ".*", 30, 30); // test function
  203. //
  204. // and we have a few cases with higher limits as well:
  205. //
  206. add_expected_result(
  207. ".*", // compiler
  208. ".*", // stdlib
  209. ".*", // platform
  210. largest_type, // test type(s)
  211. ".*J0.*Tricky.*", // test data group
  212. ".*", 400000000, 400000000); // test function
  213. add_expected_result(
  214. ".*", // compiler
  215. ".*", // stdlib
  216. ".*", // platform
  217. largest_type, // test type(s)
  218. ".*J1.*Tricky.*", // test data group
  219. ".*", 5000000, 5000000); // test function
  220. add_expected_result(
  221. ".*", // compiler
  222. ".*", // stdlib
  223. ".*", // platform
  224. largest_type, // test type(s)
  225. ".*(JN|j).*|.*Tricky.*", // test data group
  226. ".*", 33000, 20000); // test function
  227. }
  228. #endif
  229. add_expected_result(
  230. ".*", // compiler
  231. ".*", // stdlib
  232. ".*", // platform
  233. largest_type, // test type(s)
  234. ".*J0.*Tricky.*", // test data group
  235. ".*", 400000000, 400000000); // test function
  236. add_expected_result(
  237. ".*", // compiler
  238. ".*", // stdlib
  239. ".*", // platform
  240. largest_type, // test type(s)
  241. ".*J1.*Tricky.*", // test data group
  242. ".*", 5000000, 5000000); // test function
  243. add_expected_result(
  244. ".*", // compiler
  245. ".*", // stdlib
  246. ".*", // platform
  247. largest_type, // test type(s)
  248. "Bessel j:.*|Bessel JN: Mathworld.*|.*Tricky.*", // test data group
  249. ".*", 1500, 700); // test function
  250. add_expected_result(
  251. ".*", // compiler
  252. ".*", // stdlib
  253. ".*", // platform
  254. largest_type, // test type(s)
  255. ".*", // test data group
  256. ".*", 40, 20); // test function
  257. //
  258. // One set of float tests has inexact input values, so there is a slight error:
  259. //
  260. add_expected_result(
  261. ".*", // compiler
  262. ".*", // stdlib
  263. ".*", // platform
  264. "float", // test type(s)
  265. "Bessel J: Mathworld Data", // test data group
  266. ".*", 20, 20); // test function
  267. //
  268. // Finish off by printing out the compiler/stdlib/platform names,
  269. // we do this to make it easier to mark up expected error rates.
  270. //
  271. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  272. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  273. }
  274. BOOST_AUTO_TEST_CASE( test_main )
  275. {
  276. #ifdef TEST_GSL
  277. gsl_set_error_handler_off();
  278. #endif
  279. expected_results();
  280. BOOST_MATH_CONTROL_FP;
  281. test_bessel(0.1F, "float");
  282. test_bessel(0.1, "double");
  283. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  284. test_bessel(0.1L, "long double");
  285. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  286. test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
  287. #endif
  288. #else
  289. std::cout << "<note>The long double tests have been disabled on this platform "
  290. "either because the long double overloads of the usual math functions are "
  291. "not available at all, or because they are too inaccurate for these tests "
  292. "to pass.</note>" << std::endl;
  293. #endif
  294. }