test_bessel_i.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_i.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the bessel I function. 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";
  40. }
  41. else
  42. {
  43. largest_type = "long double";
  44. }
  45. #else
  46. largest_type = "(long\\s+)?double";
  47. #endif
  48. //
  49. // Mac OS has higher error rates, why?
  50. //
  51. add_expected_result(
  52. ".*", // compiler
  53. ".*", // stdlib
  54. "Mac OS", // platform
  55. largest_type, // test type(s)
  56. ".*", // test data group
  57. ".*", 400, 200); // test function
  58. //
  59. // G++ on Linux, results vary a bit by processor type,
  60. // on Itanium results are *much* better than listed here,
  61. // but x86 appears to have much less accurate std::pow
  62. // that throws off the results for tgamma(long double)
  63. // which then impacts on the Bessel functions:
  64. //
  65. add_expected_result(
  66. ".*", // compiler
  67. ".*", // stdlib
  68. "linux", // platform
  69. largest_type, // test type(s)
  70. ".*Random.*", // test data group
  71. ".*", 400, 200); // test function
  72. add_expected_result(
  73. "GNU.*", // compiler
  74. ".*", // stdlib
  75. "Win32.*", // platform
  76. largest_type, // test type(s)
  77. ".*Random.*", // test data group
  78. ".*", 400, 200); // test function
  79. add_expected_result(
  80. "GNU.*", // compiler
  81. ".*", // stdlib
  82. "Win32.*", // platform
  83. largest_type, // test type(s)
  84. ".*", // test data group
  85. ".*", 30, 10); // test function
  86. add_expected_result(
  87. ".*", // compiler
  88. ".*", // stdlib
  89. ".*Solaris.*", // platform
  90. largest_type, // test type(s)
  91. ".*", // test data group
  92. ".*", 500, 200); // test function
  93. add_expected_result(
  94. ".*", // compiler
  95. ".*", // stdlib
  96. ".*", // platform
  97. largest_type, // test type(s)
  98. ".*", // test data group
  99. ".*", 20, 10); // test function
  100. //
  101. // Set error rates a little higher for real_concept -
  102. // now that we use a series approximation for small z
  103. // that relies on tgamma the error rates are a little
  104. // higher only when a Lanczos approximation is not available.
  105. // All other types are unaffected.
  106. //
  107. add_expected_result(
  108. ".*", // compiler
  109. ".*", // stdlib
  110. ".*", // platform
  111. "real_concept", // test type(s)
  112. ".*", // test data group
  113. ".*", 500, 200); // test function
  114. //
  115. // Finish off by printing out the compiler/stdlib/platform names,
  116. // we do this to make it easier to mark up expected error rates.
  117. //
  118. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  119. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  120. }
  121. BOOST_AUTO_TEST_CASE( test_main )
  122. {
  123. #ifdef TEST_GSL
  124. gsl_set_error_handler_off();
  125. #endif
  126. expected_results();
  127. BOOST_MATH_CONTROL_FP;
  128. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  129. test_bessel(0.1F, "float");
  130. #endif
  131. test_bessel(0.1, "double");
  132. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  133. test_bessel(0.1L, "long double");
  134. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  135. test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
  136. #endif
  137. #else
  138. std::cout << "<note>The long double tests have been disabled on this platform "
  139. "either because the long double overloads of the usual math functions are "
  140. "not available at all, or because they are too inaccurate for these tests "
  141. "to pass.</note>" << std::endl;
  142. #endif
  143. }