2 ///////////////////////////////////////////////////////////////////////////////
3 // Copyright 2018 John Maddock
4 // Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_MATH_HYPERGEOMETRIC_1F1_CF_HPP
9 #define BOOST_MATH_HYPERGEOMETRIC_1F1_CF_HPP
11 #include <boost/math/tools/fraction.hpp>
14 // Evaluation of 1F1 by continued fraction
15 // see http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric1F1/10/0002/
17 // This is not terribly useful, as like the series we're adding a something to 1,
18 // so only really useful when we know that the result will be > 1.
22 namespace boost { namespace math { namespace detail {
25 struct hypergeometric_1F1_cf_func
27 typedef std::pair<T, T> result_type;
28 hypergeometric_1F1_cf_func(T a_, T b_, T z_) : a(a_), b(b_), z(z_), k(0) {}
29 std::pair<T, T> operator()()
32 return std::make_pair(-(((a + k) * z) / ((k + 1) * (b + k))), 1 + ((a + k) * z) / ((k + 1) * (b + k)));
38 template <class T, class Policy>
39 T hypergeometric_1F1_cf(const T& a, const T& b, const T& z, const Policy& pol, const char* function)
41 hypergeometric_1F1_cf_func<T> func(a, b, z);
42 boost::uintmax_t max_iter = boost::math::policies::get_max_series_iterations<Policy>();
43 T result = boost::math::tools::continued_fraction_a(func, boost::math::policies::get_epsilon<T, Policy>(), max_iter);
44 boost::math::policies::check_series_iterations<T>(function, max_iter, pol);
45 return 1 + a * z / (b * (1 + result));
50 #endif // BOOST_MATH_HYPERGEOMETRIC_1F1_BESSEL_HPP