xref: /csrg-svn/lib/libm/common_source/j1.c (revision 57151)
148402Sbostic /*-
2*57151Sbostic  * Copyright (c) 1992 The Regents of the University of California.
348402Sbostic  * All rights reserved.
448402Sbostic  *
5*57151Sbostic  * %sccs.include.redist.c%
634118Sbostic  */
734118Sbostic 
824598Szliu #ifndef lint
9*57151Sbostic static char sccsid[] = "@(#)j1.c	5.5 (Berkeley) 12/16/92";
1034118Sbostic #endif /* not lint */
1124598Szliu 
1224598Szliu /*
13*57151Sbostic  * 16 December 1992
14*57151Sbostic  * Minor modifications by Peter McIlroy to adapt non-IEEE architecture.
15*57151Sbostic  */
1624598Szliu 
17*57151Sbostic /*
18*57151Sbostic  * ====================================================
19*57151Sbostic  * Copyright (C) 1992 by Sun Microsystems, Inc.
20*57151Sbostic  *
21*57151Sbostic  * Developed at SunPro, a Sun Microsystems, Inc. business.
22*57151Sbostic  * Permission to use, copy, modify, and distribute this
23*57151Sbostic  * software is freely granted, provided that this notice
24*57151Sbostic  * is preserved.
25*57151Sbostic  * ====================================================
26*57151Sbostic  *
27*57151Sbostic  * ******************* WARNING ********************
28*57151Sbostic  * This is an alpha version of SunPro's FDLIBM (Freely
29*57151Sbostic  * Distributable Math Library) for IEEE double precision
30*57151Sbostic  * arithmetic. FDLIBM is a basic math library written
31*57151Sbostic  * in C that runs on machines that conform to IEEE
32*57151Sbostic  * Standard 754/854. This alpha version is distributed
33*57151Sbostic  * for testing purpose. Those who use this software
34*57151Sbostic  * should report any bugs to
35*57151Sbostic  *
36*57151Sbostic  *		fdlibm-comments@sunpro.eng.sun.com
37*57151Sbostic  *
38*57151Sbostic  * -- K.C. Ng, Oct 12, 1992
39*57151Sbostic  * ************************************************
40*57151Sbostic  */
4124598Szliu 
42*57151Sbostic /* double j1(double x), y1(double x)
43*57151Sbostic  * Bessel function of the first and second kinds of order zero.
44*57151Sbostic  * Method -- j1(x):
45*57151Sbostic  *	1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
46*57151Sbostic  *	2. Reduce x to |x| since j1(x)=-j1(-x),  and
47*57151Sbostic  *	   for x in (0,2)
48*57151Sbostic  *		j1(x) = x/2 + x*z*R0/S0,  where z = x*x;
49*57151Sbostic  *	   (precision:  |j1/x - 1/2 - R0/S0 |<2**-61.51 )
50*57151Sbostic  *	   for x in (2,inf)
51*57151Sbostic  * 		j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
52*57151Sbostic  * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
53*57151Sbostic  * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
54*57151Sbostic  *	   as follows:
55*57151Sbostic  *		cos(x1) =  cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
56*57151Sbostic  *			=  1/sqrt(2) * (sin(x) - cos(x))
57*57151Sbostic  *		sin(x1) =  sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
58*57151Sbostic  *			= -1/sqrt(2) * (sin(x) + cos(x))
59*57151Sbostic  * 	   (To avoid cancellation, use
60*57151Sbostic  *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
61*57151Sbostic  * 	    to compute the worse one.)
62*57151Sbostic  *
63*57151Sbostic  *	3 Special cases
64*57151Sbostic  *		j1(nan)= nan
65*57151Sbostic  *		j1(0) = 0
66*57151Sbostic  *		j1(inf) = 0
67*57151Sbostic  *
68*57151Sbostic  * Method -- y1(x):
69*57151Sbostic  *	1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
70*57151Sbostic  *	2. For x<2.
71*57151Sbostic  *	   Since
72*57151Sbostic  *		y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
73*57151Sbostic  *	   therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
74*57151Sbostic  *	   We use the following function to approximate y1,
75*57151Sbostic  *		y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
76*57151Sbostic  *	   where for x in [0,2] (abs err less than 2**-65.89)
77*57151Sbostic  *		U(z) = u0 + u1*z + ... + u4*z^4
78*57151Sbostic  *		V(z) = 1  + v1*z + ... + v5*z^5
79*57151Sbostic  *	   Note: For tiny x, 1/x dominate y1 and hence
80*57151Sbostic  *		y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
81*57151Sbostic  *	3. For x>=2.
82*57151Sbostic  * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
83*57151Sbostic  * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
84*57151Sbostic  *	   by method mentioned above.
85*57151Sbostic  */
8624598Szliu 
87*57151Sbostic #include <math.h>
88*57151Sbostic #include <float.h>
8924598Szliu 
90*57151Sbostic #if defined(vax) || defined(tahoe)
91*57151Sbostic #define _IEEE	0
92*57151Sbostic #else
93*57151Sbostic #define _IEEE	1
94*57151Sbostic #define infnan(x) (0.0)
95*57151Sbostic #endif
9624598Szliu 
97*57151Sbostic static double pone(), qone();
9824598Szliu 
99*57151Sbostic static double
100*57151Sbostic huge    = 1e300,
101*57151Sbostic zero    = 0.0,
102*57151Sbostic one	= 1.0,
103*57151Sbostic invsqrtpi= 5.641895835477562869480794515607725858441e-0001,
104*57151Sbostic tpi	= 0.636619772367581343075535053490057448,
10524598Szliu 
106*57151Sbostic 	/* R0/S0 on [0,2] */
107*57151Sbostic r00 =  -6.250000000000000020842322918309200910191e-0002,
108*57151Sbostic r01 =   1.407056669551897148204830386691427791200e-0003,
109*57151Sbostic r02 =  -1.599556310840356073980727783817809847071e-0005,
110*57151Sbostic r03 =   4.967279996095844750387702652791615403527e-0008,
111*57151Sbostic s01 =   1.915375995383634614394860200531091839635e-0002,
112*57151Sbostic s02 =   1.859467855886309024045655476348872850396e-0004,
113*57151Sbostic s03 =   1.177184640426236767593432585906758230822e-0006,
114*57151Sbostic s04 =   5.046362570762170559046714468225101016915e-0009,
115*57151Sbostic s05 =   1.235422744261379203512624973117299248281e-0011;
11624598Szliu 
117*57151Sbostic #define two_129	6.80564733841876926e+038	/* 2^129 */
118*57151Sbostic #define two_m54	5.55111512312578270e-017	/* 2^-54 */
119*57151Sbostic double j1(x)
120*57151Sbostic 	double x;
121*57151Sbostic {
122*57151Sbostic 	double z, s,c,ss,cc,r,u,v,y;
123*57151Sbostic 	y = fabs(x);
124*57151Sbostic 	if (!finite(x))			/* Inf or NaN */
125*57151Sbostic 		if (_IEEE && x != x)
126*57151Sbostic 			return(x);
127*57151Sbostic 		else
128*57151Sbostic 			return (copysign(x, zero));
129*57151Sbostic 	y = fabs(x);
130*57151Sbostic 	if (y >= 2)			/* |x| >= 2.0 */
131*57151Sbostic 	{
132*57151Sbostic 		s = sin(y);
133*57151Sbostic 		c = cos(y);
134*57151Sbostic 		ss = -s-c;
135*57151Sbostic 		cc = s-c;
136*57151Sbostic 		if (y < .5*DBL_MAX) {  	/* make sure y+y not overflow */
137*57151Sbostic 		    z = cos(y+y);
138*57151Sbostic 		    if ((s*c)<zero) cc = z/ss;
139*57151Sbostic 		    else 	    ss = z/cc;
140*57151Sbostic 		}
141*57151Sbostic 	/*
142*57151Sbostic 	 * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
143*57151Sbostic 	 * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
144*57151Sbostic 	 */
145*57151Sbostic #if !defined(vax) && !defined(tahoe)
146*57151Sbostic 		if (y > two_129)	 /* x > 2^129 */
147*57151Sbostic 			z = (invsqrtpi*cc)/sqrt(y);
148*57151Sbostic 		else
149*57151Sbostic #endif /* defined(vax) || defined(tahoe) */
150*57151Sbostic 		{
151*57151Sbostic 		    u = pone(y); v = qone(y);
152*57151Sbostic 		    z = invsqrtpi*(u*cc-v*ss)/sqrt(y);
153*57151Sbostic 		}
154*57151Sbostic 		if (x < 0) return -z;
155*57151Sbostic 		else  	 return  z;
156*57151Sbostic 	}
157*57151Sbostic 	if (y < 7.450580596923828125e-009) {	/* |x|<2**-27 */
158*57151Sbostic 	    if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */
159*57151Sbostic 	}
160*57151Sbostic 	z = x*x;
161*57151Sbostic 	r =  z*(r00+z*(r01+z*(r02+z*r03)));
162*57151Sbostic 	s =  one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
163*57151Sbostic 	r *= x;
164*57151Sbostic 	return (x*0.5+r/s);
165*57151Sbostic }
16624598Szliu 
167*57151Sbostic static double u0[5] = {
168*57151Sbostic   -1.960570906462389484206891092512047539632e-0001,
169*57151Sbostic    5.044387166398112572026169863174882070274e-0002,
170*57151Sbostic   -1.912568958757635383926261729464141209569e-0003,
171*57151Sbostic    2.352526005616105109577368905595045204577e-0005,
172*57151Sbostic    -9.190991580398788465315411784276789663849e-0008,
173*57151Sbostic };
174*57151Sbostic static double v0[5] = {
175*57151Sbostic    1.991673182366499064031901734535479833387e-0002,
176*57151Sbostic    2.025525810251351806268483867032781294682e-0004,
177*57151Sbostic    1.356088010975162198085369545564475416398e-0006,
178*57151Sbostic    6.227414523646214811803898435084697863445e-0009,
179*57151Sbostic    1.665592462079920695971450872592458916421e-0011,
180*57151Sbostic };
18135679Sbostic 
182*57151Sbostic double y1(x)
183*57151Sbostic 	double x;
184*57151Sbostic {
185*57151Sbostic 	double z, s,c,ss,cc,u,v,j1();
186*57151Sbostic     /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
187*57151Sbostic 	if (!finite(x))
188*57151Sbostic 		if (!_IEEE) return (infnan(EDOM));
189*57151Sbostic 		else if (x < 0)
190*57151Sbostic 			return(zero/zero);
191*57151Sbostic 		else if (x > 0)
192*57151Sbostic 			return (0);
193*57151Sbostic 		else
194*57151Sbostic 			return(x);
195*57151Sbostic 	if (x <= 0) {
196*57151Sbostic 		if (_IEEE && x == 0) return -one/zero;
197*57151Sbostic 		else if(x == 0) return(infnan(-ERANGE));
198*57151Sbostic 		else if(_IEEE) return (zero/zero);
199*57151Sbostic 		else return(infnan(EDOM));
200*57151Sbostic 	}
201*57151Sbostic         if (x >= 2)			 /* |x| >= 2.0 */
202*57151Sbostic 	{
203*57151Sbostic                 s = sin(x);
204*57151Sbostic                 c = cos(x);
205*57151Sbostic                 ss = -s-c;
206*57151Sbostic                 cc = s-c;
207*57151Sbostic 		if (x < .5 * DBL_MAX)	/* make sure x+x not overflow */
208*57151Sbostic 		{
209*57151Sbostic                     z = cos(x+x);
210*57151Sbostic                     if ((s*c)>zero) cc = z/ss;
211*57151Sbostic                     else            ss = z/cc;
212*57151Sbostic                 }
213*57151Sbostic         /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
214*57151Sbostic          * where x0 = x-3pi/4
215*57151Sbostic          *      Better formula:
216*57151Sbostic          *              cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
217*57151Sbostic          *                      =  1/sqrt(2) * (sin(x) - cos(x))
218*57151Sbostic          *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
219*57151Sbostic          *                      = -1/sqrt(2) * (cos(x) + sin(x))
220*57151Sbostic          * To avoid cancellation, use
221*57151Sbostic          *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
222*57151Sbostic          * to compute the worse one.
223*57151Sbostic          */
224*57151Sbostic                 if (_IEEE && x>two_129)
225*57151Sbostic 			z = (invsqrtpi*ss)/sqrt(x);
226*57151Sbostic                 else {
227*57151Sbostic                     u = pone(x); v = qone(x);
228*57151Sbostic                     z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
229*57151Sbostic                 }
230*57151Sbostic                 return z;
231*57151Sbostic         }
232*57151Sbostic         if (x <= two_m54) {    /* x < 2**-54 */
233*57151Sbostic             return (-tpi/x);
234*57151Sbostic         }
235*57151Sbostic         z = x*x;
236*57151Sbostic         u = u0[0]+z*(u0[1]+z*(u0[2]+z*(u0[3]+z*u0[4])));
237*57151Sbostic         v = one+z*(v0[0]+z*(v0[1]+z*(v0[2]+z*(v0[3]+z*v0[4]))));
238*57151Sbostic         return (x*(u/v) + tpi*(j1(x)*log(x)-one/x));
239*57151Sbostic }
24035679Sbostic 
241*57151Sbostic /* For x >= 8, the asymptotic expansions of pone is
242*57151Sbostic  *	1 + 15/128 s^2 - 4725/2^15 s^4 - ...,	where s = 1/x.
243*57151Sbostic  * We approximate pone by
244*57151Sbostic  * 	pone(x) = 1 + (R/S)
245*57151Sbostic  * where  R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
246*57151Sbostic  * 	  S = 1 + ps0*s^2 + ... + ps4*s^10
247*57151Sbostic  * and
248*57151Sbostic  *	| pone(x)-1-R/S | <= 2  ** ( -60.06)
249*57151Sbostic  */
25035679Sbostic 
251*57151Sbostic static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
252*57151Sbostic    0.0,
253*57151Sbostic    1.171874999999886486643746274751925399540e-0001,
254*57151Sbostic    1.323948065930735690925827997575471527252e+0001,
255*57151Sbostic    4.120518543073785433325860184116512799375e+0002,
256*57151Sbostic    3.874745389139605254931106878336700275601e+0003,
257*57151Sbostic    7.914479540318917214253998253147871806507e+0003,
25824598Szliu };
259*57151Sbostic static double ps8[5] = {
260*57151Sbostic    1.142073703756784104235066368252692471887e+0002,
261*57151Sbostic    3.650930834208534511135396060708677099382e+0003,
262*57151Sbostic    3.695620602690334708579444954937638371808e+0004,
263*57151Sbostic    9.760279359349508334916300080109196824151e+0004,
264*57151Sbostic    3.080427206278887984185421142572315054499e+0004,
26524598Szliu };
266*57151Sbostic 
267*57151Sbostic static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
268*57151Sbostic    1.319905195562435287967533851581013807103e-0011,
269*57151Sbostic    1.171874931906140985709584817065144884218e-0001,
270*57151Sbostic    6.802751278684328781830052995333841452280e+0000,
271*57151Sbostic    1.083081829901891089952869437126160568246e+0002,
272*57151Sbostic    5.176361395331997166796512844100442096318e+0002,
273*57151Sbostic    5.287152013633375676874794230748055786553e+0002,
27424598Szliu };
275*57151Sbostic static double ps5[5] = {
276*57151Sbostic    5.928059872211313557747989128353699746120e+0001,
277*57151Sbostic    9.914014187336144114070148769222018425781e+0002,
278*57151Sbostic    5.353266952914879348427003712029704477451e+0003,
279*57151Sbostic    7.844690317495512717451367787640014588422e+0003,
280*57151Sbostic    1.504046888103610723953792002716816255382e+0003,
28124598Szliu };
282*57151Sbostic 
283*57151Sbostic static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
284*57151Sbostic    3.025039161373736032825049903408701962756e-0009,
285*57151Sbostic    1.171868655672535980750284752227495879921e-0001,
286*57151Sbostic    3.932977500333156527232725812363183251138e+0000,
287*57151Sbostic    3.511940355916369600741054592597098912682e+0001,
288*57151Sbostic    9.105501107507812029367749771053045219094e+0001,
289*57151Sbostic    4.855906851973649494139275085628195457113e+0001,
29024598Szliu };
291*57151Sbostic static double ps3[5] = {
292*57151Sbostic    3.479130950012515114598605916318694946754e+0001,
293*57151Sbostic    3.367624587478257581844639171605788622549e+0002,
294*57151Sbostic    1.046871399757751279180649307467612538415e+0003,
295*57151Sbostic    8.908113463982564638443204408234739237639e+0002,
296*57151Sbostic    1.037879324396392739952487012284401031859e+0002,
29724598Szliu };
298*57151Sbostic 
299*57151Sbostic static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
300*57151Sbostic    1.077108301068737449490056513753865482831e-0007,
301*57151Sbostic    1.171762194626833490512746348050035171545e-0001,
302*57151Sbostic    2.368514966676087902251125130227221462134e+0000,
303*57151Sbostic    1.224261091482612280835153832574115951447e+0001,
304*57151Sbostic    1.769397112716877301904532320376586509782e+0001,
305*57151Sbostic    5.073523125888185399030700509321145995160e+0000,
30624598Szliu };
307*57151Sbostic static double ps2[5] = {
308*57151Sbostic    2.143648593638214170243114358933327983793e+0001,
309*57151Sbostic    1.252902271684027493309211410842525120355e+0002,
310*57151Sbostic    2.322764690571628159027850677565128301361e+0002,
311*57151Sbostic    1.176793732871470939654351793502076106651e+0002,
312*57151Sbostic    8.364638933716182492500902115164881195742e+0000,
31324598Szliu };
31424598Szliu 
315*57151Sbostic static double pone(x)
316*57151Sbostic 	double x;
317*57151Sbostic {
318*57151Sbostic 	double *p,*q,z,r,s;
319*57151Sbostic 	if (x >= 8.0) 			   {p = pr8; q= ps8;}
320*57151Sbostic 	else if (x >= 4.54545211791992188) {p = pr5; q= ps5;}
321*57151Sbostic 	else if (x >= 2.85714149475097656) {p = pr3; q= ps3;}
322*57151Sbostic 	else /* if (x >= 2.0) */	   {p = pr2; q= ps2;}
323*57151Sbostic 	z = one/(x*x);
324*57151Sbostic 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
325*57151Sbostic 	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
326*57151Sbostic 	return (one + r/s);
327*57151Sbostic }
328*57151Sbostic 
32935679Sbostic 
330*57151Sbostic /* For x >= 8, the asymptotic expansions of qone is
331*57151Sbostic  *	3/8 s - 105/1024 s^3 - ..., where s = 1/x.
332*57151Sbostic  * We approximate pone by
333*57151Sbostic  * 	qone(x) = s*(0.375 + (R/S))
334*57151Sbostic  * where  R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
335*57151Sbostic  * 	  S = 1 + qs1*s^2 + ... + qs6*s^12
336*57151Sbostic  * and
337*57151Sbostic  *	| qone(x)/s -0.375-R/S | <= 2  ** ( -61.13)
338*57151Sbostic  */
33924598Szliu 
340*57151Sbostic static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
341*57151Sbostic    0.0,
342*57151Sbostic   -1.025390624999927207385863635575804210817e-0001,
343*57151Sbostic   -1.627175345445899724355852152103771510209e+0001,
344*57151Sbostic   -7.596017225139501519843072766973047217159e+0002,
345*57151Sbostic   -1.184980667024295901645301570813228628541e+0004,
346*57151Sbostic   -4.843851242857503225866761992518949647041e+0004,
347*57151Sbostic };
348*57151Sbostic static double qs8[6] = {
349*57151Sbostic    1.613953697007229231029079421446916397904e+0002,
350*57151Sbostic    7.825385999233484705298782500926834217525e+0003,
351*57151Sbostic    1.338753362872495800748094112937868089032e+0005,
352*57151Sbostic    7.196577236832409151461363171617204036929e+0005,
353*57151Sbostic    6.666012326177764020898162762642290294625e+0005,
354*57151Sbostic   -2.944902643038346618211973470809456636830e+0005,
355*57151Sbostic };
35624598Szliu 
357*57151Sbostic static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
358*57151Sbostic   -2.089799311417640889742251585097264715678e-0011,
359*57151Sbostic   -1.025390502413754195402736294609692303708e-0001,
360*57151Sbostic   -8.056448281239359746193011295417408828404e+0000,
361*57151Sbostic   -1.836696074748883785606784430098756513222e+0002,
362*57151Sbostic   -1.373193760655081612991329358017247355921e+0003,
363*57151Sbostic   -2.612444404532156676659706427295870995743e+0003,
364*57151Sbostic };
365*57151Sbostic static double qs5[6] = {
366*57151Sbostic    8.127655013843357670881559763225310973118e+0001,
367*57151Sbostic    1.991798734604859732508048816860471197220e+0003,
368*57151Sbostic    1.746848519249089131627491835267411777366e+0004,
369*57151Sbostic    4.985142709103522808438758919150738000353e+0004,
370*57151Sbostic    2.794807516389181249227113445299675335543e+0004,
371*57151Sbostic   -4.719183547951285076111596613593553911065e+0003,
372*57151Sbostic };
37324598Szliu 
374*57151Sbostic static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
375*57151Sbostic   -5.078312264617665927595954813341838734288e-0009,
376*57151Sbostic   -1.025378298208370901410560259001035577681e-0001,
377*57151Sbostic   -4.610115811394734131557983832055607679242e+0000,
378*57151Sbostic   -5.784722165627836421815348508816936196402e+0001,
379*57151Sbostic   -2.282445407376317023842545937526967035712e+0002,
380*57151Sbostic   -2.192101284789093123936441805496580237676e+0002,
381*57151Sbostic };
382*57151Sbostic static double qs3[6] = {
383*57151Sbostic    4.766515503237295155392317984171640809318e+0001,
384*57151Sbostic    6.738651126766996691330687210949984203167e+0002,
385*57151Sbostic    3.380152866795263466426219644231687474174e+0003,
386*57151Sbostic    5.547729097207227642358288160210745890345e+0003,
387*57151Sbostic    1.903119193388108072238947732674639066045e+0003,
388*57151Sbostic   -1.352011914443073322978097159157678748982e+0002,
389*57151Sbostic };
39024598Szliu 
391*57151Sbostic static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
392*57151Sbostic   -1.783817275109588656126772316921194887979e-0007,
393*57151Sbostic   -1.025170426079855506812435356168903694433e-0001,
394*57151Sbostic   -2.752205682781874520495702498875020485552e+0000,
395*57151Sbostic   -1.966361626437037351076756351268110418862e+0001,
396*57151Sbostic   -4.232531333728305108194363846333841480336e+0001,
397*57151Sbostic   -2.137192117037040574661406572497288723430e+0001,
398*57151Sbostic };
399*57151Sbostic static double qs2[6] = {
400*57151Sbostic    2.953336290605238495019307530224241335502e+0001,
401*57151Sbostic    2.529815499821905343698811319455305266409e+0002,
402*57151Sbostic    7.575028348686454070022561120722815892346e+0002,
403*57151Sbostic    7.393932053204672479746835719678434981599e+0002,
404*57151Sbostic    1.559490033366661142496448853793707126179e+0002,
405*57151Sbostic   -4.959498988226281813825263003231704397158e+0000,
406*57151Sbostic };
407*57151Sbostic 
408*57151Sbostic static double qone(x)
409*57151Sbostic 	double x;
410*57151Sbostic {
411*57151Sbostic 	double *p,*q, s,r,z;
412*57151Sbostic 	if (x >= 8.0)			   {p = qr8; q= qs8;}
413*57151Sbostic 	else if (x >= 4.54545211791992188) {p = qr5; q= qs5;}
414*57151Sbostic 	else if (x >= 2.85714149475097656) {p = qr3; q= qs3;}
415*57151Sbostic 	else /* if (x >= 2.0) */	   {p = qr2; q= qs2;}
416*57151Sbostic 	z = one/(x*x);
417*57151Sbostic 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
418*57151Sbostic 	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
419*57151Sbostic 	return (.375 + r/s)/x;
42024598Szliu }
421