]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/math/special_functions/ellint_rc.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / math / special_functions / ellint_rc.hpp
CommitLineData
7c673cae
FG
1// Copyright (c) 2006 Xiaogang Zhang, 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// History:
7// XZ wrote the original of this file as part of the Google
8// Summer of Code 2006. JM modified it to fit into the
9// Boost.Math conceptual framework better, and to correctly
10// handle the y < 0 case.
11// Updated 2015 to use Carlson's latest methods.
12//
13
14#ifndef BOOST_MATH_ELLINT_RC_HPP
15#define BOOST_MATH_ELLINT_RC_HPP
16
17#ifdef _MSC_VER
18#pragma once
19#endif
20
21#include <boost/math/policies/error_handling.hpp>
22#include <boost/math/tools/config.hpp>
23#include <boost/math/special_functions/math_fwd.hpp>
24#include <boost/math/special_functions/log1p.hpp>
25#include <boost/math/constants/constants.hpp>
26#include <iostream>
27
28// Carlson's degenerate elliptic integral
29// R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt
30// Carlson, Numerische Mathematik, vol 33, 1 (1979)
31
32namespace boost { namespace math { namespace detail{
33
34template <typename T, typename Policy>
35T ellint_rc_imp(T x, T y, const Policy& pol)
36{
37 BOOST_MATH_STD_USING
38
39 static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)";
40
41 if(x < 0)
42 {
43 return policies::raise_domain_error<T>(function,
44 "Argument x must be non-negative but got %1%", x, pol);
45 }
46 if(y == 0)
47 {
48 return policies::raise_domain_error<T>(function,
49 "Argument y must not be zero but got %1%", y, pol);
50 }
51
52 // for y < 0, the integral is singular, return Cauchy principal value
53 T prefix, result;
54 if(y < 0)
55 {
56 prefix = sqrt(x / (x - y));
57 x = x - y;
58 y = -y;
59 }
60 else
61 prefix = 1;
62
63 if(x == 0)
64 {
65 result = constants::half_pi<T>() / sqrt(y);
66 }
67 else if(x == y)
68 {
69 result = 1 / sqrt(x);
70 }
71 else if(y > x)
72 {
73 result = atan(sqrt((y - x) / x)) / sqrt(y - x);
74 }
75 else
76 {
77 if(y / x > 0.5)
78 {
79 T arg = sqrt((x - y) / x);
20effc67 80 result = (boost::math::log1p(arg, pol) - boost::math::log1p(-arg, pol)) / (2 * sqrt(x - y));
7c673cae
FG
81 }
82 else
83 {
84 result = log((sqrt(x) + sqrt(x - y)) / sqrt(y)) / sqrt(x - y);
85 }
86 }
87 return prefix * result;
88}
89
90} // namespace detail
91
92template <class T1, class T2, class Policy>
93inline typename tools::promote_args<T1, T2>::type
94 ellint_rc(T1 x, T2 y, const Policy& pol)
95{
96 typedef typename tools::promote_args<T1, T2>::type result_type;
97 typedef typename policies::evaluation<result_type, Policy>::type value_type;
98 return policies::checked_narrowing_cast<result_type, Policy>(
99 detail::ellint_rc_imp(
100 static_cast<value_type>(x),
101 static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)");
102}
103
104template <class T1, class T2>
105inline typename tools::promote_args<T1, T2>::type
106 ellint_rc(T1 x, T2 y)
107{
108 return ellint_rc(x, y, policies::policy<>());
109}
110
111}} // namespaces
112
113#endif // BOOST_MATH_ELLINT_RC_HPP
114