]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/include/boost/math/special_functions/jacobi_zeta.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / special_functions / jacobi_zeta.hpp
1 // Copyright (c) 2015 John Maddock
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 //
6
7 #ifndef BOOST_MATH_ELLINT_JZ_HPP
8 #define BOOST_MATH_ELLINT_JZ_HPP
9
10 #ifdef _MSC_VER
11 #pragma once
12 #endif
13
14 #include <boost/math/special_functions/math_fwd.hpp>
15 #include <boost/math/special_functions/ellint_1.hpp>
16 #include <boost/math/special_functions/ellint_rj.hpp>
17 #include <boost/math/constants/constants.hpp>
18 #include <boost/math/policies/error_handling.hpp>
19 #include <boost/math/tools/workaround.hpp>
20
21 // Elliptic integral the Jacobi Zeta function.
22
23 namespace boost { namespace math {
24
25 namespace detail{
26
27 // Elliptic integral - Jacobi Zeta
28 template <typename T, typename Policy>
29 T jacobi_zeta_imp(T phi, T k, const Policy& pol)
30 {
31 BOOST_MATH_STD_USING
32 using namespace boost::math::tools;
33 using namespace boost::math::constants;
34
35 bool invert = false;
36 if(phi < 0)
37 {
38 phi = fabs(phi);
39 invert = true;
40 }
41
42 T result;
43 T sinp = sin(phi);
44 T cosp = cos(phi);
45 T s2 = sinp * sinp;
46 T k2 = k * k;
47 T kp = 1 - k2;
48 if(k == 1)
49 result = sinp * (boost::math::sign)(cosp); // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.
50 else
51 result = k2 * sinp * cosp * sqrt(1 - k2 * s2) * ellint_rj_imp(T(0), kp, T(1), T(1 - k2 * s2), pol) / (3 * ellint_k_imp(k, pol));
52 return invert ? T(-result) : result;
53 }
54
55 } // detail
56
57 template <class T1, class T2, class Policy>
58 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)
59 {
60 typedef typename tools::promote_args<T1, T2>::type result_type;
61 typedef typename policies::evaluation<result_type, Policy>::type value_type;
62 return policies::checked_narrowing_cast<result_type, Policy>(detail::jacobi_zeta_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::jacobi_zeta<%1%>(%1%,%1%)");
63 }
64
65 template <class T1, class T2>
66 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)
67 {
68 return boost::math::jacobi_zeta(k, phi, policies::policy<>());
69 }
70
71 }} // namespaces
72
73 #endif // BOOST_MATH_ELLINT_D_HPP
74