Chris@16: // Copyright (c) 2006 Xiaogang Zhang Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_MATH_BESSEL_JY_HPP Chris@16: #define BOOST_MATH_BESSEL_JY_HPP Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // Bessel functions of the first and second kind of fractional order Chris@16: Chris@16: namespace boost { namespace math { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: // Chris@16: // Simultaneous calculation of A&S 9.2.9 and 9.2.10 Chris@16: // for use in A&S 9.2.5 and 9.2.6. Chris@16: // This series is quick to evaluate, but divergent unless Chris@16: // x is very large, in fact it's pretty hard to figure out Chris@16: // with any degree of precision when this series actually Chris@16: // *will* converge!! Consequently, we may just have to Chris@16: // try it and see... Chris@16: // Chris@16: template Chris@16: bool hankel_PQ(T v, T x, T* p, T* q, const Policy& ) Chris@16: { Chris@16: BOOST_MATH_STD_USING Chris@16: T tolerance = 2 * policies::get_epsilon(); Chris@16: *p = 1; Chris@16: *q = 0; Chris@16: T k = 1; Chris@16: T z8 = 8 * x; Chris@16: T sq = 1; Chris@16: T mu = 4 * v * v; Chris@16: T term = 1; Chris@16: bool ok = true; Chris@16: do Chris@16: { Chris@16: term *= (mu - sq * sq) / (k * z8); Chris@16: *q += term; Chris@16: k += 1; Chris@16: sq += 2; Chris@16: T mult = (sq * sq - mu) / (k * z8); Chris@16: ok = fabs(mult) < 0.5f; Chris@16: term *= mult; Chris@16: *p += term; Chris@16: k += 1; Chris@16: sq += 2; Chris@16: } Chris@16: while((fabs(term) > tolerance * *p) && ok); Chris@16: return ok; Chris@16: } Chris@16: Chris@16: // Calculate Y(v, x) and Y(v+1, x) by Temme's method, see Chris@16: // Temme, Journal of Computational Physics, vol 21, 343 (1976) Chris@16: template Chris@16: int temme_jy(T v, T x, T* Y, T* Y1, const Policy& pol) Chris@16: { Chris@16: T g, h, p, q, f, coef, sum, sum1, tolerance; Chris@16: T a, d, e, sigma; Chris@16: unsigned long k; Chris@16: Chris@16: BOOST_MATH_STD_USING Chris@16: using namespace boost::math::tools; Chris@16: using namespace boost::math::constants; Chris@16: Chris@16: BOOST_ASSERT(fabs(v) <= 0.5f); // precondition for using this routine Chris@16: Chris@16: T gp = boost::math::tgamma1pm1(v, pol); Chris@16: T gm = boost::math::tgamma1pm1(-v, pol); Chris@16: T spv = boost::math::sin_pi(v, pol); Chris@16: T spv2 = boost::math::sin_pi(v/2, pol); Chris@16: T xp = pow(x/2, v); Chris@16: Chris@16: a = log(x / 2); Chris@16: sigma = -a * v; Chris@16: d = abs(sigma) < tools::epsilon() ? Chris@16: T(1) : sinh(sigma) / sigma; Chris@16: e = abs(v) < tools::epsilon() ? T(v*pi()*pi() / 2) Chris@16: : T(2 * spv2 * spv2 / v); Chris@16: Chris@16: T g1 = (v == 0) ? T(-euler()) : T((gp - gm) / ((1 + gp) * (1 + gm) * 2 * v)); Chris@16: T g2 = (2 + gp + gm) / ((1 + gp) * (1 + gm) * 2); Chris@16: T vspv = (fabs(v) < tools::epsilon()) ? T(1/constants::pi()) : T(v / spv); Chris@16: f = (g1 * cosh(sigma) - g2 * a * d) * 2 * vspv; Chris@16: Chris@16: p = vspv / (xp * (1 + gm)); Chris@16: q = vspv * xp / (1 + gp); Chris@16: Chris@16: g = f + e * q; Chris@16: h = p; Chris@16: coef = 1; Chris@16: sum = coef * g; Chris@16: sum1 = coef * h; Chris@16: Chris@16: T v2 = v * v; Chris@16: T coef_mult = -x * x / 4; Chris@16: Chris@16: // series summation Chris@16: tolerance = policies::get_epsilon(); Chris@16: for (k = 1; k < policies::get_max_series_iterations(); k++) Chris@16: { Chris@16: f = (k * f + p + q) / (k*k - v2); Chris@16: p /= k - v; Chris@16: q /= k + v; Chris@16: g = f + e * q; Chris@16: h = p - k * g; Chris@16: coef *= coef_mult / k; Chris@16: sum += coef * g; Chris@16: sum1 += coef * h; Chris@16: if (abs(coef * g) < abs(sum) * tolerance) Chris@16: { Chris@16: break; Chris@16: } Chris@16: } Chris@16: policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in temme_jy", k, pol); Chris@16: *Y = -sum; Chris@16: *Y1 = -2 * sum1 / x; Chris@16: Chris@16: return 0; Chris@16: } Chris@16: Chris@16: // Evaluate continued fraction fv = J_(v+1) / J_v, see Chris@16: // Abramowitz and Stegun, Handbook of Mathematical Functions, 1972, 9.1.73 Chris@16: template Chris@16: int CF1_jy(T v, T x, T* fv, int* sign, const Policy& pol) Chris@16: { Chris@16: T C, D, f, a, b, delta, tiny, tolerance; Chris@16: unsigned long k; Chris@16: int s = 1; Chris@16: Chris@16: BOOST_MATH_STD_USING Chris@16: Chris@16: // |x| <= |v|, CF1_jy converges rapidly Chris@16: // |x| > |v|, CF1_jy needs O(|x|) iterations to converge Chris@16: Chris@16: // modified Lentz's method, see Chris@16: // Lentz, Applied Optics, vol 15, 668 (1976) Chris@16: tolerance = 2 * policies::get_epsilon();; Chris@16: tiny = sqrt(tools::min_value()); Chris@16: C = f = tiny; // b0 = 0, replace with tiny Chris@16: D = 0; Chris@16: for (k = 1; k < policies::get_max_series_iterations() * 100; k++) Chris@16: { Chris@16: a = -1; Chris@16: b = 2 * (v + k) / x; Chris@16: C = b + a / C; Chris@16: D = b + a * D; Chris@16: if (C == 0) { C = tiny; } Chris@16: if (D == 0) { D = tiny; } Chris@16: D = 1 / D; Chris@16: delta = C * D; Chris@16: f *= delta; Chris@16: if (D < 0) { s = -s; } Chris@16: if (abs(delta - 1) < tolerance) Chris@16: { break; } Chris@16: } Chris@16: policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in CF1_jy", k / 100, pol); Chris@16: *fv = -f; Chris@16: *sign = s; // sign of denominator Chris@16: Chris@16: return 0; Chris@16: } Chris@16: // Chris@16: // This algorithm was originally written by Xiaogang Zhang Chris@16: // using std::complex to perform the complex arithmetic. Chris@16: // However, that turns out to 10x or more slower than using Chris@16: // all real-valued arithmetic, so it's been rewritten using Chris@16: // real values only. Chris@16: // Chris@16: template Chris@16: int CF2_jy(T v, T x, T* p, T* q, const Policy& pol) Chris@16: { Chris@16: BOOST_MATH_STD_USING Chris@16: Chris@16: T Cr, Ci, Dr, Di, fr, fi, a, br, bi, delta_r, delta_i, temp; Chris@16: T tiny; Chris@16: unsigned long k; Chris@16: Chris@16: // |x| >= |v|, CF2_jy converges rapidly Chris@16: // |x| -> 0, CF2_jy fails to converge Chris@16: BOOST_ASSERT(fabs(x) > 1); Chris@16: Chris@16: // modified Lentz's method, complex numbers involved, see Chris@16: // Lentz, Applied Optics, vol 15, 668 (1976) Chris@16: T tolerance = 2 * policies::get_epsilon(); Chris@16: tiny = sqrt(tools::min_value()); Chris@16: Cr = fr = -0.5f / x; Chris@16: Ci = fi = 1; Chris@16: //Dr = Di = 0; Chris@16: T v2 = v * v; Chris@16: a = (0.25f - v2) / x; // Note complex this one time only! Chris@16: br = 2 * x; Chris@16: bi = 2; Chris@16: temp = Cr * Cr + 1; Chris@16: Ci = bi + a * Cr / temp; Chris@16: Cr = br + a / temp; Chris@16: Dr = br; Chris@16: Di = bi; Chris@16: if (fabs(Cr) + fabs(Ci) < tiny) { Cr = tiny; } Chris@16: if (fabs(Dr) + fabs(Di) < tiny) { Dr = tiny; } Chris@16: temp = Dr * Dr + Di * Di; Chris@16: Dr = Dr / temp; Chris@16: Di = -Di / temp; Chris@16: delta_r = Cr * Dr - Ci * Di; Chris@16: delta_i = Ci * Dr + Cr * Di; Chris@16: temp = fr; Chris@16: fr = temp * delta_r - fi * delta_i; Chris@16: fi = temp * delta_i + fi * delta_r; Chris@16: for (k = 2; k < policies::get_max_series_iterations(); k++) Chris@16: { Chris@16: a = k - 0.5f; Chris@16: a *= a; Chris@16: a -= v2; Chris@16: bi += 2; Chris@16: temp = Cr * Cr + Ci * Ci; Chris@16: Cr = br + a * Cr / temp; Chris@16: Ci = bi - a * Ci / temp; Chris@16: Dr = br + a * Dr; Chris@16: Di = bi + a * Di; Chris@16: if (fabs(Cr) + fabs(Ci) < tiny) { Cr = tiny; } Chris@16: if (fabs(Dr) + fabs(Di) < tiny) { Dr = tiny; } Chris@16: temp = Dr * Dr + Di * Di; Chris@16: Dr = Dr / temp; Chris@16: Di = -Di / temp; Chris@16: delta_r = Cr * Dr - Ci * Di; Chris@16: delta_i = Ci * Dr + Cr * Di; Chris@16: temp = fr; Chris@16: fr = temp * delta_r - fi * delta_i; Chris@16: fi = temp * delta_i + fi * delta_r; Chris@16: if (fabs(delta_r - 1) + fabs(delta_i) < tolerance) Chris@16: break; Chris@16: } Chris@16: policies::check_series_iterations("boost::math::bessel_jy<%1%>(%1%,%1%) in CF2_jy", k, pol); Chris@16: *p = fr; Chris@16: *q = fi; Chris@16: Chris@16: return 0; Chris@16: } Chris@16: Chris@16: static const int need_j = 1; Chris@16: static const int need_y = 2; Chris@16: Chris@16: // Compute J(v, x) and Y(v, x) simultaneously by Steed's method, see Chris@16: // Barnett et al, Computer Physics Communications, vol 8, 377 (1974) Chris@16: template Chris@16: int bessel_jy(T v, T x, T* J, T* Y, int kind, const Policy& pol) Chris@16: { Chris@16: BOOST_ASSERT(x >= 0); Chris@16: Chris@16: T u, Jv, Ju, Yv, Yv1, Yu, Yu1(0), fv, fu; Chris@16: T W, p, q, gamma, current, prev, next; Chris@16: bool reflect = false; Chris@16: unsigned n, k; Chris@16: int s; Chris@16: int org_kind = kind; Chris@16: T cp = 0; Chris@16: T sp = 0; Chris@16: Chris@16: static const char* function = "boost::math::bessel_jy<%1%>(%1%,%1%)"; Chris@16: Chris@16: BOOST_MATH_STD_USING Chris@16: using namespace boost::math::tools; Chris@16: using namespace boost::math::constants; Chris@16: Chris@16: if (v < 0) Chris@16: { Chris@16: reflect = true; Chris@16: v = -v; // v is non-negative from here Chris@16: } Chris@101: if (v > static_cast((std::numeric_limits::max)())) Chris@101: { Chris@101: *J = *Y = policies::raise_evaluation_error(function, "Order of Bessel function is too large to evaluate: got %1%", v, pol); Chris@101: return 1; Chris@101: } Chris@16: n = iround(v, pol); Chris@16: u = v - n; // -1/2 <= u < 1/2 Chris@16: Chris@16: if(reflect) Chris@16: { Chris@16: T z = (u + n % 2); Chris@16: cp = boost::math::cos_pi(z, pol); Chris@16: sp = boost::math::sin_pi(z, pol); Chris@16: if(u != 0) Chris@16: kind = need_j|need_y; // need both for reflection formula Chris@16: } Chris@16: Chris@16: if(x == 0) Chris@16: { Chris@16: if(v == 0) Chris@16: *J = 1; Chris@16: else if((u == 0) || !reflect) Chris@16: *J = 0; Chris@16: else if(kind & need_j) Chris@16: *J = policies::raise_domain_error(function, "Value of Bessel J_v(x) is complex-infinity at %1%", x, pol); // complex infinity Chris@16: else Chris@16: *J = std::numeric_limits::quiet_NaN(); // any value will do, not using J. Chris@16: Chris@16: if((kind & need_y) == 0) Chris@16: *Y = std::numeric_limits::quiet_NaN(); // any value will do, not using Y. Chris@16: else if(v == 0) Chris@16: *Y = -policies::raise_overflow_error(function, 0, pol); Chris@16: else Chris@16: *Y = policies::raise_domain_error(function, "Value of Bessel Y_v(x) is complex-infinity at %1%", x, pol); // complex infinity Chris@16: return 1; Chris@16: } Chris@16: Chris@16: // x is positive until reflection Chris@16: W = T(2) / (x * pi()); // Wronskian Chris@16: T Yv_scale = 1; Chris@16: if(((kind & need_y) == 0) && ((x < 1) || (v > x * x / 4) || (x < 5))) Chris@16: { Chris@16: // Chris@16: // This series will actually converge rapidly for all small Chris@16: // x - say up to x < 20 - but the first few terms are large Chris@16: // and divergent which leads to large errors :-( Chris@16: // Chris@16: Jv = bessel_j_small_z_series(v, x, pol); Chris@16: Yv = std::numeric_limits::quiet_NaN(); Chris@16: } Chris@16: else if((x < 1) && (u != 0) && (log(policies::get_epsilon() / 2) > v * log((x/2) * (x/2) / v))) Chris@16: { Chris@16: // Evaluate using series representations. Chris@16: // This is particularly important for x << v as in this Chris@16: // area temme_jy may be slow to converge, if it converges at all. Chris@16: // Requires x is not an integer. Chris@16: if(kind&need_j) Chris@16: Jv = bessel_j_small_z_series(v, x, pol); Chris@16: else Chris@16: Jv = std::numeric_limits::quiet_NaN(); Chris@16: if((org_kind&need_y && (!reflect || (cp != 0))) Chris@16: || (org_kind & need_j && (reflect && (sp != 0)))) Chris@16: { Chris@16: // Only calculate if we need it, and if the reflection formula will actually use it: Chris@16: Yv = bessel_y_small_z_series(v, x, &Yv_scale, pol); Chris@16: } Chris@16: else Chris@16: Yv = std::numeric_limits::quiet_NaN(); Chris@16: } Chris@16: else if((u == 0) && (x < policies::get_epsilon())) Chris@16: { Chris@16: // Truncated series evaluation for small x and v an integer, Chris@16: // much quicker in this area than temme_jy below. Chris@16: if(kind&need_j) Chris@16: Jv = bessel_j_small_z_series(v, x, pol); Chris@16: else Chris@16: Jv = std::numeric_limits::quiet_NaN(); Chris@16: if((org_kind&need_y && (!reflect || (cp != 0))) Chris@16: || (org_kind & need_j && (reflect && (sp != 0)))) Chris@16: { Chris@16: // Only calculate if we need it, and if the reflection formula will actually use it: Chris@16: Yv = bessel_yn_small_z(n, x, &Yv_scale, pol); Chris@16: } Chris@16: else Chris@16: Yv = std::numeric_limits::quiet_NaN(); Chris@16: } Chris@16: else if(asymptotic_bessel_large_x_limit(v, x)) Chris@16: { Chris@16: if(kind&need_y) Chris@16: { Chris@16: Yv = asymptotic_bessel_y_large_x_2(v, x); Chris@16: } Chris@16: else Chris@16: Yv = std::numeric_limits::quiet_NaN(); // any value will do, we're not using it. Chris@16: if(kind&need_j) Chris@16: { Chris@16: Jv = asymptotic_bessel_j_large_x_2(v, x); Chris@16: } Chris@16: else Chris@16: Jv = std::numeric_limits::quiet_NaN(); // any value will do, we're not using it. Chris@16: } Chris@16: else if((x > 8) && hankel_PQ(v, x, &p, &q, pol)) Chris@16: { Chris@16: // Chris@16: // Hankel approximation: note that this method works best when x Chris@16: // is large, but in that case we end up calculating sines and cosines Chris@16: // of large values, with horrendous resulting accuracy. It is fast though Chris@16: // when it works.... Chris@16: // Chris@16: // Normally we calculate sin/cos(chi) where: Chris@16: // Chris@16: // chi = x - fmod(T(v / 2 + 0.25f), T(2)) * boost::math::constants::pi(); Chris@16: // Chris@16: // But this introduces large errors, so use sin/cos addition formulae to Chris@16: // improve accuracy: Chris@16: // Chris@16: T mod_v = fmod(T(v / 2 + 0.25f), T(2)); Chris@16: T sx = sin(x); Chris@16: T cx = cos(x); Chris@16: T sv = sin_pi(mod_v); Chris@16: T cv = cos_pi(mod_v); Chris@16: Chris@16: T sc = sx * cv - sv * cx; // == sin(chi); Chris@16: T cc = cx * cv + sx * sv; // == cos(chi); Chris@16: T chi = boost::math::constants::root_two() / (boost::math::constants::root_pi() * sqrt(x)); //sqrt(2 / (boost::math::constants::pi() * x)); Chris@16: Yv = chi * (p * sc + q * cc); Chris@16: Jv = chi * (p * cc - q * sc); Chris@16: } Chris@16: else if (x <= 2) // x in (0, 2] Chris@16: { Chris@16: if(temme_jy(u, x, &Yu, &Yu1, pol)) // Temme series Chris@16: { Chris@16: // domain error: Chris@16: *J = *Y = Yu; Chris@16: return 1; Chris@16: } Chris@16: prev = Yu; Chris@16: current = Yu1; Chris@16: T scale = 1; Chris@16: policies::check_series_iterations(function, n, pol); Chris@16: for (k = 1; k <= n; k++) // forward recurrence for Y Chris@16: { Chris@16: T fact = 2 * (u + k) / x; Chris@16: if((tools::max_value() - fabs(prev)) / fact < fabs(current)) Chris@16: { Chris@16: scale /= current; Chris@16: prev /= current; Chris@16: current = 1; Chris@16: } Chris@16: next = fact * current - prev; Chris@16: prev = current; Chris@16: current = next; Chris@16: } Chris@16: Yv = prev; Chris@16: Yv1 = current; Chris@16: if(kind&need_j) Chris@16: { Chris@16: CF1_jy(v, x, &fv, &s, pol); // continued fraction CF1_jy Chris@16: Jv = scale * W / (Yv * fv - Yv1); // Wronskian relation Chris@16: } Chris@16: else Chris@16: Jv = std::numeric_limits::quiet_NaN(); // any value will do, we're not using it. Chris@16: Yv_scale = scale; Chris@16: } Chris@16: else // x in (2, \infty) Chris@16: { Chris@16: // Get Y(u, x): Chris@16: Chris@16: T ratio; Chris@16: CF1_jy(v, x, &fv, &s, pol); Chris@16: // tiny initial value to prevent overflow Chris@16: T init = sqrt(tools::min_value()); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(init); Chris@16: prev = fv * s * init; Chris@16: current = s * init; Chris@16: if(v < max_factorial::value) Chris@16: { Chris@16: policies::check_series_iterations(function, n, pol); Chris@16: for (k = n; k > 0; k--) // backward recurrence for J Chris@16: { Chris@16: next = 2 * (u + k) * current / x - prev; Chris@16: prev = current; Chris@16: current = next; Chris@16: } Chris@16: ratio = (s * init) / current; // scaling ratio Chris@16: // can also call CF1_jy() to get fu, not much difference in precision Chris@16: fu = prev / current; Chris@16: } Chris@16: else Chris@16: { Chris@16: // Chris@16: // When v is large we may get overflow in this calculation Chris@16: // leading to NaN's and other nasty surprises: Chris@16: // Chris@16: policies::check_series_iterations(function, n, pol); Chris@16: bool over = false; Chris@16: for (k = n; k > 0; k--) // backward recurrence for J Chris@16: { Chris@16: T t = 2 * (u + k) / x; Chris@16: if((t > 1) && (tools::max_value() / t < current)) Chris@16: { Chris@16: over = true; Chris@16: break; Chris@16: } Chris@16: next = t * current - prev; Chris@16: prev = current; Chris@16: current = next; Chris@16: } Chris@16: if(!over) Chris@16: { Chris@16: ratio = (s * init) / current; // scaling ratio Chris@16: // can also call CF1_jy() to get fu, not much difference in precision Chris@16: fu = prev / current; Chris@16: } Chris@16: else Chris@16: { Chris@16: ratio = 0; Chris@16: fu = 1; Chris@16: } Chris@16: } Chris@16: CF2_jy(u, x, &p, &q, pol); // continued fraction CF2_jy Chris@16: T t = u / x - fu; // t = J'/J Chris@16: gamma = (p - t) / q; Chris@16: // Chris@16: // We can't allow gamma to cancel out to zero competely as it messes up Chris@16: // the subsequent logic. So pretend that one bit didn't cancel out Chris@16: // and set to a suitably small value. The only test case we've been able to Chris@16: // find for this, is when v = 8.5 and x = 4*PI. Chris@16: // Chris@16: if(gamma == 0) Chris@16: { Chris@16: gamma = u * tools::epsilon() / x; Chris@16: } Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(current); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(W); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(q); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(gamma); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(p); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(t); Chris@16: Ju = sign(current) * sqrt(W / (q + gamma * (p - t))); Chris@101: BOOST_MATH_INSTRUMENT_VARIABLE(Ju); Chris@16: Chris@16: Jv = Ju * ratio; // normalization Chris@16: Chris@16: Yu = gamma * Ju; Chris@16: Yu1 = Yu * (u/x - p - q/gamma); Chris@16: Chris@16: if(kind&need_y) Chris@16: { Chris@16: // compute Y: Chris@16: prev = Yu; Chris@16: current = Yu1; Chris@16: policies::check_series_iterations(function, n, pol); Chris@16: for (k = 1; k <= n; k++) // forward recurrence for Y Chris@16: { Chris@16: T fact = 2 * (u + k) / x; Chris@16: if((tools::max_value() - fabs(prev)) / fact < fabs(current)) Chris@16: { Chris@16: prev /= current; Chris@16: Yv_scale /= current; Chris@16: current = 1; Chris@16: } Chris@16: next = fact * current - prev; Chris@16: prev = current; Chris@16: current = next; Chris@16: } Chris@16: Yv = prev; Chris@16: } Chris@16: else Chris@16: Yv = std::numeric_limits::quiet_NaN(); // any value will do, we're not using it. Chris@16: } Chris@16: Chris@16: if (reflect) Chris@16: { Chris@16: if((sp != 0) && (tools::max_value() * fabs(Yv_scale) < fabs(sp * Yv))) Chris@16: *J = org_kind & need_j ? T(-sign(sp) * sign(Yv) * sign(Yv_scale) * policies::raise_overflow_error(function, 0, pol)) : T(0); Chris@16: else Chris@16: *J = cp * Jv - (sp == 0 ? T(0) : T((sp * Yv) / Yv_scale)); // reflection formula Chris@16: if((cp != 0) && (tools::max_value() * fabs(Yv_scale) < fabs(cp * Yv))) Chris@16: *Y = org_kind & need_y ? T(-sign(cp) * sign(Yv) * sign(Yv_scale) * policies::raise_overflow_error(function, 0, pol)) : T(0); Chris@16: else Chris@16: *Y = (sp != 0 ? sp * Jv : T(0)) + (cp == 0 ? T(0) : T((cp * Yv) / Yv_scale)); Chris@16: } Chris@16: else Chris@16: { Chris@16: *J = Jv; Chris@16: if(tools::max_value() * fabs(Yv_scale) < fabs(Yv)) Chris@16: *Y = org_kind & need_y ? T(sign(Yv) * sign(Yv_scale) * policies::raise_overflow_error(function, 0, pol)) : T(0); Chris@16: else Chris@16: *Y = Yv / Yv_scale; Chris@16: } Chris@16: Chris@16: return 0; Chris@16: } Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: }} // namespaces Chris@16: Chris@16: #endif // BOOST_MATH_BESSEL_JY_HPP Chris@16: