test_gamma.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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_gamma.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the functions tgamma and lgamma, and the
  12. // function tgamma1pm1. 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. // G++ on Darwin: results are just slightly worse than we might hope for
  51. // but still pretty good:
  52. //
  53. add_expected_result(
  54. ".*", // compiler
  55. ".*", // stdlib
  56. "Mac OS", // platform
  57. largest_type, // test type(s)
  58. "factorials", // test data group
  59. "tgamma", 100, 15); // test function
  60. //
  61. // G++ On Win32:
  62. //
  63. add_expected_result(
  64. "GNU.*", // compiler
  65. ".*", // stdlib
  66. "Win32.*", // platform
  67. largest_type, // test type(s)
  68. "factorials", // test data group
  69. "tgamma", 100, 15); // test function
  70. add_expected_result(
  71. "GNU.*", // compiler
  72. ".*", // stdlib
  73. "Win32.*", // platform
  74. "real_concept", // test type(s)
  75. "factorials", // test data group
  76. "tgamma", 600, 200); // test function
  77. add_expected_result(
  78. "GNU.*", // compiler
  79. ".*", // stdlib
  80. "Win32.*", // platform
  81. "real_concept", // test type(s)
  82. "near.*", // test data group
  83. "tgamma", 200, 100); // test function
  84. //
  85. // G++ on Linux, result vary a bit by processor type,
  86. // on Itanium results are *much* better than listed here,
  87. // but x86 appears to have much less accurate std::pow
  88. // that throws off the results:
  89. //
  90. add_expected_result(
  91. ".*", // compiler
  92. ".*", // stdlib
  93. "linux", // platform
  94. largest_type, // test type(s)
  95. "factorials", // test data group
  96. "tgamma", 600, 200); // test function
  97. add_expected_result(
  98. ".*", // compiler
  99. ".*", // stdlib
  100. "linux", // platform
  101. largest_type, // test type(s)
  102. "factorials", // test data group
  103. "lgamma", 30, 10); // test function
  104. add_expected_result(
  105. ".*", // compiler
  106. ".*", // stdlib
  107. "linux", // platform
  108. largest_type, // test type(s)
  109. "near (1|2|-10)", // test data group
  110. "tgamma", 10, 5); // test function
  111. add_expected_result(
  112. ".*", // compiler
  113. ".*", // stdlib
  114. "linux", // platform
  115. largest_type, // test type(s)
  116. "near (1|2|-10)", // test data group
  117. "lgamma", 50, 50); // test function
  118. add_expected_result(
  119. ".*", // compiler
  120. ".*", // stdlib
  121. "linux", // platform
  122. largest_type, // test type(s)
  123. "tgamma1pm1.*", // test data group
  124. "tgamma1pm1", 50, 15); // test function
  125. add_expected_result(
  126. ".*", // compiler
  127. ".*", // stdlib
  128. "linux", // platform
  129. "real_concept", // test type(s)
  130. "factorials", // test data group
  131. "tgamma", 600, 100); // test function
  132. add_expected_result(
  133. ".*", // compiler
  134. ".*", // stdlib
  135. "linux", // platform
  136. "real_concept", // test type(s)
  137. "near (0|-55)", // test data group
  138. "(t|l)gamma", 300, 150); // test function
  139. add_expected_result(
  140. ".*", // compiler
  141. ".*", // stdlib
  142. "linux", // platform
  143. "real_concept", // test type(s)
  144. "tgamma1pm1.*", // test data group
  145. "tgamma1pm1", 40, 10); // test function
  146. //
  147. // HP-UX results:
  148. //
  149. add_expected_result(
  150. ".*", // compiler
  151. ".*", // stdlib
  152. "HP-UX", // platform
  153. largest_type, // test type(s)
  154. "factorials", // test data group
  155. "tgamma", 5, 4); // test function
  156. add_expected_result(
  157. ".*", // compiler
  158. ".*", // stdlib
  159. "HP-UX", // platform
  160. largest_type, // test type(s)
  161. "near (0|-55)", // test data group
  162. "tgamma", 10, 5); // test function
  163. add_expected_result(
  164. ".*", // compiler
  165. ".*", // stdlib
  166. "HP-UX", // platform
  167. largest_type, // test type(s)
  168. "near (1|2|-10)", // test data group
  169. "lgamma", 250, 200); // test function
  170. add_expected_result(
  171. ".*", // compiler
  172. ".*", // stdlib
  173. "HP-UX", // platform
  174. "real_concept", // test type(s)
  175. "factorials", // test data group
  176. "lgamma", 50, 20); // test function
  177. add_expected_result(
  178. ".*", // compiler
  179. ".*", // stdlib
  180. "HP-UX", // platform
  181. "real_concept", // test type(s)
  182. "tgamma1pm1.*", // test data group
  183. "tgamma1pm1", 200, 80); // test function
  184. //
  185. // Tru64:
  186. //
  187. add_expected_result(
  188. ".*Tru64.*", // compiler
  189. ".*", // stdlib
  190. ".*", // platform
  191. "real_concept", // test type(s)
  192. "factorials", // test data group
  193. "lgamma", 50, 20); // test function
  194. //
  195. // Sun OS:
  196. //
  197. add_expected_result(
  198. ".*", // compiler
  199. ".*", // stdlib
  200. "Sun.*", // platform
  201. largest_type, // test type(s)
  202. "factorials", // test data group
  203. "tgamma", 450, 100); // test function
  204. add_expected_result(
  205. ".*", // compiler
  206. ".*", // stdlib
  207. ".*Solaris.*", // platform
  208. "real_concept", // test type(s)
  209. "factorials", // test data group
  210. "tgamma", 450, 150); // test function
  211. //
  212. // Catch all cases come last:
  213. //
  214. add_expected_result(
  215. ".*", // compiler
  216. ".*", // stdlib
  217. ".*", // platform
  218. largest_type, // test type(s)
  219. "factorials", // test data group
  220. "tgamma", 4, 1); // test function
  221. add_expected_result(
  222. ".*", // compiler
  223. ".*", // stdlib
  224. ".*", // platform
  225. largest_type, // test type(s)
  226. "factorials", // test data group
  227. "lgamma", 9, 1); // test function
  228. add_expected_result(
  229. ".*", // compiler
  230. ".*", // stdlib
  231. ".*", // platform
  232. largest_type, // test type(s)
  233. "near (0|-55)", // test data group
  234. "(t|l)gamma", 200, 100); // test function
  235. add_expected_result(
  236. ".*", // compiler
  237. ".*", // stdlib
  238. ".*", // platform
  239. largest_type, // test type(s)
  240. "near (1|2|-10)", // test data group
  241. "tgamma", 10, 5); // test function
  242. add_expected_result(
  243. ".*", // compiler
  244. ".*", // stdlib
  245. ".*", // platform
  246. largest_type, // test type(s)
  247. "near (1|2|-10)", // test data group
  248. "lgamma", 14, 7); // test function
  249. add_expected_result(
  250. ".*", // compiler
  251. ".*", // stdlib
  252. ".*", // platform
  253. largest_type, // test type(s)
  254. "tgamma1pm1.*", // test data group
  255. "tgamma1pm1", 30, 9); // test function
  256. add_expected_result(
  257. ".*", // compiler
  258. ".*", // stdlib
  259. ".*", // platform
  260. "real_concept", // test type(s)
  261. "factorials", // test data group
  262. "tgamma", 600, 100); // test function
  263. add_expected_result(
  264. ".*", // compiler
  265. ".*", // stdlib
  266. ".*", // platform
  267. "real_concept", // test type(s)
  268. "factorials", // test data group
  269. "lgamma", 200, 20); // test function
  270. add_expected_result(
  271. ".*", // compiler
  272. ".*", // stdlib
  273. ".*", // platform
  274. "real_concept", // test type(s)
  275. "near.*", // test data group
  276. "tgamma", 300, 100); // test function
  277. add_expected_result(
  278. ".*", // compiler
  279. ".*", // stdlib
  280. ".*", // platform
  281. "real_concept", // test type(s)
  282. "near.*", // test data group
  283. "lgamma", 40000000, 10000000); // test function
  284. add_expected_result(
  285. ".*", // compiler
  286. ".*", // stdlib
  287. ".*", // platform
  288. "real_concept", // test type(s)
  289. "tgamma1pm1.*", // test data group
  290. "tgamma1pm1", 20, 5); // test function
  291. //
  292. // Finish off by printing out the compiler/stdlib/platform names,
  293. // we do this to make it easier to mark up expected error rates.
  294. //
  295. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  296. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  297. }
  298. BOOST_AUTO_TEST_CASE( test_main )
  299. {
  300. expected_results();
  301. BOOST_MATH_CONTROL_FP;
  302. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  303. test_spots(0.0F, "float");
  304. #endif
  305. test_spots(0.0, "double");
  306. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  307. test_spots(0.0L, "long double");
  308. test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
  309. #endif
  310. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  311. test_gamma(0.1F, "float");
  312. #endif
  313. test_gamma(0.1, "double");
  314. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  315. test_gamma(0.1L, "long double");
  316. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  317. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  318. test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
  319. #endif
  320. #endif
  321. #else
  322. std::cout << "<note>The long double tests have been disabled on this platform "
  323. "either because the long double overloads of the usual math functions are "
  324. "not available at all, or because they are too inaccurate for these tests "
  325. "to pass.</note>" << std::endl;
  326. #endif
  327. }