hypergeometric_1F0.hpp 2.4 KB

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