Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:37:15

0001 //  Copyright (c) 2006 Xiaogang Zhang
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 #ifndef BOOST_MATH_BESSEL_JY_HPP
0007 #define BOOST_MATH_BESSEL_JY_HPP
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/math/tools/config.hpp>
0014 #include <boost/math/special_functions/gamma.hpp>
0015 #include <boost/math/special_functions/sign.hpp>
0016 #include <boost/math/special_functions/hypot.hpp>
0017 #include <boost/math/special_functions/sin_pi.hpp>
0018 #include <boost/math/special_functions/cos_pi.hpp>
0019 #include <boost/math/special_functions/detail/bessel_jy_asym.hpp>
0020 #include <boost/math/special_functions/detail/bessel_jy_series.hpp>
0021 #include <boost/math/constants/constants.hpp>
0022 #include <boost/math/policies/error_handling.hpp>
0023 #include <complex>
0024 
0025 // Bessel functions of the first and second kind of fractional order
0026 
0027 namespace boost { namespace math {
0028 
0029    namespace detail {
0030 
0031       //
0032       // Simultaneous calculation of A&S 9.2.9 and 9.2.10
0033       // for use in A&S 9.2.5 and 9.2.6.
0034       // This series is quick to evaluate, but divergent unless
0035       // x is very large, in fact it's pretty hard to figure out
0036       // with any degree of precision when this series actually
0037       // *will* converge!!  Consequently, we may just have to
0038       // try it and see...
0039       //
0040       template <class T, class Policy>
0041       bool hankel_PQ(T v, T x, T* p, T* q, const Policy& )
0042       {
0043          BOOST_MATH_STD_USING
0044             T tolerance = 2 * policies::get_epsilon<T, Policy>();
0045          *p = 1;
0046          *q = 0;
0047          T k = 1;
0048          T z8 = 8 * x;
0049          T sq = 1;
0050          T mu = 4 * v * v;
0051          T term = 1;
0052          bool ok = true;
0053          do
0054          {
0055             term *= (mu - sq * sq) / (k * z8);
0056             *q += term;
0057             k += 1;
0058             sq += 2;
0059             T mult = (sq * sq - mu) / (k * z8);
0060             ok = fabs(mult) < 0.5f;
0061             term *= mult;
0062             *p += term;
0063             k += 1;
0064             sq += 2;
0065          }
0066          while((fabs(term) > tolerance * *p) && ok);
0067          return ok;
0068       }
0069 
0070       // Calculate Y(v, x) and Y(v+1, x) by Temme's method, see
0071       // Temme, Journal of Computational Physics, vol 21, 343 (1976)
0072       template <typename T, typename Policy>
0073       int temme_jy(T v, T x, T* Y, T* Y1, const Policy& pol)
0074       {
0075          T g, h, p, q, f, coef, sum, sum1, tolerance;
0076          T a, d, e, sigma;
0077          unsigned long k;
0078 
0079          BOOST_MATH_STD_USING
0080             using namespace boost::math::tools;
0081          using namespace boost::math::constants;
0082 
0083          BOOST_MATH_ASSERT(fabs(v) <= 0.5f);  // precondition for using this routine
0084 
0085          T gp = boost::math::tgamma1pm1(v, pol);
0086          T gm = boost::math::tgamma1pm1(-v, pol);
0087          T spv = boost::math::sin_pi(v, pol);
0088          T spv2 = boost::math::sin_pi(v/2, pol);
0089          T xp = pow(x/2, v);
0090 
0091          a = log(x / 2);
0092          sigma = -a * v;
0093          d = abs(sigma) < tools::epsilon<T>() ?
0094             T(1) : sinh(sigma) / sigma;
0095          e = abs(v) < tools::epsilon<T>() ? T(v*pi<T>()*pi<T>() / 2)
0096             : T(2 * spv2 * spv2 / v);
0097 
0098          T g1 = (v == 0) ? T(-euler<T>()) : T((gp - gm) / ((1 + gp) * (1 + gm) * 2 * v));
0099          T g2 = (2 + gp + gm) / ((1 + gp) * (1 + gm) * 2);
0100          T vspv = (fabs(v) < tools::epsilon<T>()) ? T(1/constants::pi<T>()) : T(v / spv);
0101          f = (g1 * cosh(sigma) - g2 * a * d) * 2 * vspv;
0102 
0103          p = vspv / (xp * (1 + gm));
0104          q = vspv * xp / (1 + gp);
0105 
0106          g = f + e * q;
0107          h = p;
0108          coef = 1;
0109          sum = coef * g;
0110          sum1 = coef * h;
0111 
0112          T v2 = v * v;
0113          T coef_mult = -x * x / 4;
0114 
0115          // series summation
0116          tolerance = policies::get_epsilon<T, Policy>();
0117          for (k = 1; k < policies::get_max_series_iterations<Policy>(); k++)
0118          {
0119             f = (k * f + p + q) / (k*k - v2);
0120             p /= k - v;
0121             q /= k + v;
0122             g = f + e * q;
0123             h = p - k * g;
0124             coef *= coef_mult / k;
0125             sum += coef * g;
0126             sum1 += coef * h;
0127             if (abs(coef * g) < abs(sum) * tolerance)
0128             {
0129                break;
0130             }
0131          }
0132          policies::check_series_iterations<T>("boost::math::bessel_jy<%1%>(%1%,%1%) in temme_jy", k, pol);
0133          *Y = -sum;
0134          *Y1 = -2 * sum1 / x;
0135 
0136          return 0;
0137       }
0138 
0139       // Evaluate continued fraction fv = J_(v+1) / J_v, see
0140       // Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73
0141       template <typename T, typename Policy>
0142       int CF1_jy(T v, T x, T* fv, int* sign, const Policy& pol)
0143       {
0144          T C, D, f, a, b, delta, tiny, tolerance;
0145          unsigned long k;
0146          int s = 1;
0147 
0148          BOOST_MATH_STD_USING
0149 
0150             // |x| <= |v|, CF1_jy converges rapidly
0151             // |x| > |v|, CF1_jy needs O(|x|) iterations to converge
0152 
0153             // modified Lentz's method, see
0154             // Lentz, Applied Optics, vol 15, 668 (1976)
0155             tolerance = 2 * policies::get_epsilon<T, Policy>();
0156          tiny = sqrt(tools::min_value<T>());
0157          C = f = tiny;                           // b0 = 0, replace with tiny
0158          D = 0;
0159          for (k = 1; k < policies::get_max_series_iterations<Policy>() * 100; k++)
0160          {
0161             a = -1;
0162             b = 2 * (v + k) / x;
0163             C = b + a / C;
0164             D = b + a * D;
0165             if (C == 0) { C = tiny; }
0166             if (D == 0) { D = tiny; }
0167             D = 1 / D;
0168             delta = C * D;
0169             f *= delta;
0170             if (D < 0) { s = -s; }
0171             if (abs(delta - 1) < tolerance)
0172             { break; }
0173          }
0174          policies::check_series_iterations<T>("boost::math::bessel_jy<%1%>(%1%,%1%) in CF1_jy", k / 100, pol);
0175          *fv = -f;
0176          *sign = s;                              // sign of denominator
0177 
0178          return 0;
0179       }
0180       //
0181       // This algorithm was originally written by Xiaogang Zhang
0182       // using std::complex to perform the complex arithmetic.
0183       // However, that turns out to 10x or more slower than using
0184       // all real-valued arithmetic, so it's been rewritten using
0185       // real values only.
0186       //
0187       template <typename T, typename Policy>
0188       int CF2_jy(T v, T x, T* p, T* q, const Policy& pol)
0189       {
0190          BOOST_MATH_STD_USING
0191 
0192             T Cr, Ci, Dr, Di, fr, fi, a, br, bi, delta_r, delta_i, temp;
0193          T tiny;
0194          unsigned long k;
0195 
0196          // |x| >= |v|, CF2_jy converges rapidly
0197          // |x| -> 0, CF2_jy fails to converge
0198          BOOST_MATH_ASSERT(fabs(x) > 1);
0199 
0200          // modified Lentz's method, complex numbers involved, see
0201          // Lentz, Applied Optics, vol 15, 668 (1976)
0202          T tolerance = 2 * policies::get_epsilon<T, Policy>();
0203          tiny = sqrt(tools::min_value<T>());
0204          Cr = fr = -0.5f / x;
0205          Ci = fi = 1;
0206          //Dr = Di = 0;
0207          T v2 = v * v;
0208          a = (0.25f - v2) / x; // Note complex this one time only!
0209          br = 2 * x;
0210          bi = 2;
0211          temp = Cr * Cr + 1;
0212          Ci = bi + a * Cr / temp;
0213          Cr = br + a / temp;
0214          Dr = br;
0215          Di = bi;
0216          if (fabs(Cr) + fabs(Ci) < tiny) { Cr = tiny; }
0217          if (fabs(Dr) + fabs(Di) < tiny) { Dr = tiny; }
0218          temp = Dr * Dr + Di * Di;
0219          Dr = Dr / temp;
0220          Di = -Di / temp;
0221          delta_r = Cr * Dr - Ci * Di;
0222          delta_i = Ci * Dr + Cr * Di;
0223          temp = fr;
0224          fr = temp * delta_r - fi * delta_i;
0225          fi = temp * delta_i + fi * delta_r;
0226          for (k = 2; k < policies::get_max_series_iterations<Policy>(); k++)
0227          {
0228             a = k - 0.5f;
0229             a *= a;
0230             a -= v2;
0231             bi += 2;
0232             temp = Cr * Cr + Ci * Ci;
0233             Cr = br + a * Cr / temp;
0234             Ci = bi - a * Ci / temp;
0235             Dr = br + a * Dr;
0236             Di = bi + a * Di;
0237             if (fabs(Cr) + fabs(Ci) < tiny) { Cr = tiny; }
0238             if (fabs(Dr) + fabs(Di) < tiny) { Dr = tiny; }
0239             temp = Dr * Dr + Di * Di;
0240             Dr = Dr / temp;
0241             Di = -Di / temp;
0242             delta_r = Cr * Dr - Ci * Di;
0243             delta_i = Ci * Dr + Cr * Di;
0244             temp = fr;
0245             fr = temp * delta_r - fi * delta_i;
0246             fi = temp * delta_i + fi * delta_r;
0247             if (fabs(delta_r - 1) + fabs(delta_i) < tolerance)
0248                break;
0249          }
0250          policies::check_series_iterations<T>("boost::math::bessel_jy<%1%>(%1%,%1%) in CF2_jy", k, pol);
0251          *p = fr;
0252          *q = fi;
0253 
0254          return 0;
0255       }
0256 
0257       static const int need_j = 1;
0258       static const int need_y = 2;
0259 
0260       // Compute J(v, x) and Y(v, x) simultaneously by Steed's method, see
0261       // Barnett et al, Computer Physics Communications, vol 8, 377 (1974)
0262       template <typename T, typename Policy>
0263       int bessel_jy(T v, T x, T* J, T* Y, int kind, const Policy& pol)
0264       {
0265          BOOST_MATH_ASSERT(x >= 0);
0266 
0267          T u, Jv, Ju, Yv, Yv1, Yu, Yu1(0), fv, fu;
0268          T W, p, q, gamma, current, prev, next;
0269          bool reflect = false;
0270          unsigned n, k;
0271          int s;
0272          int org_kind = kind;
0273          T cp = 0;
0274          T sp = 0;
0275 
0276          static const char* function = "boost::math::bessel_jy<%1%>(%1%,%1%)";
0277 
0278          BOOST_MATH_STD_USING
0279             using namespace boost::math::tools;
0280          using namespace boost::math::constants;
0281 
0282          if (v < 0)
0283          {
0284             reflect = true;
0285             v = -v;                             // v is non-negative from here
0286          }
0287          if (v > static_cast<T>((std::numeric_limits<int>::max)()))
0288          {
0289             *J = *Y = policies::raise_evaluation_error<T>(function, "Order of Bessel function is too large to evaluate: got %1%", v, pol);
0290             return 1;  // LCOV_EXCL_LINE previous line will throw.
0291          }
0292          n = iround(v, pol);
0293          u = v - n;                              // -1/2 <= u < 1/2
0294 
0295          if(reflect)
0296          {
0297             T z = (u + n % 2);
0298             cp = boost::math::cos_pi(z, pol);
0299             sp = boost::math::sin_pi(z, pol);
0300             if(u != 0)
0301                kind = need_j|need_y;               // need both for reflection formula
0302          }
0303 
0304          if(x == 0)
0305          {
0306             if (v == 0)
0307                *J = 1; // LCOV_EXCL_LINE multiprecision case only
0308             else if ((u == 0) || !reflect)
0309                *J = 0;
0310             else if(kind & need_j)
0311                *J = policies::raise_domain_error<T>(function, "Value of Bessel J_v(x) is complex-infinity at %1%", x, pol); // complex infinity
0312             else
0313                *J = std::numeric_limits<T>::quiet_NaN();  // LCOV_EXCL_LINE, we should never get here, any value will do, not using J.
0314 
0315             if((kind & need_y) == 0)
0316                *Y = std::numeric_limits<T>::quiet_NaN();  // any value will do, not using Y.
0317             else
0318             {
0319                // We shoud never get here:
0320                BOOST_MATH_ASSERT(x != 0); // LCOV_EXCL_LINE
0321             }
0322             return 1;
0323          }
0324 
0325          // x is positive until reflection
0326          W = T(2) / (x * pi<T>());               // Wronskian
0327          T Yv_scale = 1;
0328          if(((kind & need_y) == 0) && ((x < 1) || (v > x * x / 4) || (x < 5)))
0329          {
0330             //
0331             // This series will actually converge rapidly for all small
0332             // x - say up to x < 20 - but the first few terms are large
0333             // and divergent which leads to large errors :-(
0334             //
0335             Jv = bessel_j_small_z_series(v, x, pol);
0336             Yv = std::numeric_limits<T>::quiet_NaN();
0337          }
0338          else if((x < 1) && (u != 0) && (log(policies::get_epsilon<T, Policy>() / 2) > v * log((x/2) * (x/2) / v)))
0339          {
0340             // Evaluate using series representations.
0341             // This is particularly important for x << v as in this
0342             // area temme_jy may be slow to converge, if it converges at all.
0343             // Requires x is not an integer.
0344             if(kind&need_j)
0345                Jv = bessel_j_small_z_series(v, x, pol);
0346             else
0347                Jv = std::numeric_limits<T>::quiet_NaN();
0348             if((org_kind&need_y && (!reflect || (cp != 0)))
0349                || (org_kind & need_j && (reflect && (sp != 0))))
0350             {
0351                // Only calculate if we need it, and if the reflection formula will actually use it:
0352                Yv = bessel_y_small_z_series(v, x, &Yv_scale, pol);
0353             }
0354             else
0355                Yv = std::numeric_limits<T>::quiet_NaN();
0356          }
0357          else if((u == 0) && (x < policies::get_epsilon<T, Policy>()))
0358          {
0359             // Truncated series evaluation for small x and v an integer,
0360             // much quicker in this area than temme_jy below.
0361             // This code is only used in the multiprecision case, otherwise
0362             // we go via bessel_jn.  LCOV_EXCL_START
0363             if(kind&need_j)
0364                Jv = bessel_j_small_z_series(v, x, pol);
0365             else
0366                Jv = std::numeric_limits<T>::quiet_NaN();
0367             if((org_kind&need_y && (!reflect || (cp != 0)))
0368                || (org_kind & need_j && (reflect && (sp != 0))))
0369             {
0370                // Only calculate if we need it, and if the reflection formula will actually use it:
0371                Yv = bessel_yn_small_z(n, x, &Yv_scale, pol);
0372             }
0373             else
0374                Yv = std::numeric_limits<T>::quiet_NaN();
0375             // LCOV_EXCL_STOP
0376          }
0377          else if(asymptotic_bessel_large_x_limit(v, x))
0378          {
0379             if(kind&need_y)
0380             {
0381                Yv = asymptotic_bessel_y_large_x_2(v, x, pol);
0382             }
0383             else
0384                Yv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it.
0385             if(kind&need_j)
0386             {
0387                Jv = asymptotic_bessel_j_large_x_2(v, x, pol);
0388             }
0389             else
0390                Jv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it.
0391          }
0392          else if((x > 8) && hankel_PQ(v, x, &p, &q, pol))
0393          {
0394             //
0395             // Hankel approximation: note that this method works best when x
0396             // is large, but in that case we end up calculating sines and cosines
0397             // of large values, with horrendous resulting accuracy.  It is fast though
0398             // when it works....
0399             //
0400             // Normally we calculate sin/cos(chi) where:
0401             //
0402             // chi = x - fmod(T(v / 2 + 0.25f), T(2)) * boost::math::constants::pi<T>();
0403             //
0404             // But this introduces large errors, so use sin/cos addition formulae to
0405             // improve accuracy:
0406             //
0407             T mod_v = fmod(T(v / 2 + 0.25f), T(2));
0408             T sx = sin(x);
0409             T cx = cos(x);
0410             T sv = boost::math::sin_pi(mod_v, pol);
0411             T cv = boost::math::cos_pi(mod_v, pol);
0412 
0413             T sc = sx * cv - sv * cx; // == sin(chi);
0414             T cc = cx * cv + sx * sv; // == cos(chi);
0415             T chi = boost::math::constants::root_two<T>() / (boost::math::constants::root_pi<T>() * sqrt(x)); //sqrt(2 / (boost::math::constants::pi<T>() * x));
0416             Yv = chi * (p * sc + q * cc);
0417             Jv = chi * (p * cc - q * sc);
0418          }
0419          else if (x <= 2)                           // x in (0, 2]
0420          {
0421             if(temme_jy(u, x, &Yu, &Yu1, pol))             // Temme series
0422             {
0423                // domain error, this should really have already been handled.
0424                *J = *Y = Yu; // LCOV_EXCL_LINE
0425                return 1;     // LCOV_EXCL_LINE
0426             }
0427             prev = Yu;
0428             current = Yu1;
0429             T scale = 1;
0430             policies::check_series_iterations<T>(function, n, pol);
0431             for (k = 1; k <= n; k++)            // forward recurrence for Y
0432             {
0433                T fact = 2 * (u + k) / x;
0434                if((tools::max_value<T>() - fabs(prev)) / fact < fabs(current))
0435                {
0436                   scale /= current;
0437                   prev /= current;
0438                   current = 1;
0439                }
0440                next = fact * current - prev;
0441                prev = current;
0442                current = next;
0443             }
0444             Yv = prev;
0445             Yv1 = current;
0446             if(kind&need_j)
0447             {
0448                CF1_jy(v, x, &fv, &s, pol);                 // continued fraction CF1_jy
0449                Jv = scale * W / (Yv * fv - Yv1);           // Wronskian relation
0450             }
0451             else
0452                Jv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it.
0453             Yv_scale = scale;
0454          }
0455          else                                    // x in (2, \infty)
0456          {
0457             // Get Y(u, x):
0458 
0459             T ratio;
0460             CF1_jy(v, x, &fv, &s, pol);
0461             // tiny initial value to prevent overflow
0462             T init = sqrt(tools::min_value<T>());
0463             BOOST_MATH_INSTRUMENT_VARIABLE(init);
0464             prev = fv * s * init;
0465             current = s * init;
0466             if(v < max_factorial<T>::value)
0467             {
0468                policies::check_series_iterations<T>(function, n, pol);
0469                for (k = n; k > 0; k--)             // backward recurrence for J
0470                {
0471                   next = 2 * (u + k) * current / x - prev;
0472                   //
0473                   // We can't allow next to completely cancel out or the subsequent logic breaks.
0474                   // Pretend that one bit did not cancel:
0475                   if (next == 0)
0476                   {
0477                      next = prev * tools::epsilon<T>() / 2;  // LCOV_EXCL_LINE requires specific hardware and rounding to trigger, does get tested on msvc
0478                   }
0479                   prev = current;
0480                   current = next;
0481                }
0482                ratio = (s * init) / current;     // scaling ratio
0483                // can also call CF1_jy() to get fu, not much difference in precision
0484                fu = prev / current;
0485             }
0486             else
0487             {
0488                //
0489                // When v is large we may get overflow in this calculation
0490                // leading to NaN's and other nasty surprises:
0491                //
0492                policies::check_series_iterations<T>(function, n, pol);
0493                bool over = false;
0494                for (k = n; k > 0; k--)             // backward recurrence for J
0495                {
0496                   T t = 2 * (u + k) / x;
0497                   if((t > 1) && (tools::max_value<T>() / t < current))
0498                   {
0499                      over = true;
0500                      break;
0501                   }
0502                   next = t * current - prev;
0503                   prev = current;
0504                   current = next;
0505                }
0506                if(!over)
0507                {
0508                   ratio = (s * init) / current;     // scaling ratio
0509                   // can also call CF1_jy() to get fu, not much difference in precision
0510                   fu = prev / current;
0511                }
0512                else
0513                {
0514                   ratio = 0;
0515                   fu = 1;
0516                }
0517             }
0518             CF2_jy(u, x, &p, &q, pol);                  // continued fraction CF2_jy
0519             T t = u / x - fu;                   // t = J'/J
0520             gamma = (p - t) / q;
0521             //
0522             // We can't allow gamma to cancel out to zero completely as it messes up
0523             // the subsequent logic.  So pretend that one bit didn't cancel out
0524             // and set to a suitably small value.  The only test case we've been able to
0525             // find for this, is when v = 8.5 and x = 4*PI.
0526             //
0527             if(gamma == 0)
0528             {
0529                gamma = u * tools::epsilon<T>() / x;  // LCOV_EXCL_LINE requires specific hardware and rounding to trigger, does get tested on msvc
0530             }
0531             BOOST_MATH_INSTRUMENT_VARIABLE(current);
0532             BOOST_MATH_INSTRUMENT_VARIABLE(W);
0533             BOOST_MATH_INSTRUMENT_VARIABLE(q);
0534             BOOST_MATH_INSTRUMENT_VARIABLE(gamma);
0535             BOOST_MATH_INSTRUMENT_VARIABLE(p);
0536             BOOST_MATH_INSTRUMENT_VARIABLE(t);
0537             Ju = sign(current) * sqrt(W / (q + gamma * (p - t)));
0538             BOOST_MATH_INSTRUMENT_VARIABLE(Ju);
0539 
0540             Jv = Ju * ratio;                    // normalization
0541 
0542             Yu = gamma * Ju;
0543             Yu1 = Yu * (u/x - p - q/gamma);
0544 
0545             if(kind&need_y)
0546             {
0547                // compute Y:
0548                prev = Yu;
0549                current = Yu1;
0550                policies::check_series_iterations<T>(function, n, pol);
0551                for (k = 1; k <= n; k++)            // forward recurrence for Y
0552                {
0553                   T fact = 2 * (u + k) / x;
0554                   if((tools::max_value<T>() - fabs(prev)) / fact < fabs(current))
0555                   {
0556                      prev /= current;
0557                      Yv_scale /= current;
0558                      current = 1;
0559                   }
0560                   next = fact * current - prev;
0561                   prev = current;
0562                   current = next;
0563                }
0564                Yv = prev;
0565             }
0566             else
0567                Yv = std::numeric_limits<T>::quiet_NaN(); // any value will do, we're not using it.
0568          }
0569 
0570          if (reflect)
0571          {
0572             if((sp != 0) && (tools::max_value<T>() * fabs(Yv_scale) < fabs(sp * Yv)))
0573                *J = org_kind & need_j ? T(-sign(sp) * sign(Yv) * (Yv_scale != 0 ? sign(Yv_scale) : 1) * policies::raise_overflow_error<T>(function, nullptr, pol)) : T(0);
0574             else
0575                *J = cp * Jv - (sp == 0 ? T(0) : T((sp * Yv) / Yv_scale));     // reflection formula
0576             if((cp != 0) && (tools::max_value<T>() * fabs(Yv_scale) < fabs(cp * Yv)))
0577                *Y = org_kind & need_y ? T(-sign(cp) * sign(Yv) * (Yv_scale != 0 ? sign(Yv_scale) : 1) * policies::raise_overflow_error<T>(function, nullptr, pol)) : T(0);
0578             else
0579                *Y = (sp != 0 ? sp * Jv : T(0)) + (cp == 0 ? T(0) : T((cp * Yv) / Yv_scale));
0580          }
0581          else
0582          {
0583             *J = Jv;
0584             if(tools::max_value<T>() * fabs(Yv_scale) < fabs(Yv))
0585                *Y = org_kind & need_y ? T(sign(Yv) * sign(Yv_scale) * policies::raise_overflow_error<T>(function, nullptr, pol)) : T(0);
0586             else
0587                *Y = Yv / Yv_scale;
0588          }
0589 
0590          return 0;
0591       }
0592 
0593    } // namespace detail
0594 
0595 }} // namespaces
0596 
0597 #endif // BOOST_MATH_BESSEL_JY_HPP