summaryrefslogtreecommitdiff
path: root/libm/float/j1f.c
blob: 4306e9747b91bb28ed5cf46fa6f79c3cc56c0132 (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
/*							j1f.c
 *
 *	Bessel function of order one
 *
 *
 *
 * SYNOPSIS:
 *
 * float x, y, j1f();
 *
 * y = j1f( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns Bessel function of order one of the argument.
 *
 * The domain is divided into the intervals [0, 2] and
 * (2, infinity). In the first interval a polynomial approximation
 *        2 
 * (w - r  ) x P(w)
 *       1  
 *                     2 
 * is used, where w = x  and r is the first zero 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) - 3pi/4.  The function is
 *
 *   j0(x) = Modulus(x) cos( Phase(x) ).
 *
 *
 *
 * ACCURACY:
 *
 *                      Absolute error:
 * arithmetic   domain      # trials      peak       rms
 *    IEEE      0,  2       100000       1.2e-7     2.5e-8
 *    IEEE      2, 32       100000       2.0e-7     5.3e-8
 *
 *
 */
/*							y1.c
 *
 *	Bessel function of second kind of order one
 *
 *
 *
 * SYNOPSIS:
 *
 * double x, y, y1();
 *
 * y = y1( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns Bessel function of the second kind of order one
 * 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
 * y0(x)  =  (w - r  ) x R(x^2)  +  2/pi (ln(x) j1(x) - 1/x) .
 *                 1
 *
 * Thus a call to j1() is required.
 *
 * 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) - 3pi/4.  Then the function is
 *
 *   y0(x) = Modulus(x) sin( Phase(x) ).
 *
 *
 *
 *
 * ACCURACY:
 *
 *                      Absolute error:
 * arithmetic   domain      # trials      peak         rms
 *    IEEE      0,  2       100000       2.2e-7     4.6e-8
 *    IEEE      2, 32       100000       1.9e-7     5.3e-8
 *
 * (error criterion relative when |y1| > 1).
 *
 */


/*
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 JP[5] = {
-4.878788132172128E-009f,
 6.009061827883699E-007f,
-4.541343896997497E-005f,
 1.937383947804541E-003f,
-3.405537384615824E-002f
};

static float YP[5] = {
 8.061978323326852E-009f,
-9.496460629917016E-007f,
 6.719543806674249E-005f,
-2.641785726447862E-003f,
 4.202369946500099E-002f
};

static float MO1[8] = {
 6.913942741265801E-002f,
-2.284801500053359E-001f,
 3.138238455499697E-001f,
-2.102302420403875E-001f,
 5.435364690523026E-003f,
 1.493389585089498E-001f,
 4.976029650847191E-006f,
 7.978845453073848E-001f
};

static float PH1[8] = {
-4.497014141919556E+001f,
 5.073465654089319E+001f,
-2.485774108720340E+001f,
 7.222973196770240E+000f,
-1.544842782180211E+000f,
 3.503787691653334E-001f,
-1.637986776941202E-001f,
 3.749989509080821E-001f
};

static float YO1 =  4.66539330185668857532f;
static float Z1 = 1.46819706421238932572E1f;

static float THPIO4F =  2.35619449019234492885f;    /* 3*pi/4 */
static float TWOOPI =  0.636619772367581343075535f; /* 2/pi */
extern float PIO4;


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

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


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

if( x <= 2.0f )
	{
	z = x * x;	
	p = (z-Z1) * x * polevlf( z, JP, 4 );
	return( p );
	}

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

p = w * polevlf( q, MO1, 7);
w = q*q;
xn = q * polevlf( w, PH1, 7) - THPIO4F;
p = p * cosf(xn + x);
return(p);
}




extern float MAXNUMF;

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


x = xx;
if( x <= 2.0f )
	{
	if( x <= 0.0f )
		{
		mtherr( "y1f", DOMAIN );
		return( -MAXNUMF );
		}
	z = x * x;
	w = (z - YO1) * x * polevlf( z, YP, 4 );
	w += TWOOPI * ( j1f(x) * logf(x)  -  1.0f/x );
	return( w );
	}

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

p = w * polevlf( q, MO1, 7);
w = q*q;
xn = q * polevlf( w, PH1, 7) - THPIO4F;
p = p * sinf(xn + x);
return(p);
}