test_igamma_inv.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // (C) Copyright John Maddock 2006.
  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_igamma_inv.hpp"
  7. #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
  8. # define TEST_FLOAT
  9. # define TEST_DOUBLE
  10. # define TEST_LDOUBLE
  11. # define TEST_REAL_CONCEPT
  12. #endif
  13. //
  14. // DESCRIPTION:
  15. // ~~~~~~~~~~~~
  16. //
  17. // This file tests the incomplete gamma function inverses
  18. // gamma_p_inv and gamma_q_inv. There are three sets of tests:
  19. // 1) Spot tests which compare our results with selected values
  20. // computed using the online special function calculator at
  21. // functions.wolfram.com,
  22. // 2) Accuracy tests use values generated with NTL::RR at
  23. // 1000-bit precision and our generic versions of these functions.
  24. // 3) Round trip sanity checks, use the test data for the forward
  25. // functions, and verify that we can get (approximately) back
  26. // where we started.
  27. //
  28. // Note that when this file is first run on a new platform many of
  29. // these tests will fail: the default accuracy is 1 epsilon which
  30. // is too tight for most platforms. In this situation you will
  31. // need to cast a human eye over the error rates reported and make
  32. // a judgement as to whether they are acceptable. Either way please
  33. // report the results to the Boost mailing list. Acceptable rates of
  34. // error are marked up below as a series of regular expressions that
  35. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  36. // along with the maximum expected peek and RMS mean errors for that
  37. // test.
  38. //
  39. void expected_results()
  40. {
  41. //
  42. // Define the max and mean errors expected for
  43. // various compilers and platforms.
  44. //
  45. const char* largest_type;
  46. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  47. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  48. {
  49. largest_type = "(long\\s+)?double";
  50. }
  51. else
  52. {
  53. largest_type = "long double";
  54. }
  55. #else
  56. largest_type = "(long\\s+)?double";
  57. #endif
  58. //
  59. // Large exponent range causes more extreme test cases to be evaluated:
  60. //
  61. if(std::numeric_limits<long double>::max_exponent > std::numeric_limits<double>::max_exponent)
  62. {
  63. add_expected_result(
  64. "[^|]*", // compiler
  65. "[^|]*", // stdlib
  66. "[^|]*", // platform
  67. largest_type, // test type(s)
  68. "[^|]*small[^|]*", // test data group
  69. "[^|]*", 200000, 10000); // test function
  70. add_expected_result(
  71. "[^|]*", // compiler
  72. "[^|]*", // stdlib
  73. "[^|]*", // platform
  74. "real_concept", // test type(s)
  75. "[^|]*small[^|]*", // test data group
  76. "[^|]*", 98000, 12000); // test function
  77. }
  78. //
  79. // These high error rates are seen on on some Linux
  80. // architectures:
  81. //
  82. add_expected_result(
  83. "[^|]*", // compiler
  84. "[^|]*", // stdlib
  85. "linux.*", // platform
  86. largest_type, // test type(s)
  87. "[^|]*medium[^|]*", // test data group
  88. "[^|]*", 350, 5); // test function
  89. add_expected_result(
  90. "[^|]*", // compiler
  91. "[^|]*", // stdlib
  92. "linux.*", // platform
  93. largest_type, // test type(s)
  94. "[^|]*large[^|]*", // test data group
  95. "[^|]*", 150, 5); // test function
  96. //
  97. // Catch all cases come last:
  98. //
  99. add_expected_result(
  100. "[^|]*", // compiler
  101. "[^|]*", // stdlib
  102. "[^|]*", // platform
  103. largest_type, // test type(s)
  104. "[^|]*medium[^|]*", // test data group
  105. "[^|]*", 20, 5); // test function
  106. add_expected_result(
  107. "[^|]*", // compiler
  108. "[^|]*", // stdlib
  109. "[^|]*", // platform
  110. largest_type, // test type(s)
  111. "[^|]*large[^|]*", // test data group
  112. "[^|]*", 5, 2); // test function
  113. add_expected_result(
  114. "[^|]*", // compiler
  115. "[^|]*", // stdlib
  116. "[^|]*", // platform
  117. largest_type, // test type(s)
  118. "[^|]*small[^|]*", // test data group
  119. "[^|]*", 2100, 500); // test function
  120. add_expected_result(
  121. "[^|]*", // compiler
  122. "[^|]*", // stdlib
  123. "[^|]*", // platform
  124. "float|double", // test type(s)
  125. "[^|]*small[^|]*", // test data group
  126. "gamma_p_inv", 500, 60); // test function
  127. add_expected_result(
  128. "[^|]*", // compiler
  129. "[^|]*", // stdlib
  130. "[^|]*", // platform
  131. "float|double", // test type(s)
  132. "[^|]*", // test data group
  133. "gamma_q_inv", 350, 60); // test function
  134. add_expected_result(
  135. "[^|]*", // compiler
  136. "[^|]*", // stdlib
  137. "[^|]*", // platform
  138. "float|double", // test type(s)
  139. "[^|]*", // test data group
  140. "[^|]*", 4, 2); // test function
  141. add_expected_result(
  142. "[^|]*", // compiler
  143. "[^|]*", // stdlib
  144. "[^|]*", // platform
  145. "real_concept", // test type(s)
  146. "[^|]*medium[^|]*", // test data group
  147. "[^|]*", 20, 5); // test function
  148. add_expected_result(
  149. "[^|]*", // compiler
  150. "[^|]*", // stdlib
  151. "[^|]*", // platform
  152. "real_concept", // test type(s)
  153. "[^|]*large[^|]*", // test data group
  154. "[^|]*", 1000, 500); // test function
  155. add_expected_result(
  156. "[^|]*", // compiler
  157. "[^|]*", // stdlib
  158. "[^|]*", // platform
  159. "real_concept", // test type(s)
  160. "[^|]*small[^|]*", // test data group
  161. "[^|]*", 3700, 500); // test function
  162. //
  163. // Finish off by printing out the compiler/stdlib/platform names,
  164. // we do this to make it easier to mark up expected error rates.
  165. //
  166. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  167. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  168. }
  169. BOOST_AUTO_TEST_CASE( test_main )
  170. {
  171. expected_results();
  172. BOOST_MATH_CONTROL_FP;
  173. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  174. #ifdef TEST_FLOAT
  175. test_spots(0.0F, "float");
  176. #endif
  177. #endif
  178. #ifdef TEST_DOUBLE
  179. test_spots(0.0, "double");
  180. #endif
  181. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  182. #ifdef TEST_LDOUBLE
  183. test_spots(0.0L, "long double");
  184. #endif
  185. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  186. #ifdef TEST_REAL_CONCEPT
  187. test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
  188. #endif
  189. #endif
  190. #endif
  191. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  192. #ifdef TEST_FLOAT
  193. test_gamma(0.1F, "float");
  194. #endif
  195. #endif
  196. #ifdef TEST_DOUBLE
  197. test_gamma(0.1, "double");
  198. #endif
  199. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  200. #ifdef TEST_LDOUBLE
  201. test_gamma(0.1L, "long double");
  202. #endif
  203. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  204. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  205. #ifdef TEST_REAL_CONCEPT
  206. test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
  207. #endif
  208. #endif
  209. #endif
  210. #else
  211. std::cout << "<note>The long double tests have been disabled on this platform "
  212. "either because the long double overloads of the usual math functions are "
  213. "not available at all, or because they are too inaccurate for these tests "
  214. "to pass.</note>" << std::endl;
  215. #endif
  216. }