Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / math / special_functions / detail / hypergeometric_1F1_cf.hpp
1
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)
7 //
8 #ifndef BOOST_MATH_HYPERGEOMETRIC_1F1_CF_HPP
9 #define BOOST_MATH_HYPERGEOMETRIC_1F1_CF_HPP
10
11 #include <boost/math/tools/fraction.hpp>
12
13 //
14 // Evaluation of 1F1 by continued fraction
15 // see http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric1F1/10/0002/
16 //
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.
19 //
20
21
22   namespace boost { namespace math { namespace detail {
23
24      template <class T>
25      struct hypergeometric_1F1_cf_func
26      {
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()()
30         {
31            ++k;
32            return std::make_pair(-(((a + k) * z) / ((k + 1) * (b + k))), 1 + ((a + k) * z) / ((k + 1) * (b + k)));
33         }
34         T a, b, z;
35         unsigned k;
36      };
37
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)
40      {
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));
46      }
47
48   } } } // namespaces
49
50 #endif // BOOST_MATH_HYPERGEOMETRIC_1F1_BESSEL_HPP