test_bessel_k_prime.cpp 4.7 KB

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