test_igamma_inva.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_inva.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_inva and gamma_q_inva. There are two sets of tests:
  19. // 2) TODO: Accuracy tests use values generated with NTL::RR at
  20. // 1000-bit precision and our generic versions of these functions.
  21. // 3) Round trip sanity checks, use the test data for the forward
  22. // functions, and verify that we can get (approximately) back
  23. // where we started.
  24. //
  25. // Note that when this file is first run on a new platform many of
  26. // these tests will fail: the default accuracy is 1 epsilon which
  27. // is too tight for most platforms. In this situation you will
  28. // need to cast a human eye over the error rates reported and make
  29. // a judgement as to whether they are acceptable. Either way please
  30. // report the results to the Boost mailing list. Acceptable rates of
  31. // error are marked up below as a series of regular expressions that
  32. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  33. // along with the maximum expected peek and RMS mean errors for that
  34. // test.
  35. //
  36. void expected_results()
  37. {
  38. //
  39. // Define the max and mean errors expected for
  40. // various compilers and platforms.
  41. //
  42. const char* largest_type;
  43. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  44. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  45. {
  46. largest_type = "(long\\s+)?double";
  47. }
  48. else
  49. {
  50. largest_type = "long double";
  51. }
  52. #else
  53. largest_type = "(long\\s+)?double";
  54. #endif
  55. //
  56. // Linux:
  57. //
  58. add_expected_result(
  59. "[^|]*", // compiler
  60. "[^|]*", // stdlib
  61. "linux", // platform
  62. largest_type, // test type(s)
  63. "[^|]*", // test data group
  64. "[^|]*", 800, 200); // test function
  65. //
  66. // Catch all cases come last:
  67. //
  68. add_expected_result(
  69. "[^|]*", // compiler
  70. "[^|]*", // stdlib
  71. "[^|]*", // platform
  72. "real_concept", // test type(s)
  73. "[^|]*", // test data group
  74. "[^|]*", 3000, 1000); // test function
  75. add_expected_result(
  76. "[^|]*", // compiler
  77. "[^|]*", // stdlib
  78. "[^|]*", // platform
  79. largest_type, // test type(s)
  80. "[^|]*", // test data group
  81. "[^|]*", 300, 100); // test function
  82. // this one has to come last in case double *is* the widest
  83. // float type:
  84. add_expected_result(
  85. "[^|]*", // compiler
  86. "[^|]*", // stdlib
  87. "[^|]*", // platform
  88. "float|double", // test type(s)
  89. "[^|]*", // test data group
  90. "[^|]*", 10, 5); // test function
  91. //
  92. // Finish off by printing out the compiler/stdlib/platform names,
  93. // we do this to make it easier to mark up expected error rates.
  94. //
  95. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  96. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  97. }
  98. BOOST_AUTO_TEST_CASE( test_main )
  99. {
  100. expected_results();
  101. BOOST_MATH_CONTROL_FP;
  102. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  103. #ifdef TEST_FLOAT
  104. test_gamma(0.1F, "float");
  105. #endif
  106. #endif
  107. #ifdef TEST_DOUBLE
  108. test_gamma(0.1, "double");
  109. #endif
  110. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  111. #ifdef TEST_LDOUBLE
  112. test_gamma(0.1L, "long double");
  113. #endif
  114. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  115. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  116. #ifdef TEST_REAL_CONCEPT
  117. test_gamma(boost::math::concepts::real_concept(0.1), "real_concept");
  118. #endif
  119. #endif
  120. #endif
  121. #else
  122. std::cout << "<note>The long double tests have been disabled on this platform "
  123. "either because the long double overloads of the usual math functions are "
  124. "not available at all, or because they are too inaccurate for these tests "
  125. "to pass.</note>" << std::endl;
  126. #endif
  127. }