...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/special_functions/ellint_d.hpp>
namespace boost { namespace math { template <class T1, class T2> calculatedresulttype ellint_d(T1 k, T2 phi); template <class T1, class T2, class Policy> calculatedresulttype ellint_d(T1 k, T2 phi, const Policy&); template <class T1> calculatedresulttype ellint_d(T1 k); template <class T1, class Policy> calculatedresulttype ellint_d(T1 k, const Policy&); }} // namespaces
These two functions evaluate the incomplete elliptic integral D(φ, k) and its complete counterpart D(k) = D(π/2, k).
The return type of these functions is computed using the __arg_pomotion_rules when the arguments are of different types: when they are the same type then the result is the same type as the arguments.
template <class T1, class T2> calculatedresulttype ellint_d(T1 k, T2 phi); template <class T1, class T2, class Policy> calculatedresulttype ellint_3(T1 k, T2 phi, const Policy&);
Returns the incomplete elliptic integral:
Requires 1 <= k <= 1, otherwise returns the result of domain_error (outside this range the result would be complex).
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
template <class T1> calculatedresulttype ellint_d(T1 k); template <class T1, class Policy> calculatedresulttype ellint_d(T1 k, const Policy&);
Returns the complete elliptic integral D(k) = D(π/2, k)
Requires 1 <= k <= 1 otherwise returns the result of domain_error (outside this range the result would be complex).
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
These functions are trivially computed in terms of other elliptic integrals and generally have very low error rates (a few epsilon) unless parameter φ is very large, in which case the usual trigonometric function argumentreduction issues apply.
Table 6.66. Error rates for ellint_d (complete)
Microsoft Visual C++ version 12.0 
GNU C++ version 5.1.0 
GNU C++ version 5.1.0 
Sun compiler version 0x5130 


Elliptic Integral E: Mathworld Data 
Max = 0.637ε (Mean = 0.368ε) 
Max = 0.637ε (Mean = 0.368ε) 
Max = 1.27ε (Mean = 0.735ε) 
Max = 1.27ε (Mean = 0.735ε) 
Elliptic Integral D: Random Data 
Max = 1.27ε (Mean = 0.355ε) 
Max = 0ε (Mean = 0ε) 
Max = 1.27ε (Mean = 0.334ε) 
Max = 1.27ε (Mean = 0.334ε) 
Table 6.67. Error rates for ellint_d
Microsoft Visual C++ version 12.0 
GNU C++ version 5.1.0 
GNU C++ version 5.1.0 
Sun compiler version 0x5130 


Elliptic Integral E: Mathworld Data 
Max = 0.862ε (Mean = 0.457ε) 
Max = 0ε (Mean = 0ε) 
Max = 1.3ε (Mean = 0.813ε) 
Max = 1.3ε (Mean = 0.813ε) 
Elliptic Integral D: Random Data 
Max = 2.87ε (Mean = 0.805ε) 
Max = 0ε (Mean = 0ε) 
Max = 2.51ε (Mean = 0.883ε) 
Max = 2.51ε (Mean = 0.883ε) 
The tests use a mixture of spot test values calculated using values calculated at wolframalpha.com, and random test data generated using MPFR at 1000bit precision and a deliberately naive implementation in terms of the Legendre integrals.
The implementation for D(φ, k) first performs argument reduction using the relations:
D(φ, k) = D(φ, k)
and
D(nπ+φ, k) = 2nD(k) + D(φ, k)
to move φ to the range [0, π/2].
The functions are then implemented in terms of Carlson's integral R_{D} using the relation: