File indexing completed on 2025-07-14 08:36:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_MATH_ELLINT_RC_HPP
0015 #define BOOST_MATH_ELLINT_RC_HPP
0016
0017 #ifdef _MSC_VER
0018 #pragma once
0019 #endif
0020
0021 #include <boost/math/policies/error_handling.hpp>
0022 #include <boost/math/tools/config.hpp>
0023 #include <boost/math/special_functions/math_fwd.hpp>
0024 #include <boost/math/special_functions/log1p.hpp>
0025 #include <boost/math/constants/constants.hpp>
0026 #include <iostream>
0027
0028
0029
0030
0031
0032 namespace boost { namespace math { namespace detail{
0033
0034 template <typename T, typename Policy>
0035 T ellint_rc_imp(T x, T y, const Policy& pol)
0036 {
0037 BOOST_MATH_STD_USING
0038
0039 static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)";
0040
0041 if(x < 0)
0042 {
0043 return policies::raise_domain_error<T>(function, "Argument x must be non-negative but got %1%", x, pol);
0044 }
0045 if(y == 0)
0046 {
0047 return policies::raise_domain_error<T>(function, "Argument y must not be zero but got %1%", y, pol);
0048 }
0049
0050
0051 T prefix, result;
0052 if(y < 0)
0053 {
0054 prefix = sqrt(x / (x - y));
0055 x = x - y;
0056 y = -y;
0057 }
0058 else
0059 prefix = 1;
0060
0061 if(x == 0)
0062 {
0063 result = constants::half_pi<T>() / sqrt(y);
0064 }
0065 else if(x == y)
0066 {
0067 result = 1 / sqrt(x);
0068 }
0069 else if(y > x)
0070 {
0071 result = atan(sqrt((y - x) / x)) / sqrt(y - x);
0072 }
0073 else
0074 {
0075 if(y / x > T(0.5))
0076 {
0077 T arg = sqrt((x - y) / x);
0078 result = (boost::math::log1p(arg, pol) - boost::math::log1p(-arg, pol)) / (2 * sqrt(x - y));
0079 }
0080 else
0081 {
0082 result = log((sqrt(x) + sqrt(x - y)) / sqrt(y)) / sqrt(x - y);
0083 }
0084 }
0085 return prefix * result;
0086 }
0087
0088 }
0089
0090 template <class T1, class T2, class Policy>
0091 inline typename tools::promote_args<T1, T2>::type
0092 ellint_rc(T1 x, T2 y, const Policy& pol)
0093 {
0094 typedef typename tools::promote_args<T1, T2>::type result_type;
0095 typedef typename policies::evaluation<result_type, Policy>::type value_type;
0096 return policies::checked_narrowing_cast<result_type, Policy>(
0097 detail::ellint_rc_imp(
0098 static_cast<value_type>(x),
0099 static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)");
0100 }
0101
0102 template <class T1, class T2>
0103 inline typename tools::promote_args<T1, T2>::type
0104 ellint_rc(T1 x, T2 y)
0105 {
0106 return ellint_rc(x, y, policies::policy<>());
0107 }
0108
0109 }}
0110
0111 #endif
0112