test_bessel_k.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright John Maddock 2006, 2007
  2. // Copyright Paul A. Bristow 2007
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <pch_light.hpp>
  7. #ifdef _MSC_VER
  8. # pragma warning(disable : 4756) // overflow in constant arithmetic
  9. // Constants are too big for float case, but this doesn't matter for test.
  10. #endif
  11. #include "test_bessel_k.hpp"
  12. //
  13. // DESCRIPTION:
  14. // ~~~~~~~~~~~~
  15. //
  16. // This file tests the bessel K function. There are two sets of tests, spot
  17. // tests which compare our results with selected values computed
  18. // using the online special function calculator at
  19. // functions.wolfram.com, while the bulk of the accuracy tests
  20. // use values generated with NTL::RR at 1000-bit precision
  21. // and our generic versions of these functions.
  22. //
  23. // Note that when this file is first run on a new platform many of
  24. // these tests will fail: the default accuracy is 1 epsilon which
  25. // is too tight for most platforms. In this situation you will
  26. // need to cast a human eye over the error rates reported and make
  27. // a judgement as to whether they are acceptable. Either way please
  28. // report the results to the Boost mailing list. Acceptable rates of
  29. // error are marked up below as a series of regular expressions that
  30. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  31. // along with the maximum expected peek and RMS mean errors for that
  32. // test.
  33. //
  34. void expected_results()
  35. {
  36. //
  37. // Define the max and mean errors expected for
  38. // various compilers and platforms.
  39. //
  40. const char* largest_type;
  41. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  42. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  43. {
  44. largest_type = "(long\\s+)?double|real_concept";
  45. }
  46. else
  47. {
  48. largest_type = "long double|real_concept";
  49. }
  50. #else
  51. largest_type = "(long\\s+)?double|real_concept";
  52. #endif
  53. //
  54. // On MacOS X cyl_bessel_k has much higher error levels than
  55. // expected: given that the implementation is basically
  56. // just a continued fraction evaluation combined with
  57. // exponentiation, we conclude that exp and pow are less
  58. // accurate on this platform, especially when the result
  59. // is outside the range of a double.
  60. //
  61. add_expected_result(
  62. ".*", // compiler
  63. ".*", // stdlib
  64. "Mac OS", // platform
  65. largest_type, // test type(s)
  66. ".*", // test data group
  67. ".*", 4000, 1300); // test function
  68. add_expected_result(
  69. "GNU.*", // compiler
  70. ".*", // stdlib
  71. "Win32.*", // platform
  72. largest_type, // test type(s)
  73. ".*large.*", // test data group
  74. ".*", 250, 100); // test function
  75. add_expected_result(
  76. ".*", // compiler
  77. ".*", // stdlib
  78. ".*", // platform
  79. largest_type, // test type(s)
  80. ".*large.*", // test data group
  81. ".*", 100, 50); // test function
  82. add_expected_result(
  83. ".*", // compiler
  84. ".*", // stdlib
  85. ".*", // platform
  86. "real_concept", // test type(s)
  87. ".*", // test data group
  88. ".*", 90, 50); // test function
  89. add_expected_result(
  90. ".*", // compiler
  91. ".*", // stdlib
  92. ".*", // platform
  93. largest_type, // test type(s)
  94. ".*", // test data group
  95. ".*", 35, 15); // test function
  96. //
  97. // Finish off by printing out the compiler/stdlib/platform names,
  98. // we do this to make it easier to mark up expected error rates.
  99. //
  100. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  101. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  102. }
  103. BOOST_AUTO_TEST_CASE( test_main )
  104. {
  105. #ifdef TEST_GSL
  106. gsl_set_error_handler_off();
  107. #endif
  108. expected_results();
  109. BOOST_MATH_CONTROL_FP;
  110. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  111. test_bessel(0.1F, "float");
  112. #endif
  113. test_bessel(0.1, "double");
  114. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  115. test_bessel(0.1L, "long double");
  116. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  117. test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
  118. #endif
  119. #else
  120. std::cout << "<note>The long double tests have been disabled on this platform "
  121. "either because the long double overloads of the usual math functions are "
  122. "not available at all, or because they are too inaccurate for these tests "
  123. "to pass.</note>" << std::endl;
  124. #endif
  125. }