1 
2 ///////////////////////////////////////////////////////////////////////////////
3 //  Copyright 2014 Anton Bikineev
4 //  Copyright 2014 Christopher Kormanyos
5 //  Copyright 2014 John Maddock
6 //  Copyright 2014 Paul Bristow
7 //  Distributed under the Boost
8 //  Software License, Version 1.0. (See accompanying file
9 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef BOOST_MATH_HYPERGEOMETRIC_1F0_HPP
12 #define BOOST_MATH_HYPERGEOMETRIC_1F0_HPP
13 
14 #include <boost/math/policies/policy.hpp>
15 #include <boost/math/policies/error_handling.hpp>
16 
17 
18 namespace boost { namespace math { namespace detail {
19 
20 template <class T, class Policy>
hypergeometric_1F0_imp(const T & a,const T & z,const Policy & pol)21 inline T hypergeometric_1F0_imp(const T& a, const T& z, const Policy& pol)
22 {
23    static const char* function = "boost::math::hypergeometric_1F0<%1%,%1%>(%1%, %1%)";
24    BOOST_MATH_STD_USING // pow
25 
26    if (z == 1)
27       return policies::raise_pole_error<T>(
28          function,
29          "Evaluation of 1F0 with z = %1%.",
30          z,
31          pol);
32    if (1 - z < 0)
33    {
34       if (floor(a) != a)
35          return policies::raise_domain_error<T>(function,
36             "Result is complex when a is non-integral and z > 1, but got z = %1%", z, pol);
37    }
38    // more naive and convergent method than series
39    return pow(T(1 - z), T(-a));
40 }
41 
42 } // namespace detail
43 
44 template <class T1, class T2, class Policy>
hypergeometric_1F0(T1 a,T2 z,const Policy &)45 inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z, const Policy&)
46 {
47    BOOST_FPU_EXCEPTION_GUARD
48    typedef typename tools::promote_args<T1, T2>::type result_type;
49    typedef typename policies::evaluation<result_type, Policy>::type value_type;
50    typedef typename policies::normalise<
51       Policy,
52       policies::promote_float<false>,
53       policies::promote_double<false>,
54       policies::discrete_quantile<>,
55       policies::assert_undefined<> >::type forwarding_policy;
56    return policies::checked_narrowing_cast<result_type, Policy>(
57       detail::hypergeometric_1F0_imp<value_type>(
58          static_cast<value_type>(a),
59          static_cast<value_type>(z),
60          forwarding_policy()),
61       "boost::math::hypergeometric_1F0<%1%>(%1%,%1%)");
62 }
63 
64 template <class T1, class T2>
hypergeometric_1F0(T1 a,T2 z)65 inline typename tools::promote_args<T1, T2>::type hypergeometric_1F0(T1 a, T2 z)
66 {
67    return hypergeometric_1F0(a, z, policies::policy<>());
68 }
69 
70 
71   } } // namespace boost::math
72 
73 #endif // BOOST_MATH_HYPERGEOMETRIC_1F0_HPP
74