Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:36:03

0001 //  Copyright (c) 2006 Xiaogang Zhang, 2015 John Maddock
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //  History:
0007 //  XZ wrote the original of this file as part of the Google
0008 //  Summer of Code 2006.  JM modified it to fit into the
0009 //  Boost.Math conceptual framework better, and to correctly
0010 //  handle the y < 0 case.
0011 //  Updated 2015 to use Carlson's latest methods.
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 // Carlson's degenerate elliptic integral
0029 // R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt
0030 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
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     // for y < 0, the integral is singular, return Cauchy principal value
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 } // namespace detail
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 }} // namespaces
0110 
0111 #endif // BOOST_MATH_ELLINT_RC_HPP
0112