hypergeometric_1F0.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include <boost/math/tools/promotion.hpp>
  14. namespace boost { namespace math { namespace detail {
  15. template <class T, class Policy>
  16. inline T hypergeometric_1F0_imp(const T& a, const T& z, const Policy& pol)
  17. {
  18. static const char* function = "boost::math::hypergeometric_1F0<%1%,%1%>(%1%, %1%)";
  19. BOOST_MATH_STD_USING // pow
  20. if (z == 1)
  21. return policies::raise_pole_error<T>(function, "Evaluation of 1F0 with z = %1%.", z, pol);
  22. if (1 - z < 0)
  23. {
  24. if (floor(a) != a)
  25. return policies::raise_domain_error<T>(function, "Result is complex when a is non-integral and z > 1, but got z = %1%", z, pol);
  26. }
  27. // more naive and convergent method than series
  28. return pow(T(1 - z), T(-a));
  29. }
  30. } // namespace detail
  31. template <class T1, class T2, class Policy>
  32. inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z, const Policy&)
  33. {
  34. BOOST_FPU_EXCEPTION_GUARD
  35. typedef typename tools::promote_args<T1, T2>::type result_type;
  36. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  37. typedef typename policies::normalise<
  38. Policy,
  39. policies::promote_float<false>,
  40. policies::promote_double<false>,
  41. policies::discrete_quantile<>,
  42. policies::assert_undefined<> >::type forwarding_policy;
  43. return policies::checked_narrowing_cast<result_type, Policy>(
  44. detail::hypergeometric_1F0_imp<value_type>(
  45. static_cast<value_type>(a),
  46. static_cast<value_type>(z),
  47. forwarding_policy()),
  48. "boost::math::hypergeometric_1F0<%1%>(%1%,%1%)");
  49. }
  50. template <class T1, class T2>
  51. inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z)
  52. {
  53. return hypergeometric_1F0(a, z, policies::policy<>());
  54. }
  55. } } // namespace boost::math
  56. #endif // BOOST_MATH_HYPERGEOMETRIC_1F0_HPP