hypergeometric_1F0.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2014 Anton Bikineev
  3. // Copyright 2014 Christopher Kormanyos
  4. // Copyright 2014 John Maddock
  5. // Copyright 2014 Paul Bristow
  6. // Distributed under the Boost
  7. // Software License, Version 1.0. (See accompanying file
  8. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_MATH_HYPERGEOMETRIC_1F0_HPP
  10. #define BOOST_MATH_HYPERGEOMETRIC_1F0_HPP
  11. #include <boost/math/policies/policy.hpp>
  12. #include <boost/math/policies/error_handling.hpp>
  13. namespace boost { namespace math { namespace detail {
  14. template <class T, class Policy>
  15. inline T hypergeometric_1F0_imp(const T& a, const T& z, const Policy& pol)
  16. {
  17. static const char* function = "boost::math::hypergeometric_1F0<%1%,%1%>(%1%, %1%)";
  18. BOOST_MATH_STD_USING // pow
  19. if (z == 1)
  20. return policies::raise_pole_error<T>(
  21. function,
  22. "Evaluation of 1F0 with z = %1%.",
  23. z,
  24. pol);
  25. if (1 - z < 0)
  26. {
  27. if (floor(a) != a)
  28. return policies::raise_domain_error<T>(function,
  29. "Result is complex when a is non-integral and z > 1, but got z = %1%", z, pol);
  30. }
  31. // more naive and convergent method than series
  32. return pow(T(1 - z), T(-a));
  33. }
  34. } // namespace detail
  35. template <class T1, class T2, class Policy>
  36. inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z, const Policy&)
  37. {
  38. BOOST_FPU_EXCEPTION_GUARD
  39. typedef typename tools::promote_args<T1, T2>::type result_type;
  40. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  41. typedef typename policies::normalise<
  42. Policy,
  43. policies::promote_float<false>,
  44. policies::promote_double<false>,
  45. policies::discrete_quantile<>,
  46. policies::assert_undefined<> >::type forwarding_policy;
  47. return policies::checked_narrowing_cast<result_type, Policy>(
  48. detail::hypergeometric_1F0_imp<value_type>(
  49. static_cast<value_type>(a),
  50. static_cast<value_type>(z),
  51. forwarding_policy()),
  52. "boost::math::hypergeometric_1F0<%1%>(%1%,%1%)");
  53. }
  54. template <class T1, class T2>
  55. inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z)
  56. {
  57. return hypergeometric_1F0(a, z, policies::policy<>());
  58. }
  59. } } // namespace boost::math
  60. #endif // BOOST_MATH_HYPERGEOMETRIC_1F0_HPP