test_tgamma_ratio.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_tgamma_ratio.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the gamma ratio functions tgamma_ratio,
  12. // and tgamma_delta_ratio. The accuracy tests
  13. // use values generated with NTL::RR at 1000-bit precision
  14. // and our generic versions of these functions.
  15. //
  16. // Note that when this file is first run on a new platform many of
  17. // these tests will fail: the default accuracy is 1 epsilon which
  18. // is too tight for most platforms. In this situation you will
  19. // need to cast a human eye over the error rates reported and make
  20. // a judgement as to whether they are acceptable. Either way please
  21. // report the results to the Boost mailing list. Acceptable rates of
  22. // error are marked up below as a series of regular expressions that
  23. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  24. // along with the maximum expected peek and RMS mean errors for that
  25. // test.
  26. //
  27. void expected_results()
  28. {
  29. //
  30. // Define the max and mean errors expected for
  31. // various compilers and platforms.
  32. //
  33. const char* largest_type;
  34. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  35. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  36. {
  37. largest_type = "(long\\s+)?double";
  38. }
  39. else
  40. {
  41. largest_type = "long double";
  42. }
  43. #else
  44. largest_type = "(long\\s+)?double";
  45. #endif
  46. //
  47. // HP-UX
  48. // This is a weird one, HP-UX and Mac OS X show up errors at float
  49. // precision, that don't show up on other platforms.
  50. // There appears to be some kind of rounding issue going on (not enough
  51. // precision in the input to get the answer right):
  52. //
  53. add_expected_result(
  54. "[^|]*", // compiler
  55. "[^|]*", // stdlib
  56. "HP-UX|Mac OS|linux|.*(bsd|BSD).*", // platform
  57. "float", // test type(s)
  58. "[^|]*", // test data group
  59. "tgamma_ratio[^|]*", 35, 8); // test function
  60. //
  61. // Linux AMD x86em64 has slightly higher rates:
  62. //
  63. add_expected_result(
  64. "[^|]*", // compiler
  65. "[^|]*", // stdlib
  66. "linux.*", // platform
  67. largest_type, // test type(s)
  68. "[^|]*", // test data group
  69. "tgamma_ratio[^|]*", 300, 100); // test function
  70. add_expected_result(
  71. "[^|]*", // compiler
  72. "[^|]*", // stdlib
  73. "linux.*", // platform
  74. "real_concept", // test type(s)
  75. "[^|]*", // test data group
  76. "tgamma_ratio[^|]*", 300, 100); // test function
  77. add_expected_result(
  78. "GNU.*", // compiler
  79. "[^|]*", // stdlib
  80. "Win32.*", // platform
  81. largest_type, // test type(s)
  82. "[^|]*", // test data group
  83. "tgamma_ratio[^|]*", 300, 100); // test function
  84. //
  85. // Solaris:
  86. //
  87. add_expected_result(
  88. "[^|]*", // compiler
  89. "[^|]*", // stdlib
  90. ".*Solaris.*", // platform
  91. largest_type, // test type(s)
  92. "[^|]*", // test data group
  93. "tgamma_ratio[^|]*", 200, 100); // test function
  94. //
  95. // Catch all cases come last:
  96. //
  97. add_expected_result(
  98. "[^|]*", // compiler
  99. "[^|]*", // stdlib
  100. "[^|]*", // platform
  101. largest_type, // test type(s)
  102. "[^|]*", // test data group
  103. "tgamma_delta_ratio[^|]*", 30, 20); // test function
  104. add_expected_result(
  105. "[^|]*", // compiler
  106. "[^|]*", // stdlib
  107. "[^|]*", // platform
  108. largest_type, // test type(s)
  109. "[^|]*", // test data group
  110. "tgamma_ratio[^|]*", 100, 50); // test function
  111. add_expected_result(
  112. "[^|]*", // compiler
  113. "[^|]*", // stdlib
  114. "[^|]*", // platform
  115. "real_concept", // test type(s)
  116. "[^|]*", // test data group
  117. "tgamma_delta_ratio[^|]*", 50, 20); // test function
  118. add_expected_result(
  119. "[^|]*", // compiler
  120. "[^|]*", // stdlib
  121. "[^|]*", // platform
  122. "real_concept", // test type(s)
  123. "[^|]*", // test data group
  124. "[^|]*", 250, 150); // test function
  125. //
  126. // Finish off by printing out the compiler/stdlib/platform names,
  127. // we do this to make it easier to mark up expected error rates.
  128. //
  129. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  130. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  131. }
  132. BOOST_AUTO_TEST_CASE( test_main )
  133. {
  134. BOOST_MATH_CONTROL_FP;
  135. expected_results();
  136. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  137. test_tgamma_ratio(0.1F, "float");
  138. #endif
  139. test_tgamma_ratio(0.1, "double");
  140. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  141. test_tgamma_ratio(0.1L, "long double");
  142. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  143. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  144. test_tgamma_ratio(boost::math::concepts::real_concept(0.1), "real_concept");
  145. #endif
  146. #endif
  147. #else
  148. std::cout << "<note>The long double tests have been disabled on this platform "
  149. "either because the long double overloads of the usual math functions are "
  150. "not available at all, or because they are too inaccurate for these tests "
  151. "to pass.</note>" << std::endl;
  152. #endif
  153. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  154. test_spots(0.1F, "float");
  155. #endif
  156. test_spots(0.1, "double");
  157. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  158. test_spots(0.1L, "long double");
  159. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  160. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  161. test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
  162. #endif
  163. #endif
  164. #else
  165. std::cout << "<note>The long double tests have been disabled on this platform "
  166. "either because the long double overloads of the usual math functions are "
  167. "not available at all, or because they are too inaccurate for these tests "
  168. "to pass.</note>" << std::endl;
  169. #endif
  170. }