Chris@101: // Copyright (c) 2006 Xiaogang Zhang, 2015 John Maddock Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // History: Chris@16: // XZ wrote the original of this file as part of the Google Chris@16: // Summer of Code 2006. JM modified it to fit into the Chris@16: // Boost.Math conceptual framework better, and to correctly Chris@16: // handle the y < 0 case. Chris@101: // Updated 2015 to use Carlson's latest methods. Chris@16: // Chris@16: Chris@16: #ifndef BOOST_MATH_ELLINT_RC_HPP Chris@16: #define BOOST_MATH_ELLINT_RC_HPP Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@16: Chris@16: // Carlson's degenerate elliptic integral Chris@16: // R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt Chris@16: // Carlson, Numerische Mathematik, vol 33, 1 (1979) Chris@16: Chris@16: namespace boost { namespace math { namespace detail{ Chris@16: Chris@16: template Chris@16: T ellint_rc_imp(T x, T y, const Policy& pol) Chris@16: { Chris@16: BOOST_MATH_STD_USING Chris@16: Chris@16: static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)"; Chris@16: Chris@16: if(x < 0) Chris@16: { Chris@16: return policies::raise_domain_error(function, Chris@16: "Argument x must be non-negative but got %1%", x, pol); Chris@16: } Chris@16: if(y == 0) Chris@16: { Chris@16: return policies::raise_domain_error(function, Chris@16: "Argument y must not be zero but got %1%", y, pol); Chris@16: } Chris@16: Chris@16: // for y < 0, the integral is singular, return Cauchy principal value Chris@101: T prefix, result; Chris@101: if(y < 0) Chris@16: { Chris@16: prefix = sqrt(x / (x - y)); Chris@16: x = x - y; Chris@16: y = -y; Chris@16: } Chris@16: else Chris@16: prefix = 1; Chris@16: Chris@101: if(x == 0) Chris@16: { Chris@101: result = constants::half_pi() / sqrt(y); Chris@101: } Chris@101: else if(x == y) Chris@101: { Chris@101: result = 1 / sqrt(x); Chris@101: } Chris@101: else if(y > x) Chris@101: { Chris@101: result = atan(sqrt((y - x) / x)) / sqrt(y - x); Chris@101: } Chris@101: else Chris@101: { Chris@101: if(y / x > 0.5) Chris@101: { Chris@101: T arg = sqrt((x - y) / x); Chris@101: result = (boost::math::log1p(arg) - boost::math::log1p(-arg)) / (2 * sqrt(x - y)); Chris@101: } Chris@101: else Chris@101: { Chris@101: result = log((sqrt(x) + sqrt(x - y)) / sqrt(y)) / sqrt(x - y); Chris@101: } Chris@101: } Chris@101: return prefix * result; Chris@16: } Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: ellint_rc(T1 x, T2 y, const Policy& pol) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: typedef typename policies::evaluation::type value_type; Chris@16: return policies::checked_narrowing_cast( Chris@16: detail::ellint_rc_imp( Chris@16: static_cast(x), Chris@16: static_cast(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)"); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: ellint_rc(T1 x, T2 y) Chris@16: { Chris@16: return ellint_rc(x, y, policies::policy<>()); Chris@16: } Chris@16: Chris@16: }} // namespaces Chris@16: Chris@16: #endif // BOOST_MATH_ELLINT_RC_HPP Chris@16: