brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 8b6f809 Raw
84 lines · plain
1//  Copyright (c) 2015 John Maddock2//  Use, modification and distribution are subject to the3//  Boost Software License, Version 1.0. (See accompanying file4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5//6 7#ifndef BOOST_MATH_ELLINT_JZ_HPP8#define BOOST_MATH_ELLINT_JZ_HPP9 10#ifdef _MSC_VER11#pragma once12#endif13 14#include <boost/math/tools/config.hpp>15#include <boost/math/tools/promotion.hpp>16#include <boost/math/special_functions/math_fwd.hpp>17#include <boost/math/special_functions/ellint_1.hpp>18#include <boost/math/special_functions/ellint_rj.hpp>19#include <boost/math/special_functions/sign.hpp>20#include <boost/math/constants/constants.hpp>21#include <boost/math/policies/error_handling.hpp>22#include <boost/math/tools/workaround.hpp>23 24// Elliptic integral the Jacobi Zeta function.25 26namespace boost { namespace math { 27   28namespace detail{29 30// Elliptic integral - Jacobi Zeta31template <typename T, typename Policy>32BOOST_MATH_GPU_ENABLED T jacobi_zeta_imp(T phi, T k, const Policy& pol, T kp)33{34    BOOST_MATH_STD_USING35    using namespace boost::math::tools;36    using namespace boost::math::constants;37 38    bool invert = false;39    if(phi < 0)40    {41       phi = fabs(phi);42       invert = true;43    }44 45    T result;46    T sinp = sin(phi);47    T cosp = cos(phi);48    T c2 = cosp * cosp;49    T one_minus_ks2 = kp + c2 - kp * c2;50    T k2 = k * k;51    if(k == 1)52       result = sinp * (boost::math::sign)(cosp);  // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.53    else54    {55       result = k2 * sinp * cosp * sqrt(one_minus_ks2) * ellint_rj_imp(T(0), kp, T(1), one_minus_ks2, pol) / (3 * ellint_k_imp(k, pol, kp));56    }57    return invert ? T(-result) : result;58}59template <typename T, typename Policy>60BOOST_MATH_GPU_ENABLED inline T jacobi_zeta_imp(T phi, T k, const Policy& pol)61{62   return jacobi_zeta_imp(phi, k, pol, T(1 - k * k));63}64} // detail65 66template <class T1, class T2, class Policy>67BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)68{69   typedef typename tools::promote_args<T1, T2>::type result_type;70   typedef typename policies::evaluation<result_type, Policy>::type value_type;71   return policies::checked_narrowing_cast<result_type, Policy>(detail::jacobi_zeta_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::jacobi_zeta<%1%>(%1%,%1%)");72}73 74template <class T1, class T2>75BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)76{77   return boost::math::jacobi_zeta(k, phi, policies::policy<>());78}79 80}} // namespaces81 82#endif // BOOST_MATH_ELLINT_D_HPP83 84