test_ellint_d.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright John Maddock 2015.
  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. #ifdef _MSC_VER
  6. # pragma warning(disable : 4756) // overflow in constant arithmetic
  7. // Constants are too big for float case, but this doesn't matter for test.
  8. #endif
  9. #include <boost/math/concepts/real_concept.hpp>
  10. #define BOOST_TEST_MAIN
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/test/tools/floating_point_comparison.hpp>
  13. #include <boost/math/special_functions/math_fwd.hpp>
  14. #include <boost/array.hpp>
  15. #include "functor.hpp"
  16. #include "handle_test_result.hpp"
  17. #include "table_type.hpp"
  18. #ifndef SC_
  19. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  20. #endif
  21. template <class Real, typename T>
  22. void do_test_ellint_d2(const T& data, const char* type_name, const char* test)
  23. {
  24. #if !(defined(ERROR_REPORTING_MODE) && !defined(ELLINT_D2_FUNCTION_TO_TEST))
  25. typedef Real value_type;
  26. std::cout << "Testing: " << test << std::endl;
  27. #ifdef ELLINT_D2_FUNCTION_TO_TEST
  28. value_type(*fp2)(value_type, value_type) = ELLINT_D2_FUNCTION_TO_TEST;
  29. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  30. value_type (*fp2)(value_type, value_type) = boost::math::ellint_d<value_type, value_type>;
  31. #else
  32. value_type (*fp2)(value_type, value_type) = boost::math::ellint_d;
  33. #endif
  34. boost::math::tools::test_result<value_type> result;
  35. result = boost::math::tools::test_hetero<Real>(
  36. data,
  37. bind_func<Real>(fp2, 1, 0),
  38. extract_result<Real>(2));
  39. handle_test_result(result, data[result.worst()], result.worst(),
  40. type_name, "ellint_d", test);
  41. std::cout << std::endl;
  42. #endif
  43. }
  44. template <class Real, typename T>
  45. void do_test_ellint_d1(T& data, const char* type_name, const char* test)
  46. {
  47. #if !(defined(ERROR_REPORTING_MODE) && !defined(ELLINT_D1_FUNCTION_TO_TEST))
  48. typedef Real value_type;
  49. boost::math::tools::test_result<value_type> result;
  50. std::cout << "Testing: " << test << std::endl;
  51. #ifdef ELLINT_D1_FUNCTION_TO_TEST
  52. value_type(*fp1)(value_type) = ELLINT_D1_FUNCTION_TO_TEST;
  53. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  54. value_type (*fp1)(value_type) = boost::math::ellint_d<value_type>;
  55. #else
  56. value_type (*fp1)(value_type) = boost::math::ellint_d;
  57. #endif
  58. result = boost::math::tools::test_hetero<Real>(
  59. data,
  60. bind_func<Real>(fp1, 0),
  61. extract_result<Real>(1));
  62. handle_test_result(result, data[result.worst()], result.worst(),
  63. type_name, "ellint_d (complete)", test);
  64. std::cout << std::endl;
  65. #endif
  66. }
  67. template <typename T>
  68. void test_spots(T, const char* type_name)
  69. {
  70. BOOST_MATH_STD_USING
  71. // Function values calculated on http://functions.wolfram.com/
  72. // Note that Mathematica's EllipticE accepts k^2 as the second parameter.
  73. static const boost::array<boost::array<T, 3>, 11> data1 = {{
  74. { { SC_(0.5), SC_(0.5), SC_(0.040348098248931543984282958654503585) } },
  75. {{ SC_(0), SC_(0.5), SC_(0) }},
  76. { { SC_(1), SC_(0.5), SC_(0.28991866293419922467977188008516755) } },
  77. { { SC_(1), T(1), SC_(0.38472018607562056416055864584160775) } },
  78. { { SC_(-1), T(1), SC_(-0.38472018607562056416055864584160775) } },
  79. { { SC_(-1), T(0.5), SC_(-0.28991866293419922467977188008516755) } },
  80. { { SC_(-10), T(0.5), SC_(-5.2996914501577855803123384771117708) } },
  81. { { SC_(10), SC_(-0.5), SC_(5.2996914501577855803123384771117708) } },
  82. { { SC_(0.125), SC_(1.5), SC_(0.000655956467603362564458676111698495009248974444516843) } },
  83. }};
  84. do_test_ellint_d2<T>(data1, type_name, "Elliptic Integral E: Mathworld Data");
  85. #include "ellint_d2_data.ipp"
  86. do_test_ellint_d2<T>(ellint_d2_data, type_name, "Elliptic Integral D: Random Data");
  87. // Function values calculated on http://functions.wolfram.com/
  88. // Note that Mathematica's EllipticE accepts k^2 as the second parameter.
  89. static const boost::array<boost::array<T, 2>, 3> data2 = {{
  90. { { SC_(0.5), SC_(0.87315258189267554964563356323264341) } },
  91. { { SC_(1.0) / 1024, SC_(0.78539844427788694671464428063604776) } },
  92. { { boost::math::tools::root_epsilon<T>(), SC_(0.78539816339744830961566084581987572) } }
  93. }};
  94. do_test_ellint_d1<T>(data2, type_name, "Elliptic Integral E: Mathworld Data");
  95. #include "ellint_d_data.ipp"
  96. do_test_ellint_d1<T>(ellint_d_data, type_name, "Elliptic Integral D: Random Data");
  97. BOOST_MATH_CHECK_THROW(boost::math::ellint_d(T(1)), std::domain_error);
  98. BOOST_MATH_CHECK_THROW(boost::math::ellint_d(T(-1)), std::domain_error);
  99. BOOST_MATH_CHECK_THROW(boost::math::ellint_d(T(1.5)), std::domain_error);
  100. BOOST_MATH_CHECK_THROW(boost::math::ellint_d(T(-1.5)), std::domain_error);
  101. }