1*84d9c625SLionel Sambuc /* $NetBSD: n_j0.c,v 1.7 2011/11/02 02:34:56 christos Exp $ */
22fe8fb19SBen Gras /*-
32fe8fb19SBen Gras * Copyright (c) 1992, 1993
42fe8fb19SBen Gras * The Regents of the University of California. All rights reserved.
52fe8fb19SBen Gras *
62fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras * modification, are permitted provided that the following conditions
82fe8fb19SBen Gras * are met:
92fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras * documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors
152fe8fb19SBen Gras * may be used to endorse or promote products derived from this software
162fe8fb19SBen Gras * without specific prior written permission.
172fe8fb19SBen Gras *
182fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
192fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
222fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
282fe8fb19SBen Gras * SUCH DAMAGE.
292fe8fb19SBen Gras */
302fe8fb19SBen Gras
312fe8fb19SBen Gras #ifndef lint
322fe8fb19SBen Gras #if 0
332fe8fb19SBen Gras static char sccsid[] = "@(#)j0.c 8.2 (Berkeley) 11/30/93";
342fe8fb19SBen Gras #endif
352fe8fb19SBen Gras #endif /* not lint */
362fe8fb19SBen Gras
372fe8fb19SBen Gras /*
382fe8fb19SBen Gras * 16 December 1992
392fe8fb19SBen Gras * Minor modifications by Peter McIlroy to adapt non-IEEE architecture.
402fe8fb19SBen Gras */
412fe8fb19SBen Gras
422fe8fb19SBen Gras /*
432fe8fb19SBen Gras * ====================================================
442fe8fb19SBen Gras * Copyright (C) 1992 by Sun Microsystems, Inc.
452fe8fb19SBen Gras *
462fe8fb19SBen Gras * Developed at SunPro, a Sun Microsystems, Inc. business.
472fe8fb19SBen Gras * Permission to use, copy, modify, and distribute this
482fe8fb19SBen Gras * software is freely granted, provided that this notice
492fe8fb19SBen Gras * is preserved.
502fe8fb19SBen Gras * ====================================================
512fe8fb19SBen Gras *
522fe8fb19SBen Gras * ******************* WARNING ********************
532fe8fb19SBen Gras * This is an alpha version of SunPro's FDLIBM (Freely
542fe8fb19SBen Gras * Distributable Math Library) for IEEE double precision
552fe8fb19SBen Gras * arithmetic. FDLIBM is a basic math library written
562fe8fb19SBen Gras * in C that runs on machines that conform to IEEE
572fe8fb19SBen Gras * Standard 754/854. This alpha version is distributed
582fe8fb19SBen Gras * for testing purpose. Those who use this software
592fe8fb19SBen Gras * should report any bugs to
602fe8fb19SBen Gras *
612fe8fb19SBen Gras * fdlibm-comments@sunpro.eng.sun.com
622fe8fb19SBen Gras *
632fe8fb19SBen Gras * -- K.C. Ng, Oct 12, 1992
642fe8fb19SBen Gras * ************************************************
652fe8fb19SBen Gras */
662fe8fb19SBen Gras
672fe8fb19SBen Gras /* double j0(double x), y0(double x)
682fe8fb19SBen Gras * Bessel function of the first and second kinds of order zero.
692fe8fb19SBen Gras * Method -- j0(x):
702fe8fb19SBen Gras * 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
712fe8fb19SBen Gras * 2. Reduce x to |x| since j0(x)=j0(-x), and
722fe8fb19SBen Gras * for x in (0,2)
732fe8fb19SBen Gras * j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x;
742fe8fb19SBen Gras * (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
752fe8fb19SBen Gras * for x in (2,inf)
762fe8fb19SBen Gras * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
772fe8fb19SBen Gras * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
782fe8fb19SBen Gras * as follow:
792fe8fb19SBen Gras * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
802fe8fb19SBen Gras * = 1/sqrt(2) * (cos(x) + sin(x))
812fe8fb19SBen Gras * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
822fe8fb19SBen Gras * = 1/sqrt(2) * (sin(x) - cos(x))
832fe8fb19SBen Gras * (To avoid cancellation, use
842fe8fb19SBen Gras * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
852fe8fb19SBen Gras * to compute the worse one.)
862fe8fb19SBen Gras *
872fe8fb19SBen Gras * 3 Special cases
882fe8fb19SBen Gras * j0(nan)= nan
892fe8fb19SBen Gras * j0(0) = 1
902fe8fb19SBen Gras * j0(inf) = 0
912fe8fb19SBen Gras *
922fe8fb19SBen Gras * Method -- y0(x):
932fe8fb19SBen Gras * 1. For x<2.
942fe8fb19SBen Gras * Since
952fe8fb19SBen Gras * y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
962fe8fb19SBen Gras * therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
972fe8fb19SBen Gras * We use the following function to approximate y0,
982fe8fb19SBen Gras * y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
992fe8fb19SBen Gras * where
1002fe8fb19SBen Gras * U(z) = u0 + u1*z + ... + u6*z^6
1012fe8fb19SBen Gras * V(z) = 1 + v1*z + ... + v4*z^4
1022fe8fb19SBen Gras * with absolute approximation error bounded by 2**-72.
1032fe8fb19SBen Gras * Note: For tiny x, U/V = u0 and j0(x)~1, hence
1042fe8fb19SBen Gras * y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
1052fe8fb19SBen Gras * 2. For x>=2.
1062fe8fb19SBen Gras * y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
1072fe8fb19SBen Gras * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
1082fe8fb19SBen Gras * by the method mentioned above.
1092fe8fb19SBen Gras * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
1102fe8fb19SBen Gras */
1112fe8fb19SBen Gras
1122fe8fb19SBen Gras #include "mathimpl.h"
1132fe8fb19SBen Gras #include <float.h>
1142fe8fb19SBen Gras #include <errno.h>
1152fe8fb19SBen Gras
1162fe8fb19SBen Gras #if defined(__vax__) || defined(tahoe)
1172fe8fb19SBen Gras #define _IEEE 0
1182fe8fb19SBen Gras #else
1192fe8fb19SBen Gras #define _IEEE 1
1202fe8fb19SBen Gras #define infnan(x) (0.0)
1212fe8fb19SBen Gras #endif
1222fe8fb19SBen Gras
1232fe8fb19SBen Gras static double pzero (double), qzero (double);
1242fe8fb19SBen Gras
1252fe8fb19SBen Gras static const double
126*84d9c625SLionel Sambuc huge = _HUGE,
1272fe8fb19SBen Gras zero = 0.0,
1282fe8fb19SBen Gras one = 1.0,
1292fe8fb19SBen Gras invsqrtpi= 5.641895835477562869480794515607725858441e-0001,
1302fe8fb19SBen Gras tpi = 0.636619772367581343075535053490057448,
1312fe8fb19SBen Gras /* R0/S0 on [0, 2.00] */
1322fe8fb19SBen Gras r02 = 1.562499999999999408594634421055018003102e-0002,
1332fe8fb19SBen Gras r03 = -1.899792942388547334476601771991800712355e-0004,
1342fe8fb19SBen Gras r04 = 1.829540495327006565964161150603950916854e-0006,
1352fe8fb19SBen Gras r05 = -4.618326885321032060803075217804816988758e-0009,
1362fe8fb19SBen Gras s01 = 1.561910294648900170180789369288114642057e-0002,
1372fe8fb19SBen Gras s02 = 1.169267846633374484918570613449245536323e-0004,
1382fe8fb19SBen Gras s03 = 5.135465502073181376284426245689510134134e-0007,
1392fe8fb19SBen Gras s04 = 1.166140033337900097836930825478674320464e-0009;
1402fe8fb19SBen Gras
1412fe8fb19SBen Gras double
j0(double x)1422fe8fb19SBen Gras j0(double x)
1432fe8fb19SBen Gras {
1442fe8fb19SBen Gras double z, s,c,ss,cc,r,u,v;
1452fe8fb19SBen Gras
1462fe8fb19SBen Gras if (!finite(x)) {
147*84d9c625SLionel Sambuc #if _IEEE
148*84d9c625SLionel Sambuc return one/(x*x);
149*84d9c625SLionel Sambuc #else
150*84d9c625SLionel Sambuc return (0);
151*84d9c625SLionel Sambuc #endif
1522fe8fb19SBen Gras }
1532fe8fb19SBen Gras x = fabs(x);
1542fe8fb19SBen Gras if (x >= 2.0) { /* |x| >= 2.0 */
1552fe8fb19SBen Gras s = sin(x);
1562fe8fb19SBen Gras c = cos(x);
1572fe8fb19SBen Gras ss = s-c;
1582fe8fb19SBen Gras cc = s+c;
1592fe8fb19SBen Gras if (x < .5 * DBL_MAX) { /* make sure x+x not overflow */
1602fe8fb19SBen Gras z = -cos(x+x);
1612fe8fb19SBen Gras if ((s*c)<zero) cc = z/ss;
1622fe8fb19SBen Gras else ss = z/cc;
1632fe8fb19SBen Gras }
1642fe8fb19SBen Gras /*
1652fe8fb19SBen Gras * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
1662fe8fb19SBen Gras * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
1672fe8fb19SBen Gras */
168*84d9c625SLionel Sambuc #if _IEEE
169*84d9c625SLionel Sambuc if (x > 6.80564733841876927e+38) /* 2^129 */
1702fe8fb19SBen Gras z = (invsqrtpi*cc)/sqrt(x);
171*84d9c625SLionel Sambuc else
172*84d9c625SLionel Sambuc #endif
173*84d9c625SLionel Sambuc {
1742fe8fb19SBen Gras u = pzero(x); v = qzero(x);
1752fe8fb19SBen Gras z = invsqrtpi*(u*cc-v*ss)/sqrt(x);
1762fe8fb19SBen Gras }
1772fe8fb19SBen Gras return z;
1782fe8fb19SBen Gras }
1792fe8fb19SBen Gras if (x < 1.220703125e-004) { /* |x| < 2**-13 */
1802fe8fb19SBen Gras if (huge+x > one) { /* raise inexact if x != 0 */
1812fe8fb19SBen Gras if (x < 7.450580596923828125e-009) /* |x|<2**-27 */
1822fe8fb19SBen Gras return one;
1832fe8fb19SBen Gras else return (one - 0.25*x*x);
1842fe8fb19SBen Gras }
1852fe8fb19SBen Gras }
1862fe8fb19SBen Gras z = x*x;
1872fe8fb19SBen Gras r = z*(r02+z*(r03+z*(r04+z*r05)));
1882fe8fb19SBen Gras s = one+z*(s01+z*(s02+z*(s03+z*s04)));
1892fe8fb19SBen Gras if (x < one) { /* |x| < 1.00 */
1902fe8fb19SBen Gras return (one + z*(-0.25+(r/s)));
1912fe8fb19SBen Gras } else {
1922fe8fb19SBen Gras u = 0.5*x;
1932fe8fb19SBen Gras return ((one+u)*(one-u)+z*(r/s));
1942fe8fb19SBen Gras }
1952fe8fb19SBen Gras }
1962fe8fb19SBen Gras
1972fe8fb19SBen Gras static const double
1982fe8fb19SBen Gras u00 = -7.380429510868722527422411862872999615628e-0002,
1992fe8fb19SBen Gras u01 = 1.766664525091811069896442906220827182707e-0001,
2002fe8fb19SBen Gras u02 = -1.381856719455968955440002438182885835344e-0002,
2012fe8fb19SBen Gras u03 = 3.474534320936836562092566861515617053954e-0004,
2022fe8fb19SBen Gras u04 = -3.814070537243641752631729276103284491172e-0006,
2032fe8fb19SBen Gras u05 = 1.955901370350229170025509706510038090009e-0008,
2042fe8fb19SBen Gras u06 = -3.982051941321034108350630097330144576337e-0011,
2052fe8fb19SBen Gras v01 = 1.273048348341237002944554656529224780561e-0002,
2062fe8fb19SBen Gras v02 = 7.600686273503532807462101309675806839635e-0005,
2072fe8fb19SBen Gras v03 = 2.591508518404578033173189144579208685163e-0007,
2082fe8fb19SBen Gras v04 = 4.411103113326754838596529339004302243157e-0010;
2092fe8fb19SBen Gras
2102fe8fb19SBen Gras double
y0(double x)2112fe8fb19SBen Gras y0(double x)
2122fe8fb19SBen Gras {
2132fe8fb19SBen Gras double z, s, c, ss, cc, u, v;
2142fe8fb19SBen Gras /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
2152fe8fb19SBen Gras if (!finite(x)) {
216*84d9c625SLionel Sambuc #if _IEEE
2172fe8fb19SBen Gras return (one/(x+x*x));
218*84d9c625SLionel Sambuc #else
2192fe8fb19SBen Gras return (0);
220*84d9c625SLionel Sambuc #endif
2212fe8fb19SBen Gras }
2222fe8fb19SBen Gras if (x == 0) {
223*84d9c625SLionel Sambuc #if _IEEE
224*84d9c625SLionel Sambuc return (-one/zero);
225*84d9c625SLionel Sambuc #else
226*84d9c625SLionel Sambuc return(infnan(-ERANGE));
227*84d9c625SLionel Sambuc #endif
2282fe8fb19SBen Gras }
2292fe8fb19SBen Gras if (x<0) {
230*84d9c625SLionel Sambuc #if _IEEE
231*84d9c625SLionel Sambuc return (zero/zero);
232*84d9c625SLionel Sambuc #else
233*84d9c625SLionel Sambuc return (infnan(EDOM));
234*84d9c625SLionel Sambuc #endif
2352fe8fb19SBen Gras }
2362fe8fb19SBen Gras if (x >= 2.00) { /* |x| >= 2.0 */
2372fe8fb19SBen Gras /* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
2382fe8fb19SBen Gras * where x0 = x-pi/4
2392fe8fb19SBen Gras * Better formula:
2402fe8fb19SBen Gras * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
2412fe8fb19SBen Gras * = 1/sqrt(2) * (sin(x) + cos(x))
2422fe8fb19SBen Gras * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
2432fe8fb19SBen Gras * = 1/sqrt(2) * (sin(x) - cos(x))
2442fe8fb19SBen Gras * To avoid cancellation, use
2452fe8fb19SBen Gras * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
2462fe8fb19SBen Gras * to compute the worse one.
2472fe8fb19SBen Gras */
2482fe8fb19SBen Gras s = sin(x);
2492fe8fb19SBen Gras c = cos(x);
2502fe8fb19SBen Gras ss = s-c;
2512fe8fb19SBen Gras cc = s+c;
2522fe8fb19SBen Gras /*
2532fe8fb19SBen Gras * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
2542fe8fb19SBen Gras * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
2552fe8fb19SBen Gras */
2562fe8fb19SBen Gras if (x < .5 * DBL_MAX) { /* make sure x+x not overflow */
2572fe8fb19SBen Gras z = -cos(x+x);
2582fe8fb19SBen Gras if ((s*c)<zero) cc = z/ss;
2592fe8fb19SBen Gras else ss = z/cc;
2602fe8fb19SBen Gras }
261*84d9c625SLionel Sambuc #if _IEEE
262*84d9c625SLionel Sambuc if (x > 6.80564733841876927e+38) /* > 2^129 */
2632fe8fb19SBen Gras z = (invsqrtpi*ss)/sqrt(x);
264*84d9c625SLionel Sambuc else
265*84d9c625SLionel Sambuc #endif
266*84d9c625SLionel Sambuc {
2672fe8fb19SBen Gras u = pzero(x); v = qzero(x);
2682fe8fb19SBen Gras z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
2692fe8fb19SBen Gras }
2702fe8fb19SBen Gras return z;
2712fe8fb19SBen Gras }
2722fe8fb19SBen Gras if (x <= 7.450580596923828125e-009) { /* x < 2**-27 */
2732fe8fb19SBen Gras return (u00 + tpi*log(x));
2742fe8fb19SBen Gras }
2752fe8fb19SBen Gras z = x*x;
2762fe8fb19SBen Gras u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
2772fe8fb19SBen Gras v = one+z*(v01+z*(v02+z*(v03+z*v04)));
2782fe8fb19SBen Gras return (u/v + tpi*(j0(x)*log(x)));
2792fe8fb19SBen Gras }
2802fe8fb19SBen Gras
2812fe8fb19SBen Gras /* The asymptotic expansions of pzero is
2822fe8fb19SBen Gras * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
2832fe8fb19SBen Gras * For x >= 2, We approximate pzero by
2842fe8fb19SBen Gras * pzero(x) = 1 + (R/S)
2852fe8fb19SBen Gras * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
2862fe8fb19SBen Gras * S = 1 + ps0*s^2 + ... + ps4*s^10
2872fe8fb19SBen Gras * and
2882fe8fb19SBen Gras * | pzero(x)-1-R/S | <= 2 ** ( -60.26)
2892fe8fb19SBen Gras */
2902fe8fb19SBen Gras static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
2912fe8fb19SBen Gras 0.0,
2922fe8fb19SBen Gras -7.031249999999003994151563066182798210142e-0002,
2932fe8fb19SBen Gras -8.081670412753498508883963849859423939871e+0000,
2942fe8fb19SBen Gras -2.570631056797048755890526455854482662510e+0002,
2952fe8fb19SBen Gras -2.485216410094288379417154382189125598962e+0003,
2962fe8fb19SBen Gras -5.253043804907295692946647153614119665649e+0003,
2972fe8fb19SBen Gras };
2982fe8fb19SBen Gras static const double ps8[5] = {
2992fe8fb19SBen Gras 1.165343646196681758075176077627332052048e+0002,
3002fe8fb19SBen Gras 3.833744753641218451213253490882686307027e+0003,
3012fe8fb19SBen Gras 4.059785726484725470626341023967186966531e+0004,
3022fe8fb19SBen Gras 1.167529725643759169416844015694440325519e+0005,
3032fe8fb19SBen Gras 4.762772841467309430100106254805711722972e+0004,
3042fe8fb19SBen Gras };
3052fe8fb19SBen Gras
3062fe8fb19SBen Gras static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
3072fe8fb19SBen Gras -1.141254646918944974922813501362824060117e-0011,
3082fe8fb19SBen Gras -7.031249408735992804117367183001996028304e-0002,
3092fe8fb19SBen Gras -4.159610644705877925119684455252125760478e+0000,
3102fe8fb19SBen Gras -6.767476522651671942610538094335912346253e+0001,
3112fe8fb19SBen Gras -3.312312996491729755731871867397057689078e+0002,
3122fe8fb19SBen Gras -3.464333883656048910814187305901796723256e+0002,
3132fe8fb19SBen Gras };
3142fe8fb19SBen Gras static const double ps5[5] = {
3152fe8fb19SBen Gras 6.075393826923003305967637195319271932944e+0001,
3162fe8fb19SBen Gras 1.051252305957045869801410979087427910437e+0003,
3172fe8fb19SBen Gras 5.978970943338558182743915287887408780344e+0003,
3182fe8fb19SBen Gras 9.625445143577745335793221135208591603029e+0003,
3192fe8fb19SBen Gras 2.406058159229391070820491174867406875471e+0003,
3202fe8fb19SBen Gras };
3212fe8fb19SBen Gras
3222fe8fb19SBen Gras static const double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
3232fe8fb19SBen Gras -2.547046017719519317420607587742992297519e-0009,
3242fe8fb19SBen Gras -7.031196163814817199050629727406231152464e-0002,
3252fe8fb19SBen Gras -2.409032215495295917537157371488126555072e+0000,
3262fe8fb19SBen Gras -2.196597747348830936268718293366935843223e+0001,
3272fe8fb19SBen Gras -5.807917047017375458527187341817239891940e+0001,
3282fe8fb19SBen Gras -3.144794705948885090518775074177485744176e+0001,
3292fe8fb19SBen Gras };
3302fe8fb19SBen Gras static const double ps3[5] = {
3312fe8fb19SBen Gras 3.585603380552097167919946472266854507059e+0001,
3322fe8fb19SBen Gras 3.615139830503038919981567245265266294189e+0002,
3332fe8fb19SBen Gras 1.193607837921115243628631691509851364715e+0003,
3342fe8fb19SBen Gras 1.127996798569074250675414186814529958010e+0003,
3352fe8fb19SBen Gras 1.735809308133357510239737333055228118910e+0002,
3362fe8fb19SBen Gras };
3372fe8fb19SBen Gras
3382fe8fb19SBen Gras static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
3392fe8fb19SBen Gras -8.875343330325263874525704514800809730145e-0008,
3402fe8fb19SBen Gras -7.030309954836247756556445443331044338352e-0002,
3412fe8fb19SBen Gras -1.450738467809529910662233622603401167409e+0000,
3422fe8fb19SBen Gras -7.635696138235277739186371273434739292491e+0000,
3432fe8fb19SBen Gras -1.119316688603567398846655082201614524650e+0001,
3442fe8fb19SBen Gras -3.233645793513353260006821113608134669030e+0000,
3452fe8fb19SBen Gras };
3462fe8fb19SBen Gras static const double ps2[5] = {
3472fe8fb19SBen Gras 2.222029975320888079364901247548798910952e+0001,
3482fe8fb19SBen Gras 1.362067942182152109590340823043813120940e+0002,
3492fe8fb19SBen Gras 2.704702786580835044524562897256790293238e+0002,
3502fe8fb19SBen Gras 1.538753942083203315263554770476850028583e+0002,
3512fe8fb19SBen Gras 1.465761769482561965099880599279699314477e+0001,
3522fe8fb19SBen Gras };
3532fe8fb19SBen Gras
3542fe8fb19SBen Gras static double
pzero(double x)3552fe8fb19SBen Gras pzero(double x)
3562fe8fb19SBen Gras {
3572fe8fb19SBen Gras const double *p,*q;
3582fe8fb19SBen Gras double z,r,s;
3592fe8fb19SBen Gras if (x >= 8.00) {p = pr8; q= ps8;}
3602fe8fb19SBen Gras else if (x >= 4.54545211791992188) {p = pr5; q= ps5;}
3612fe8fb19SBen Gras else if (x >= 2.85714149475097656) {p = pr3; q= ps3;}
3622fe8fb19SBen Gras else /* if (x >= 2.00) */ {p = pr2; q= ps2;}
3632fe8fb19SBen Gras z = one/(x*x);
3642fe8fb19SBen Gras r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
3652fe8fb19SBen Gras s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
3662fe8fb19SBen Gras return one+ r/s;
3672fe8fb19SBen Gras }
3682fe8fb19SBen Gras
3692fe8fb19SBen Gras
3702fe8fb19SBen Gras /* For x >= 8, the asymptotic expansions of qzero is
3712fe8fb19SBen Gras * -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
3722fe8fb19SBen Gras * We approximate pzero by
3732fe8fb19SBen Gras * qzero(x) = s*(-1.25 + (R/S))
3742fe8fb19SBen Gras * where R = qr0 + qr1*s^2 + qr2*s^4 + ... + qr5*s^10
3752fe8fb19SBen Gras * S = 1 + qs0*s^2 + ... + qs5*s^12
3762fe8fb19SBen Gras * and
3772fe8fb19SBen Gras * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
3782fe8fb19SBen Gras */
3792fe8fb19SBen Gras static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
3802fe8fb19SBen Gras 0.0,
3812fe8fb19SBen Gras 7.324218749999350414479738504551775297096e-0002,
3822fe8fb19SBen Gras 1.176820646822526933903301695932765232456e+0001,
3832fe8fb19SBen Gras 5.576733802564018422407734683549251364365e+0002,
3842fe8fb19SBen Gras 8.859197207564685717547076568608235802317e+0003,
3852fe8fb19SBen Gras 3.701462677768878501173055581933725704809e+0004,
3862fe8fb19SBen Gras };
3872fe8fb19SBen Gras static const double qs8[6] = {
3882fe8fb19SBen Gras 1.637760268956898345680262381842235272369e+0002,
3892fe8fb19SBen Gras 8.098344946564498460163123708054674227492e+0003,
3902fe8fb19SBen Gras 1.425382914191204905277585267143216379136e+0005,
3912fe8fb19SBen Gras 8.033092571195144136565231198526081387047e+0005,
3922fe8fb19SBen Gras 8.405015798190605130722042369969184811488e+0005,
3932fe8fb19SBen Gras -3.438992935378666373204500729736454421006e+0005,
3942fe8fb19SBen Gras };
3952fe8fb19SBen Gras
3962fe8fb19SBen Gras static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
3972fe8fb19SBen Gras 1.840859635945155400568380711372759921179e-0011,
3982fe8fb19SBen Gras 7.324217666126847411304688081129741939255e-0002,
3992fe8fb19SBen Gras 5.835635089620569401157245917610984757296e+0000,
4002fe8fb19SBen Gras 1.351115772864498375785526599119895942361e+0002,
4012fe8fb19SBen Gras 1.027243765961641042977177679021711341529e+0003,
4022fe8fb19SBen Gras 1.989977858646053872589042328678602481924e+0003,
4032fe8fb19SBen Gras };
4042fe8fb19SBen Gras static const double qs5[6] = {
4052fe8fb19SBen Gras 8.277661022365377058749454444343415524509e+0001,
4062fe8fb19SBen Gras 2.077814164213929827140178285401017305309e+0003,
4072fe8fb19SBen Gras 1.884728877857180787101956800212453218179e+0004,
4082fe8fb19SBen Gras 5.675111228949473657576693406600265778689e+0004,
4092fe8fb19SBen Gras 3.597675384251145011342454247417399490174e+0004,
4102fe8fb19SBen Gras -5.354342756019447546671440667961399442388e+0003,
4112fe8fb19SBen Gras };
4122fe8fb19SBen Gras
4132fe8fb19SBen Gras static const double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
4142fe8fb19SBen Gras 4.377410140897386263955149197672576223054e-0009,
4152fe8fb19SBen Gras 7.324111800429115152536250525131924283018e-0002,
4162fe8fb19SBen Gras 3.344231375161707158666412987337679317358e+0000,
4172fe8fb19SBen Gras 4.262184407454126175974453269277100206290e+0001,
4182fe8fb19SBen Gras 1.708080913405656078640701512007621675724e+0002,
4192fe8fb19SBen Gras 1.667339486966511691019925923456050558293e+0002,
4202fe8fb19SBen Gras };
4212fe8fb19SBen Gras static const double qs3[6] = {
4222fe8fb19SBen Gras 4.875887297245871932865584382810260676713e+0001,
4232fe8fb19SBen Gras 7.096892210566060535416958362640184894280e+0002,
4242fe8fb19SBen Gras 3.704148226201113687434290319905207398682e+0003,
4252fe8fb19SBen Gras 6.460425167525689088321109036469797462086e+0003,
4262fe8fb19SBen Gras 2.516333689203689683999196167394889715078e+0003,
4272fe8fb19SBen Gras -1.492474518361563818275130131510339371048e+0002,
4282fe8fb19SBen Gras };
4292fe8fb19SBen Gras
4302fe8fb19SBen Gras static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
4312fe8fb19SBen Gras 1.504444448869832780257436041633206366087e-0007,
4322fe8fb19SBen Gras 7.322342659630792930894554535717104926902e-0002,
4332fe8fb19SBen Gras 1.998191740938159956838594407540292600331e+0000,
4342fe8fb19SBen Gras 1.449560293478857407645853071687125850962e+0001,
4352fe8fb19SBen Gras 3.166623175047815297062638132537957315395e+0001,
4362fe8fb19SBen Gras 1.625270757109292688799540258329430963726e+0001,
4372fe8fb19SBen Gras };
4382fe8fb19SBen Gras static const double qs2[6] = {
4392fe8fb19SBen Gras 3.036558483552191922522729838478169383969e+0001,
4402fe8fb19SBen Gras 2.693481186080498724211751445725708524507e+0002,
4412fe8fb19SBen Gras 8.447837575953201460013136756723746023736e+0002,
4422fe8fb19SBen Gras 8.829358451124885811233995083187666981299e+0002,
4432fe8fb19SBen Gras 2.126663885117988324180482985363624996652e+0002,
4442fe8fb19SBen Gras -5.310954938826669402431816125780738924463e+0000,
4452fe8fb19SBen Gras };
4462fe8fb19SBen Gras
4472fe8fb19SBen Gras static double
qzero(double x)4482fe8fb19SBen Gras qzero(double x)
4492fe8fb19SBen Gras {
4502fe8fb19SBen Gras const double *p,*q;
4512fe8fb19SBen Gras double s,r,z;
4522fe8fb19SBen Gras if (x >= 8.00) {p = qr8; q= qs8;}
4532fe8fb19SBen Gras else if (x >= 4.54545211791992188) {p = qr5; q= qs5;}
4542fe8fb19SBen Gras else if (x >= 2.85714149475097656) {p = qr3; q= qs3;}
4552fe8fb19SBen Gras else /* if (x >= 2.00) */ {p = qr2; q= qs2;}
4562fe8fb19SBen Gras z = one/(x*x);
4572fe8fb19SBen Gras r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
4582fe8fb19SBen Gras s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
4592fe8fb19SBen Gras return (-.125 + r/s)/x;
4602fe8fb19SBen Gras }
461