test_2F0.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright John Maddock 2006.
  2. // Copyright Paul A. Bristow 2007, 2009
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  7. #include <boost/math/concepts/real_concept.hpp>
  8. #include <boost/math/special_functions/math_fwd.hpp>
  9. #define BOOST_TEST_MAIN
  10. #include <boost/test/unit_test.hpp>
  11. #include <boost/test/tools/floating_point_comparison.hpp>
  12. #include <boost/math/tools/stats.hpp>
  13. #include <boost/math/tools/test.hpp>
  14. #include <boost/math/tools/big_constant.hpp>
  15. #include <boost/math/constants/constants.hpp>
  16. #include <boost/type_traits/is_floating_point.hpp>
  17. #include <boost/array.hpp>
  18. #include "functor.hpp"
  19. #include "handle_test_result.hpp"
  20. #include "table_type.hpp"
  21. #include <boost/math/special_functions/hypergeometric_2F0.hpp>
  22. template <class Real, class T>
  23. void do_test_2F0(const T& data, const char* type_name, const char* test_name)
  24. {
  25. typedef Real value_type;
  26. typedef value_type(*pg)(value_type, value_type, value_type);
  27. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  28. pg funcp = boost::math::hypergeometric_0F1<value_type, value_type>;
  29. #else
  30. pg funcp = boost::math::hypergeometric_2F0;
  31. #endif
  32. boost::math::tools::test_result<value_type> result;
  33. std::cout << "Testing " << test_name << " with type " << type_name
  34. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  35. //
  36. // test hypergeometric_2F0 against data:
  37. //
  38. result = boost::math::tools::test_hetero<Real>(
  39. data,
  40. bind_func<Real>(funcp, 0, 1, 2),
  41. extract_result<Real>(3));
  42. handle_test_result(result, data[result.worst()], result.worst(), type_name, "hypergeometric_0F1", test_name);
  43. std::cout << std::endl;
  44. }
  45. #ifndef SC_
  46. #define SC_(x) BOOST_MATH_BIG_CONSTANT(T, 1000000, x)
  47. #endif
  48. template <class T>
  49. void test_spots1(T, const char* type_name)
  50. {
  51. #include "hypergeometric_2F0.ipp"
  52. do_test_2F0<T>(hypergeometric_2F0, type_name, "Random non-integer a2, |z| < 1");
  53. #include "hypergeometric_2F0_large_z.ipp"
  54. do_test_2F0<T>(hypergeometric_2F0_large_z, type_name, "Random non-integer a2, |z| > 1");
  55. }
  56. template <class T>
  57. void test_spots2(T, const char* type_name)
  58. {
  59. #include "hypergeometric_2F0_integer_a2.ipp"
  60. do_test_2F0<T>(hypergeometric_2F0_integer_a2, type_name, "Integer a2, |z| > 1");
  61. #include "hypergeometric_2F0_half.ipp"
  62. do_test_2F0<T>(hypergeometric_2F0_half, type_name, "a1 = a2 + 0.5");
  63. }
  64. template <class T>
  65. void test_spots(T z, const char* type_name)
  66. {
  67. test_spots1(z, type_name);
  68. test_spots2(z, type_name);
  69. T a1 = 1;
  70. T a2 = 0.1f;
  71. z = -1;
  72. if (std::numeric_limits<T>::has_infinity)
  73. {
  74. BOOST_CHECK((boost::math::isinf)(boost::math::hypergeometric_2F0(a1, a2, z)));
  75. z = 1;
  76. BOOST_CHECK((boost::math::isinf)(boost::math::hypergeometric_2F0(a1, a2, z)));
  77. a2 = -2.4f;
  78. BOOST_CHECK((boost::math::isinf)(boost::math::hypergeometric_2F0(a1, a2, z)));
  79. a1 = -0.5f;
  80. BOOST_CHECK((boost::math::isinf)(boost::math::hypergeometric_2F0(a1, a2, z)));
  81. }
  82. }