annotate DEPENDENCIES/generic/include/boost/math/special_functions/ellint_rc.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@101 1 // Copyright (c) 2006 Xiaogang Zhang, 2015 John Maddock
Chris@16 2 // Use, modification and distribution are subject to the
Chris@16 3 // Boost Software License, Version 1.0. (See accompanying file
Chris@16 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 //
Chris@16 6 // History:
Chris@16 7 // XZ wrote the original of this file as part of the Google
Chris@16 8 // Summer of Code 2006. JM modified it to fit into the
Chris@16 9 // Boost.Math conceptual framework better, and to correctly
Chris@16 10 // handle the y < 0 case.
Chris@101 11 // Updated 2015 to use Carlson's latest methods.
Chris@16 12 //
Chris@16 13
Chris@16 14 #ifndef BOOST_MATH_ELLINT_RC_HPP
Chris@16 15 #define BOOST_MATH_ELLINT_RC_HPP
Chris@16 16
Chris@16 17 #ifdef _MSC_VER
Chris@16 18 #pragma once
Chris@16 19 #endif
Chris@16 20
Chris@16 21 #include <boost/math/policies/error_handling.hpp>
Chris@16 22 #include <boost/math/tools/config.hpp>
Chris@16 23 #include <boost/math/special_functions/math_fwd.hpp>
Chris@101 24 #include <boost/math/special_functions/log1p.hpp>
Chris@101 25 #include <boost/math/constants/constants.hpp>
Chris@101 26 #include <iostream>
Chris@16 27
Chris@16 28 // Carlson's degenerate elliptic integral
Chris@16 29 // R_C(x, y) = R_F(x, y, y) = 0.5 * \int_{0}^{\infty} (t+x)^{-1/2} (t+y)^{-1} dt
Chris@16 30 // Carlson, Numerische Mathematik, vol 33, 1 (1979)
Chris@16 31
Chris@16 32 namespace boost { namespace math { namespace detail{
Chris@16 33
Chris@16 34 template <typename T, typename Policy>
Chris@16 35 T ellint_rc_imp(T x, T y, const Policy& pol)
Chris@16 36 {
Chris@16 37 BOOST_MATH_STD_USING
Chris@16 38
Chris@16 39 static const char* function = "boost::math::ellint_rc<%1%>(%1%,%1%)";
Chris@16 40
Chris@16 41 if(x < 0)
Chris@16 42 {
Chris@16 43 return policies::raise_domain_error<T>(function,
Chris@16 44 "Argument x must be non-negative but got %1%", x, pol);
Chris@16 45 }
Chris@16 46 if(y == 0)
Chris@16 47 {
Chris@16 48 return policies::raise_domain_error<T>(function,
Chris@16 49 "Argument y must not be zero but got %1%", y, pol);
Chris@16 50 }
Chris@16 51
Chris@16 52 // for y < 0, the integral is singular, return Cauchy principal value
Chris@101 53 T prefix, result;
Chris@101 54 if(y < 0)
Chris@16 55 {
Chris@16 56 prefix = sqrt(x / (x - y));
Chris@16 57 x = x - y;
Chris@16 58 y = -y;
Chris@16 59 }
Chris@16 60 else
Chris@16 61 prefix = 1;
Chris@16 62
Chris@101 63 if(x == 0)
Chris@16 64 {
Chris@101 65 result = constants::half_pi<T>() / sqrt(y);
Chris@101 66 }
Chris@101 67 else if(x == y)
Chris@101 68 {
Chris@101 69 result = 1 / sqrt(x);
Chris@101 70 }
Chris@101 71 else if(y > x)
Chris@101 72 {
Chris@101 73 result = atan(sqrt((y - x) / x)) / sqrt(y - x);
Chris@101 74 }
Chris@101 75 else
Chris@101 76 {
Chris@101 77 if(y / x > 0.5)
Chris@101 78 {
Chris@101 79 T arg = sqrt((x - y) / x);
Chris@101 80 result = (boost::math::log1p(arg) - boost::math::log1p(-arg)) / (2 * sqrt(x - y));
Chris@101 81 }
Chris@101 82 else
Chris@101 83 {
Chris@101 84 result = log((sqrt(x) + sqrt(x - y)) / sqrt(y)) / sqrt(x - y);
Chris@101 85 }
Chris@101 86 }
Chris@101 87 return prefix * result;
Chris@16 88 }
Chris@16 89
Chris@16 90 } // namespace detail
Chris@16 91
Chris@16 92 template <class T1, class T2, class Policy>
Chris@16 93 inline typename tools::promote_args<T1, T2>::type
Chris@16 94 ellint_rc(T1 x, T2 y, const Policy& pol)
Chris@16 95 {
Chris@16 96 typedef typename tools::promote_args<T1, T2>::type result_type;
Chris@16 97 typedef typename policies::evaluation<result_type, Policy>::type value_type;
Chris@16 98 return policies::checked_narrowing_cast<result_type, Policy>(
Chris@16 99 detail::ellint_rc_imp(
Chris@16 100 static_cast<value_type>(x),
Chris@16 101 static_cast<value_type>(y), pol), "boost::math::ellint_rc<%1%>(%1%,%1%)");
Chris@16 102 }
Chris@16 103
Chris@16 104 template <class T1, class T2>
Chris@16 105 inline typename tools::promote_args<T1, T2>::type
Chris@16 106 ellint_rc(T1 x, T2 y)
Chris@16 107 {
Chris@16 108 return ellint_rc(x, y, policies::policy<>());
Chris@16 109 }
Chris@16 110
Chris@16 111 }} // namespaces
Chris@16 112
Chris@16 113 #endif // BOOST_MATH_ELLINT_RC_HPP
Chris@16 114