test_expint.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_expint.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the expint functions. There are two sets of tests:
  12. // 1) Sanity checks: comparison to test values created with the
  13. // online calculator at functions.wolfram.com
  14. // 2) Accuracy tests use values generated with NTL::RR at
  15. // 1000-bit precision and our generic versions of these functions.
  16. //
  17. // Note that when this file is first run on a new platform many of
  18. // these tests will fail: the default accuracy is 1 epsilon which
  19. // is too tight for most platforms. In this situation you will
  20. // need to cast a human eye over the error rates reported and make
  21. // a judgement as to whether they are acceptable. Either way please
  22. // report the results to the Boost mailing list. Acceptable rates of
  23. // error are marked up below as a series of regular expressions that
  24. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  25. // along with the maximum expected peek and RMS mean errors for that
  26. // test.
  27. //
  28. void expected_results()
  29. {
  30. //
  31. // Define the max and mean errors expected for
  32. // various compilers and platforms.
  33. //
  34. //
  35. // On MacOS X erfc has much higher error levels than
  36. // expected: given that the implementation is basically
  37. // just a rational function evaluation combined with
  38. // exponentiation, we conclude that exp and pow are less
  39. // accurate on this platform, especially when the result
  40. // is outside the range of a double.
  41. //
  42. add_expected_result(
  43. ".*", // compiler
  44. ".*", // stdlib
  45. "Mac OS", // platform
  46. "float|double|long double", // test type(s)
  47. ".*E1.*", // test data group
  48. ".*", 30, 10); // test function
  49. add_expected_result(
  50. ".*", // compiler
  51. ".*", // stdlib
  52. "Mac OS", // platform
  53. "float|double|long double|real_concept", // test type(s)
  54. ".*Ei.*", // test data group
  55. ".*", 300, 200); // test function
  56. add_expected_result(
  57. ".*", // compiler
  58. ".*", // stdlib
  59. "Mac OS", // platform
  60. ".*", // test type(s)
  61. ".*", // test data group
  62. ".*", 40, 15); // test function
  63. add_expected_result(
  64. ".*", // compiler
  65. ".*", // stdlib
  66. ".*", // platform
  67. "float|double|long double", // test type(s)
  68. ".*E1.*", // test data group
  69. ".*", 2, 1); // test function
  70. add_expected_result(
  71. ".*", // compiler
  72. ".*", // stdlib
  73. ".*", // platform
  74. "float|double|long double", // test type(s)
  75. ".*Ei.*", // test data group
  76. ".*", 6, 3); // test function
  77. if(std::numeric_limits<long double>::digits > 100)
  78. {
  79. add_expected_result(
  80. ".*", // compiler
  81. ".*", // stdlib
  82. ".*", // platform
  83. "real_concept", // test type(s)
  84. ".*Ei.*", // test data group
  85. ".*", 150, 50); // test function
  86. }
  87. add_expected_result(
  88. ".*", // compiler
  89. ".*", // stdlib
  90. ".*", // platform
  91. "real_concept", // test type(s)
  92. ".*Ei.*", // test data group
  93. ".*", 150, 50); // test function
  94. add_expected_result(
  95. ".*", // compiler
  96. ".*", // stdlib
  97. ".*", // platform
  98. ".*", // test type(s)
  99. ".*", // test data group
  100. ".*", 25, 5); // test function
  101. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  102. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  103. }
  104. BOOST_AUTO_TEST_CASE( test_main )
  105. {
  106. expected_results();
  107. BOOST_MATH_CONTROL_FP;
  108. boost::math::expint(114.7);
  109. test_spots(0.0f, "float");
  110. test_spots(0.0, "double");
  111. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  112. test_spots(0.0L, "long double");
  113. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  114. test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
  115. #endif
  116. #else
  117. std::cout << "<note>The long double tests have been disabled on this platform "
  118. "either because the long double overloads of the usual math functions are "
  119. "not available at all, or because they are too inaccurate for these tests "
  120. "to pass.</note>" << std::endl;
  121. #endif
  122. test_expint(0.1F, "float");
  123. test_expint(0.1, "double");
  124. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  125. test_expint(0.1L, "long double");
  126. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  127. test_expint(boost::math::concepts::real_concept(0.1), "real_concept");
  128. #endif
  129. #else
  130. std::cout << "<note>The long double tests have been disabled on this platform "
  131. "either because the long double overloads of the usual math functions are "
  132. "not available at all, or because they are too inaccurate for these tests "
  133. "to pass.</note>" << std::endl;
  134. #endif
  135. }