File indexing completed on 2025-01-18 09:40:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_MATH_HYPERGEOMETRIC_0F1_HPP
0011 #define BOOST_MATH_HYPERGEOMETRIC_0F1_HPP
0012
0013 #include <boost/math/policies/policy.hpp>
0014 #include <boost/math/policies/error_handling.hpp>
0015 #include <boost/math/special_functions/detail/hypergeometric_series.hpp>
0016 #include <boost/math/special_functions/detail/hypergeometric_0F1_bessel.hpp>
0017
0018 namespace boost { namespace math { namespace detail {
0019
0020
0021 template <class T>
0022 struct hypergeometric_0F1_cf
0023 {
0024
0025
0026
0027
0028
0029
0030
0031 T b, z;
0032 int k;
0033 hypergeometric_0F1_cf(T b_, T z_) : b(b_), z(z_), k(-2) {}
0034 typedef std::pair<T, T> result_type;
0035
0036 result_type operator()()
0037 {
0038 ++k;
0039 if (k <= 0)
0040 return std::make_pair(z / b, 1);
0041 return std::make_pair(-z / ((k + 1) * (b + k)), 1 + z / ((k + 1) * (b + k)));
0042 }
0043 };
0044
0045 template <class T, class Policy>
0046 T hypergeometric_0F1_cf_imp(T b, T z, const Policy& pol, const char* function)
0047 {
0048 hypergeometric_0F1_cf<T> evaluator(b, z);
0049 std::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
0050 T cf = tools::continued_fraction_b(evaluator, policies::get_epsilon<T, Policy>(), max_iter);
0051 policies::check_series_iterations<T>(function, max_iter, pol);
0052 return cf;
0053 }
0054
0055
0056 template <class T, class Policy>
0057 inline T hypergeometric_0F1_imp(const T& b, const T& z, const Policy& pol)
0058 {
0059 const char* function = "boost::math::hypergeometric_0f1<%1%,%1%>(%1%, %1%)";
0060 BOOST_MATH_STD_USING
0061
0062
0063 if (z == 0)
0064 return T(1);
0065
0066 if ((b <= 0) && (b == floor(b)))
0067 return policies::raise_pole_error<T>(
0068 function,
0069 "Evaluation of 0f1 with nonpositive integer b = %1%.", b, pol);
0070
0071 if (z < -5 && b > -5)
0072 {
0073
0074
0075
0076
0077 if (fabs(z / b) > 4)
0078 return hypergeometric_0F1_bessel(b, z, pol);
0079 return hypergeometric_0F1_cf_imp(b, z, pol, function);
0080 }
0081
0082
0083
0084 return detail::hypergeometric_0F1_generic_series(b, z, pol);
0085 }
0086
0087 }
0088
0089 template <class T1, class T2, class Policy>
0090 inline typename tools::promote_args<T1, T2>::type hypergeometric_0F1(T1 b, T2 z, const Policy& )
0091 {
0092 BOOST_FPU_EXCEPTION_GUARD
0093 typedef typename tools::promote_args<T1, T2>::type result_type;
0094 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0095 typedef typename policies::normalise<
0096 Policy,
0097 policies::promote_float<false>,
0098 policies::promote_double<false>,
0099 policies::discrete_quantile<>,
0100 policies::assert_undefined<> >::type forwarding_policy;
0101 return policies::checked_narrowing_cast<result_type, Policy>(
0102 detail::hypergeometric_0F1_imp<value_type>(
0103 static_cast<value_type>(b),
0104 static_cast<value_type>(z),
0105 forwarding_policy()),
0106 "boost::math::hypergeometric_0F1<%1%>(%1%,%1%)");
0107 }
0108
0109 template <class T1, class T2>
0110 inline typename tools::promote_args<T1, T2>::type hypergeometric_0F1(T1 b, T2 z)
0111 {
0112 return hypergeometric_0F1(b, z, policies::policy<>());
0113 }
0114
0115
0116 } }
0117
0118 #endif