summaryrefslogtreecommitdiff
path: root/libm/float/j0f.c
blob: 2b0d4a5a403c141126ef66f33ba139ba94eeca4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*							j0f.c
 *
 *	Bessel function of order zero
 *
 *
 *
 * SYNOPSIS:
 *
 * float x, y, j0f();
 *
 * y = j0f( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns Bessel function of order zero of the argument.
 *
 * The domain is divided into the intervals [0, 2] and
 * (2, infinity). In the first interval the following polynomial
 * approximation is used:
 *
 *
 *        2         2         2
 * (w - r  ) (w - r  ) (w - r  ) P(w)
 *       1         2         3   
 *
 *            2
 * where w = x  and the three r's are zeros of the function.
 *
 * In the second interval, the modulus and phase are approximated
 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
 * and Phase(x) = x + 1/x R(1/x^2) - pi/4.  The function is
 *
 *   j0(x) = Modulus(x) cos( Phase(x) ).
 *
 *
 *
 * ACCURACY:
 *
 *                      Absolute error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0, 2        100000      1.3e-7      3.6e-8
 *    IEEE      2, 32       100000      1.9e-7      5.4e-8
 *
 */
/*							y0f.c
 *
 *	Bessel function of the second kind, order zero
 *
 *
 *
 * SYNOPSIS:
 *
 * float x, y, y0f();
 *
 * y = y0f( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns Bessel function of the second kind, of order
 * zero, of the argument.
 *
 * The domain is divided into the intervals [0, 2] and
 * (2, infinity). In the first interval a rational approximation
 * R(x) is employed to compute
 *
 *                  2         2         2
 * y0(x)  =  (w - r  ) (w - r  ) (w - r  ) R(x)  +  2/pi ln(x) j0(x).
 *                 1         2         3   
 *
 * Thus a call to j0() is required.  The three zeros are removed
 * from R(x) to improve its numerical stability.
 *
 * In the second interval, the modulus and phase are approximated
 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
 * and Phase(x) = x + 1/x S(1/x^2) - pi/4.  Then the function is
 *
 *   y0(x) = Modulus(x) sin( Phase(x) ).
 *
 *
 *
 *
 * ACCURACY:
 *
 *  Absolute error, when y0(x) < 1; else relative error:
 *
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0,  2       100000      2.4e-7      3.4e-8
 *    IEEE      2, 32       100000      1.8e-7      5.3e-8
 *
 */

/*
Cephes Math Library Release 2.2:  June, 1992
Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
*/


#include <math.h>

static float MO[8] = {
-6.838999669318810E-002f,
 1.864949361379502E-001f,
-2.145007480346739E-001f,
 1.197549369473540E-001f,
-3.560281861530129E-003f,
-4.969382655296620E-002f,
-3.355424622293709E-006f,
 7.978845717621440E-001f
};

static float PH[8] = {
 3.242077816988247E+001f,
-3.630592630518434E+001f,
 1.756221482109099E+001f,
-4.974978466280903E+000f,
 1.001973420681837E+000f,
-1.939906941791308E-001f,
 6.490598792654666E-002f,
-1.249992184872738E-001f
};

static float YP[5] = {
 9.454583683980369E-008f,
-9.413212653797057E-006f,
 5.344486707214273E-004f,
-1.584289289821316E-002f,
 1.707584643733568E-001f
};

float YZ1 =  0.43221455686510834878f;
float YZ2 = 22.401876406482861405f;
float YZ3 = 64.130620282338755553f;

static float DR1 =  5.78318596294678452118f;
/*
static float DR2 = 30.4712623436620863991;
static float DR3 = 74.887006790695183444889;
*/

static float JP[5] = {
-6.068350350393235E-008f,
 6.388945720783375E-006f,
-3.969646342510940E-004f,
 1.332913422519003E-002f,
-1.729150680240724E-001f
};
extern float PIO4F;


float polevlf(float, float *, int);
float logf(float), sinf(float), cosf(float), sqrtf(float);

float j0f( float xx )
{
float x, w, z, p, q, xn;


if( xx < 0 )
	x = -xx;
else
	x = xx;

if( x <= 2.0f )
	{
	z = x * x;
	if( x < 1.0e-3f )
		return( 1.0f - 0.25f*z );

	p = (z-DR1) * polevlf( z, JP, 4);
	return( p );
	}

q = 1.0f/x;
w = sqrtf(q);

p = w * polevlf( q, MO, 7);
w = q*q;
xn = q * polevlf( w, PH, 7) - PIO4F;
p = p * cosf(xn + x);
return(p);
}

/*							y0() 2	*/
/* Bessel function of second kind, order zero	*/

/* Rational approximation coefficients YP[] are used for x < 6.5.
 * The function computed is  y0(x)  -  2 ln(x) j0(x) / pi,
 * whose value at x = 0 is  2 * ( log(0.5) + EUL ) / pi
 * = 0.073804295108687225 , EUL is Euler's constant.
 */

static float TWOOPI =  0.636619772367581343075535f; /* 2/pi */
extern float MAXNUMF;

float y0f( float xx )
{
float x, w, z, p, q, xn;


x = xx;
if( x <= 2.0f )
	{
	if( x <= 0.0f )
		{
		mtherr( "y0f", DOMAIN );
		return( -MAXNUMF );
		}
	z = x * x;
/*	w = (z-YZ1)*(z-YZ2)*(z-YZ3) * polevlf( z, YP, 4);*/
	w = (z-YZ1) * polevlf( z, YP, 4);
	w += TWOOPI * logf(x) * j0f(x);
	return( w );
	}

q = 1.0f/x;
w = sqrtf(q);

p = w * polevlf( q, MO, 7);
w = q*q;
xn = q * polevlf( w, PH, 7) - PIO4F;
p = p * sinf(xn + x);
return( p );
}