test_igamma.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the incomplete gamma functions tgamma,
  12. // tgamma_lower, gamma_p and gamma_q. There are two sets of tests, spot
  13. // tests which compare our results with selected values computed
  14. // using the online special function calculator at
  15. // functions.wolfram.com, while the bulk of the accuracy tests
  16. // use values generated with NTL::RR at 1000-bit precision
  17. // and our generic versions of these functions.
  18. //
  19. // Note that when this file is first run on a new platform many of
  20. // these tests will fail: the default accuracy is 1 epsilon which
  21. // is too tight for most platforms. In this situation you will
  22. // need to cast a human eye over the error rates reported and make
  23. // a judgement as to whether they are acceptable. Either way please
  24. // report the results to the Boost mailing list. Acceptable rates of
  25. // error are marked up below as a series of regular expressions that
  26. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  27. // along with the maximum expected peek and RMS mean errors for that
  28. // test.
  29. //
  30. void expected_results()
  31. {
  32. //
  33. // Define the max and mean errors expected for
  34. // various compilers and platforms.
  35. //
  36. const char* largest_type;
  37. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  38. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  39. {
  40. largest_type = "(long\\s+)?double";
  41. }
  42. else
  43. {
  44. largest_type = "long double";
  45. }
  46. #else
  47. largest_type = "(long\\s+)?double";
  48. #endif
  49. //
  50. // Linux:
  51. //
  52. // These should not really be needed, but on *some* Linux
  53. // versions these error rates are quite large and appear to
  54. // be related to the accuracy of powl and expl. On Itanium
  55. // or Xeon machines the error rates are much lower than this.
  56. // Worst cases appear to be AMD64 machines.
  57. //
  58. add_expected_result(
  59. "[^|]*", // compiler
  60. "[^|]*", // stdlib
  61. "linux", // platform
  62. largest_type, // test type(s)
  63. "[^|]*medium[^|]*", // test data group
  64. "[^|]*", 1300, 200); // test function
  65. add_expected_result(
  66. "[^|]*", // compiler
  67. "[^|]*", // stdlib
  68. ".*Solaris.*", // platform
  69. "real_concept", // test type(s)
  70. "[^|]*medium[^|]*", // test data group
  71. "[^|]*", 1000, 200); // test function
  72. add_expected_result(
  73. "[^|]*", // compiler
  74. "[^|]*", // stdlib
  75. "linux", // platform
  76. largest_type, // test type(s)
  77. "[^|]*integer[^|]*", // test data group
  78. "[^|]*", 1300, 200); // test function
  79. add_expected_result(
  80. "[^|]*", // compiler
  81. "[^|]*", // stdlib
  82. "linux", // platform
  83. "real_concept", // test type(s)
  84. "[^|]*medium[^|]*", // test data group
  85. "[^|]*", 1300, 200); // test function
  86. add_expected_result(
  87. "[^|]*", // compiler
  88. "[^|]*", // stdlib
  89. "linux", // platform
  90. "real_concept", // test type(s)
  91. "[^|]*integer[^|]*", // test data group
  92. "[^|]*", 600, 200); // test function
  93. //
  94. // Mac OS X:
  95. // It's not clear why these should be required, but see notes above
  96. // about Linux.
  97. //
  98. add_expected_result(
  99. "[^|]*", // compiler
  100. "[^|]*", // stdlib
  101. "Mac OS", // platform
  102. largest_type, // test type(s)
  103. "[^|]*medium[^|]*", // test data group
  104. "[^|]*", 5000, 1000); // test function
  105. add_expected_result(
  106. "[^|]*", // compiler
  107. "[^|]*", // stdlib
  108. "Mac OS", // platform
  109. largest_type, // test type(s)
  110. "[^|]*small[^|]*", // test data group
  111. "[^|]*", 80, 40); // test function
  112. add_expected_result(
  113. "[^|]*", // compiler
  114. "[^|]*", // stdlib
  115. "Mac OS", // platform
  116. largest_type, // test type(s)
  117. "[^|]*integer[^|]*", // test data group
  118. "[^|]*", 2000, 300); // test function
  119. add_expected_result(
  120. "[^|]*", // compiler
  121. "[^|]*", // stdlib
  122. "Mac OS", // platform
  123. "real_concept", // test type(s)
  124. "[^|]*medium[^|]*", // test data group
  125. "[^|]*", 5000, 1000); // test function
  126. add_expected_result(
  127. "[^|]*", // compiler
  128. "[^|]*", // stdlib
  129. "Mac OS", // platform
  130. "real_concept", // test type(s)
  131. "[^|]*small[^|]*", // test data group
  132. "[^|]*", 75, 15); // test function
  133. add_expected_result(
  134. "[^|]*", // compiler
  135. "[^|]*", // stdlib
  136. "Mac OS", // platform
  137. "real_concept", // test type(s)
  138. "[^|]*integer[^|]*", // test data group
  139. "[^|]*", 2000, 300); // test function
  140. //
  141. // HP-UX:
  142. //
  143. add_expected_result(
  144. "[^|]*", // compiler
  145. "[^|]*", // stdlib
  146. "HP-UX", // platform
  147. largest_type, // test type(s)
  148. "[^|]*medium[^|]*", // test data group
  149. "[^|]*", 500, 50); // test function
  150. add_expected_result(
  151. "[^|]*", // compiler
  152. "[^|]*", // stdlib
  153. "HP-UX", // platform
  154. "real_concept", // test type(s)
  155. "[^|]*medium[^|]*", // test data group
  156. "[^|]*", 500, 100); // test function
  157. //
  158. // Sun OS:
  159. //
  160. add_expected_result(
  161. "[^|]*", // compiler
  162. "[^|]*", // stdlib
  163. "Sun.*", // platform
  164. largest_type, // test type(s)
  165. "[^|]*medium[^|]*", // test data group
  166. "[^|]*", 500, 100); // test function
  167. add_expected_result(
  168. "[^|]*", // compiler
  169. "[^|]*", // stdlib
  170. "Sun.*", // platform
  171. largest_type, // test type(s)
  172. "[^|]*integer[^|]*", // test data group
  173. "[^|]*", 100, 30); // test function
  174. add_expected_result(
  175. "[^|]*", // compiler
  176. "[^|]*", // stdlib
  177. "Sun.*", // platform
  178. "real_concept", // test type(s)
  179. "[^|]*medium[^|]*", // test data group
  180. "[^|]*", 500, 100); // test function
  181. add_expected_result(
  182. "[^|]*", // compiler
  183. "[^|]*", // stdlib
  184. "Sun.*", // platform
  185. "real_concept", // test type(s)
  186. "[^|]*integer[^|]*", // test data group
  187. "[^|]*", 100, 30); // test function
  188. //
  189. // Mac OS X:
  190. //
  191. add_expected_result(
  192. "[^|]*", // compiler
  193. "[^|]*", // stdlib
  194. "Mac OS", // platform
  195. largest_type, // test type(s)
  196. "[^|]*medium[^|]*", // test data group
  197. "[^|]*", 100, 50); // test function
  198. //
  199. // Minw:
  200. //
  201. add_expected_result(
  202. "GNU[^|]*", // compiler
  203. "[^|]*", // stdlib
  204. "Win32[^|]*", // platform
  205. "real_concept", // test type(s)
  206. "[^|]*medium[^|]*", // test data group
  207. "[^|]*", 1300, 200); // test function
  208. add_expected_result(
  209. "GNU[^|]*", // compiler
  210. "[^|]*", // stdlib
  211. "Win32[^|]*", // platform
  212. largest_type, // test type(s)
  213. "[^|]*medium[^|]*", // test data group
  214. "[^|]*", 700, 200); // test function
  215. add_expected_result(
  216. "GNU[^|]*", // compiler
  217. "[^|]*", // stdlib
  218. "Win32[^|]*", // platform
  219. largest_type, // test type(s)
  220. "[^|]*small[^|]*", // test data group
  221. "[^|]*", 100, 50); // test function
  222. add_expected_result(
  223. "GNU[^|]*", // compiler
  224. "[^|]*", // stdlib
  225. "Win32[^|]*", // platform
  226. largest_type, // test type(s)
  227. "[^|]*integer[^|]*", // test data group
  228. ".*", 120, 50); // test function
  229. add_expected_result(
  230. "GNU[^|]*", // compiler
  231. "[^|]*", // stdlib
  232. "Win32[^|]*", // platform
  233. "real_concept", // test type(s)
  234. "[^|]*integer[^|]*", // test data group
  235. ".*", 100, 50); // test function
  236. //
  237. // Large exponent range causes more extreme test cases to be evaluated:
  238. //
  239. if(std::numeric_limits<long double>::max_exponent > std::numeric_limits<double>::max_exponent)
  240. {
  241. add_expected_result(
  242. "[^|]*", // compiler
  243. "[^|]*", // stdlib
  244. "[^|]*", // platform
  245. largest_type, // test type(s)
  246. "[^|]*large[^|]*", // test data group
  247. ".*", 40000, 3000); // test function
  248. }
  249. //
  250. // Catch all cases come last:
  251. //
  252. add_expected_result(
  253. "[^|]*", // compiler
  254. "[^|]*", // stdlib
  255. "[^|]*", // platform
  256. largest_type, // test type(s)
  257. "[^|]*medium[^|]*", // test data group
  258. "[^|]*", 50, 20); // test function
  259. add_expected_result(
  260. "[^|]*", // compiler
  261. "[^|]*", // stdlib
  262. "[^|]*", // platform
  263. largest_type, // test type(s)
  264. "[^|]*small[^|]*", // test data group
  265. "[^|]*", 20, 10); // test function
  266. add_expected_result(
  267. "[^|]*", // compiler
  268. "[^|]*", // stdlib
  269. "[^|]*", // platform
  270. largest_type, // test type(s)
  271. "[^|]*large[^|]*", // test data group
  272. "gamma_q", 500, 50); // test function
  273. add_expected_result(
  274. "[^|]*", // compiler
  275. "[^|]*", // stdlib
  276. "Cygwin", // platform
  277. largest_type, // test type(s)
  278. "[^|]*large[^|]*", // test data group
  279. "gamma_p", 700, 50); // test function
  280. add_expected_result(
  281. "[^|]*", // compiler
  282. "[^|]*", // stdlib
  283. "[^|]*", // platform
  284. largest_type, // test type(s)
  285. "[^|]*large[^|]*", // test data group
  286. "gamma_p", 350, 50); // test function
  287. add_expected_result(
  288. "[^|]*", // compiler
  289. "[^|]*", // stdlib
  290. "[^|]*", // platform
  291. largest_type, // test type(s)
  292. "[^|]*integer[^|]*", // test data group
  293. ".*", 20, 10); // test function
  294. add_expected_result(
  295. "[^|]*", // compiler
  296. "[^|]*", // stdlib
  297. "[^|]*", // platform
  298. "real_concept", // test type(s)
  299. "[^|]*medium[^|]*", // test data group
  300. "[^|]*", 1500, 400); // test function
  301. add_expected_result(
  302. "[^|]*", // compiler
  303. "[^|]*", // stdlib
  304. "[^|]*", // platform
  305. "real_concept", // test type(s)
  306. "[^|]*small[^|]*", // test data group
  307. ".*", 100, 20); // test function
  308. add_expected_result(
  309. "[^|]*", // compiler
  310. "[^|]*", // stdlib
  311. "[^|]*", // platform
  312. "real_concept", // test type(s)
  313. "[^|]*large[^|]*", // test data group
  314. ".*", 1000000, 100000); // test function
  315. add_expected_result(
  316. "[^|]*", // compiler
  317. "[^|]*", // stdlib
  318. "[^|]*", // platform
  319. "real_concept", // test type(s)
  320. "[^|]*integer[^|]*", // test data group
  321. ".*", 200, 40); // test function
  322. //
  323. // Finish off by printing out the compiler/stdlib/platform names,
  324. // we do this to make it easier to mark up expected error rates.
  325. //
  326. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  327. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  328. }
  329. BOOST_AUTO_TEST_CASE( test_main )
  330. {
  331. expected_results();
  332. BOOST_MATH_CONTROL_FP;
  333. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  334. test_spots(0.0F);
  335. #endif
  336. test_spots(0.0);
  337. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  338. test_spots(0.0L);
  339. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  340. test_spots(boost::math::concepts::real_concept(0.1));
  341. #endif
  342. #endif
  343. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  344. test_gamma(0.1F, "float");
  345. #endif
  346. test_gamma(0.1, "double");
  347. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  348. test_gamma(0.1L, "long double");
  349. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  350. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  351. test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
  352. #endif
  353. #endif
  354. #else
  355. std::cout << "<note>The long double tests have been disabled on this platform "
  356. "either because the long double overloads of the usual math functions are "
  357. "not available at all, or because they are too inaccurate for these tests "
  358. "to pass.</note>" << std::endl;
  359. #endif
  360. }