test_jacobi_zeta.hpp 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/math/constants/constants.hpp>
  15. //#include <boost/math/special_functions/next.hpp>
  16. #include <boost/array.hpp>
  17. #include "functor.hpp"
  18. #include "handle_test_result.hpp"
  19. #include "table_type.hpp"
  20. #ifndef SC_
  21. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  22. #endif
  23. template <class Real, typename T>
  24. void do_test_jacobi_zeta(const T& data, const char* type_name, const char* test)
  25. {
  26. #if !(defined(ERROR_REPORTING_MODE) && !defined(JACOBI_ZETA_FUNCTION_TO_TEST))
  27. typedef Real value_type;
  28. std::cout << "Testing: " << test << std::endl;
  29. #ifdef JACOBI_ZETA_FUNCTION_TO_TEST
  30. value_type(*fp2)(value_type, value_type) = JACOBI_ZETA_FUNCTION_TO_TEST;
  31. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  32. value_type (*fp2)(value_type, value_type) = boost::math::ellint_d<value_type, value_type>;
  33. #else
  34. value_type(*fp2)(value_type, value_type) = boost::math::jacobi_zeta;
  35. #endif
  36. boost::math::tools::test_result<value_type> result;
  37. result = boost::math::tools::test_hetero<Real>(
  38. data,
  39. bind_func<Real>(fp2, 1, 0),
  40. extract_result<Real>(2));
  41. handle_test_result(result, data[result.worst()], result.worst(),
  42. type_name, "jacobi_zeta", test);
  43. std::cout << std::endl;
  44. #endif
  45. }
  46. template <typename T>
  47. void test_spots(T, const char* type_name)
  48. {
  49. BOOST_MATH_STD_USING
  50. // Function values calculated on http://functions.wolfram.com/
  51. // Note that Mathematica's EllipticE accepts k^2 as the second parameter.
  52. static const boost::array<boost::array<T, 3>, 18> data1 = {{
  53. { { SC_(0.5), SC_(0.5), SC_(0.055317014255129651475392155709691519) } },
  54. { { SC_(-0.5), SC_(0.5), SC_(-0.055317014255129651475392155709691519) } },
  55. { { SC_(0), SC_(0.5), SC_(0) } },
  56. { { SC_(1), T(0.5), SC_(0.061847782565098669252626761181452815) } },
  57. // { { boost::math::float_prior(boost::math::constants::half_pi<T>()), T(0.5), SC_(0) } },
  58. { { SC_(1), T(0), SC_(0) } },
  59. { { SC_(1), T(1), SC_(0.84147098480789650665250232163029900) } },
  60. { { SC_(2), T(0.5), SC_(-0.051942537457672732722176231281435254) } },
  61. { { SC_(5), T(0.5), SC_(-0.037609329968145259476447488930872898) } },
  62. { { SC_(0.5), SC_(1), SC_(0.479425538604203000273287935215571388081803367940600675188616) } },
  63. { { boost::math::constants::half_pi<T>() - static_cast<T>(1) / 1024, SC_(1), SC_(0.999999523162879692486369202949889069215510235208243466564977) } },
  64. { { boost::math::constants::half_pi<T>() + static_cast<T>(1) / 1024, SC_(1), SC_(-0.999999523162879692486369202949889069215510235208243466564977) } },
  65. { { SC_(2), SC_(1), SC_(-0.90929742682568169539601986591174484270225497144789026837897) } },
  66. { { SC_(3), SC_(1), SC_(-0.14112000805986722210074480280811027984693326425226558415188) } },
  67. { { SC_(4), SC_(1), SC_(0.756802495307928251372639094511829094135912887336472571485416) } },
  68. { { SC_(-0.5), SC_(1), SC_(-0.479425538604203000273287935215571388081803367940600675188616) } },
  69. { { SC_(-2), SC_(1), SC_(0.90929742682568169539601986591174484270225497144789026837897) } },
  70. { { SC_(-3), SC_(1), SC_(0.14112000805986722210074480280811027984693326425226558415188) } },
  71. { { SC_(-4), SC_(1), SC_(-0.756802495307928251372639094511829094135912887336472571485416) } },
  72. }};
  73. do_test_jacobi_zeta<T>(data1, type_name, "Elliptic Integral Jacobi Zeta: Mathworld Data");
  74. #include "jacobi_zeta_data.ipp"
  75. do_test_jacobi_zeta<T>(jacobi_zeta_data, type_name, "Elliptic Integral Jacobi Zeta: Random Data");
  76. #include "jacobi_zeta_big_phi.ipp"
  77. do_test_jacobi_zeta<T>(jacobi_zeta_big_phi, type_name, "Elliptic Integral Jacobi Zeta: Large Phi Values");
  78. }