brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 0500272 Raw
98 lines · plain
1//  Copyright (c) 2015 John Maddock2//  Copyright (c) 2024 Matt Borland3//  Use, modification and distribution are subject to the4//  Boost Software License, Version 1.0. (See accompanying file5//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)6 7#ifndef BOOST_MATH_ELLINT_HL_HPP8#define BOOST_MATH_ELLINT_HL_HPP9 10#ifdef _MSC_VER11#pragma once12#endif13 14#include <boost/math/tools/config.hpp>15#include <boost/math/tools/numeric_limits.hpp>16#include <boost/math/tools/type_traits.hpp>17#include <boost/math/special_functions/math_fwd.hpp>18#include <boost/math/special_functions/ellint_rj.hpp>19#include <boost/math/special_functions/ellint_1.hpp>20#include <boost/math/special_functions/jacobi_zeta.hpp>21#include <boost/math/constants/constants.hpp>22#include <boost/math/policies/error_handling.hpp>23#include <boost/math/tools/workaround.hpp>24 25// Elliptic integral the Jacobi Zeta function.26 27namespace boost { namespace math { 28   29namespace detail{30 31// Elliptic integral - Jacobi Zeta32template <typename T, typename Policy>33BOOST_MATH_GPU_ENABLED T heuman_lambda_imp(T phi, T k, const Policy& pol)34{35    BOOST_MATH_STD_USING36    using namespace boost::math::tools;37    using namespace boost::math::constants;38 39    constexpr auto function = "boost::math::heuman_lambda<%1%>(%1%, %1%)";40 41    if(fabs(k) > 1)42       return policies::raise_domain_error<T>(function, "We require |k| <= 1 but got k = %1%", k, pol);43 44    T result;45    T sinp = sin(phi);46    T cosp = cos(phi);47    T s2 = sinp * sinp;48    T k2 = k * k;49    T kp = 1 - k2;50    T delta = sqrt(1 - (kp * s2));51    if(fabs(phi) <= constants::half_pi<T>())52    {53       result = kp * sinp * cosp / (delta * constants::half_pi<T>());54       result *= ellint_rf_imp(T(0), kp, T(1), pol) + k2 * ellint_rj(T(0), kp, T(1), T(1 - k2 / (delta * delta)), pol) / (3 * delta * delta);55    }56    else57    {58       typedef boost::math::integral_constant<int,59          boost::math::is_floating_point<T>::value && boost::math::numeric_limits<T>::digits && (boost::math::numeric_limits<T>::digits <= 54) ? 0 :60          boost::math::is_floating_point<T>::value && boost::math::numeric_limits<T>::digits && (boost::math::numeric_limits<T>::digits <= 64) ? 1 : 261       > precision_tag_type;62 63       T rkp = sqrt(kp);64       T ratio;65       if(rkp == 1)66       {67          return policies::raise_domain_error<T>(function, "When 1-k^2 == 1 then phi must be < Pi/2, but got phi = %1%", phi, pol);68       }69       else70       {71          ratio = ellint_f_imp(phi, rkp, pol, k2) / ellint_k_imp(rkp, pol, k2);72       }73       result = ratio + ellint_k_imp(k, pol, precision_tag_type()) * jacobi_zeta_imp(phi, rkp, pol, k2) / constants::half_pi<T>();74    }75    return result;76}77 78} // detail79 80template <class T1, class T2, class Policy>81BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi, const Policy& pol)82{83   typedef typename tools::promote_args<T1, T2>::type result_type;84   typedef typename policies::evaluation<result_type, Policy>::type value_type;85   return policies::checked_narrowing_cast<result_type, Policy>(detail::heuman_lambda_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::heuman_lambda<%1%>(%1%,%1%)");86}87 88template <class T1, class T2>89BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi)90{91   return boost::math::heuman_lambda(k, phi, policies::policy<>());92}93 94}} // namespaces95 96#endif // BOOST_MATH_ELLINT_D_HPP97 98