Source file
src/math/j1.go
1
2
3
4
5 package math
6
7
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 func J1(x float64) float64 {
76 const (
77 TwoM27 = 1.0 / (1 << 27)
78 Two129 = 1 << 129
79
80 R00 = -6.25000000000000000000e-02
81 R01 = 1.40705666955189706048e-03
82 R02 = -1.59955631084035597520e-05
83 R03 = 4.96727999609584448412e-08
84 S01 = 1.91537599538363460805e-02
85 S02 = 1.85946785588630915560e-04
86 S03 = 1.17718464042623683263e-06
87 S04 = 5.04636257076217042715e-09
88 S05 = 1.23542274426137913908e-11
89 )
90
91 switch {
92 case IsNaN(x):
93 return x
94 case IsInf(x, 0) || x == 0:
95 return 0
96 }
97
98 sign := false
99 if x < 0 {
100 x = -x
101 sign = true
102 }
103 if x >= 2 {
104 s, c := Sincos(x)
105 ss := -s - c
106 cc := s - c
107
108
109 if x < MaxFloat64/2 {
110 z := Cos(x + x)
111 if s*c > 0 {
112 cc = z / ss
113 } else {
114 ss = z / cc
115 }
116 }
117
118
119
120
121 var z float64
122 if x > Two129 {
123 z = (1 / SqrtPi) * cc / Sqrt(x)
124 } else {
125 u := pone(x)
126 v := qone(x)
127 z = (1 / SqrtPi) * (u*cc - v*ss) / Sqrt(x)
128 }
129 if sign {
130 return -z
131 }
132 return z
133 }
134 if x < TwoM27 {
135 return 0.5 * x
136 }
137 z := x * x
138 r := z * (R00 + z*(R01+z*(R02+z*R03)))
139 s := 1.0 + z*(S01+z*(S02+z*(S03+z*(S04+z*S05))))
140 r *= x
141 z = 0.5*x + r/s
142 if sign {
143 return -z
144 }
145 return z
146 }
147
148
149
150
151
152
153
154
155
156 func Y1(x float64) float64 {
157 const (
158 TwoM54 = 1.0 / (1 << 54)
159 Two129 = 1 << 129
160 U00 = -1.96057090646238940668e-01
161 U01 = 5.04438716639811282616e-02
162 U02 = -1.91256895875763547298e-03
163 U03 = 2.35252600561610495928e-05
164 U04 = -9.19099158039878874504e-08
165 V00 = 1.99167318236649903973e-02
166 V01 = 2.02552581025135171496e-04
167 V02 = 1.35608801097516229404e-06
168 V03 = 6.22741452364621501295e-09
169 V04 = 1.66559246207992079114e-11
170 )
171
172 switch {
173 case x < 0 || IsNaN(x):
174 return NaN()
175 case IsInf(x, 1):
176 return 0
177 case x == 0:
178 return Inf(-1)
179 }
180
181 if x >= 2 {
182 s, c := Sincos(x)
183 ss := -s - c
184 cc := s - c
185
186
187 if x < MaxFloat64/2 {
188 z := Cos(x + x)
189 if s*c > 0 {
190 cc = z / ss
191 } else {
192 ss = z / cc
193 }
194 }
195
196
197
198
199
200
201
202
203
204
205
206 var z float64
207 if x > Two129 {
208 z = (1 / SqrtPi) * ss / Sqrt(x)
209 } else {
210 u := pone(x)
211 v := qone(x)
212 z = (1 / SqrtPi) * (u*ss + v*cc) / Sqrt(x)
213 }
214 return z
215 }
216 if x <= TwoM54 {
217 return -(2 / Pi) / x
218 }
219 z := x * x
220 u := U00 + z*(U01+z*(U02+z*(U03+z*U04)))
221 v := 1 + z*(V00+z*(V01+z*(V02+z*(V03+z*V04))))
222 return x*(u/v) + (2/Pi)*(J1(x)*Log(x)-1/x)
223 }
224
225
226
227
228
229
230
231
232
233
234
235 var p1R8 = [6]float64{
236 0.00000000000000000000e+00,
237 1.17187499999988647970e-01,
238 1.32394806593073575129e+01,
239 4.12051854307378562225e+02,
240 3.87474538913960532227e+03,
241 7.91447954031891731574e+03,
242 }
243 var p1S8 = [5]float64{
244 1.14207370375678408436e+02,
245 3.65093083420853463394e+03,
246 3.69562060269033463555e+04,
247 9.76027935934950801311e+04,
248 3.08042720627888811578e+04,
249 }
250
251
252 var p1R5 = [6]float64{
253 1.31990519556243522749e-11,
254 1.17187493190614097638e-01,
255 6.80275127868432871736e+00,
256 1.08308182990189109773e+02,
257 5.17636139533199752805e+02,
258 5.28715201363337541807e+02,
259 }
260 var p1S5 = [5]float64{
261 5.92805987221131331921e+01,
262 9.91401418733614377743e+02,
263 5.35326695291487976647e+03,
264 7.84469031749551231769e+03,
265 1.50404688810361062679e+03,
266 }
267
268
269 var p1R3 = [6]float64{
270 3.02503916137373618024e-09,
271 1.17186865567253592491e-01,
272 3.93297750033315640650e+00,
273 3.51194035591636932736e+01,
274 9.10550110750781271918e+01,
275 4.85590685197364919645e+01,
276 }
277 var p1S3 = [5]float64{
278 3.47913095001251519989e+01,
279 3.36762458747825746741e+02,
280 1.04687139975775130551e+03,
281 8.90811346398256432622e+02,
282 1.03787932439639277504e+02,
283 }
284
285
286 var p1R2 = [6]float64{
287 1.07710830106873743082e-07,
288 1.17176219462683348094e-01,
289 2.36851496667608785174e+00,
290 1.22426109148261232917e+01,
291 1.76939711271687727390e+01,
292 5.07352312588818499250e+00,
293 }
294 var p1S2 = [5]float64{
295 2.14364859363821409488e+01,
296 1.25290227168402751090e+02,
297 2.32276469057162813669e+02,
298 1.17679373287147100768e+02,
299 8.36463893371618283368e+00,
300 }
301
302 func pone(x float64) float64 {
303 var p *[6]float64
304 var q *[5]float64
305 if x >= 8 {
306 p = &p1R8
307 q = &p1S8
308 } else if x >= 4.5454 {
309 p = &p1R5
310 q = &p1S5
311 } else if x >= 2.8571 {
312 p = &p1R3
313 q = &p1S3
314 } else if x >= 2 {
315 p = &p1R2
316 q = &p1S2
317 }
318 z := 1 / (x * x)
319 r := p[0] + z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))))
320 s := 1.0 + z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))))
321 return 1 + r/s
322 }
323
324
325
326
327
328
329
330
331
332
333
334 var q1R8 = [6]float64{
335 0.00000000000000000000e+00,
336 -1.02539062499992714161e-01,
337 -1.62717534544589987888e+01,
338 -7.59601722513950107896e+02,
339 -1.18498066702429587167e+04,
340 -4.84385124285750353010e+04,
341 }
342 var q1S8 = [6]float64{
343 1.61395369700722909556e+02,
344 7.82538599923348465381e+03,
345 1.33875336287249578163e+05,
346 7.19657723683240939863e+05,
347 6.66601232617776375264e+05,
348 -2.94490264303834643215e+05,
349 }
350
351
352 var q1R5 = [6]float64{
353 -2.08979931141764104297e-11,
354 -1.02539050241375426231e-01,
355 -8.05644828123936029840e+00,
356 -1.83669607474888380239e+02,
357 -1.37319376065508163265e+03,
358 -2.61244440453215656817e+03,
359 }
360 var q1S5 = [6]float64{
361 8.12765501384335777857e+01,
362 1.99179873460485964642e+03,
363 1.74684851924908907677e+04,
364 4.98514270910352279316e+04,
365 2.79480751638918118260e+04,
366 -4.71918354795128470869e+03,
367 }
368
369
370 var q1R3 = [6]float64{
371 -5.07831226461766561369e-09,
372 -1.02537829820837089745e-01,
373 -4.61011581139473403113e+00,
374 -5.78472216562783643212e+01,
375 -2.28244540737631695038e+02,
376 -2.19210128478909325622e+02,
377 }
378 var q1S3 = [6]float64{
379 4.76651550323729509273e+01,
380 6.73865112676699709482e+02,
381 3.38015286679526343505e+03,
382 5.54772909720722782367e+03,
383 1.90311919338810798763e+03,
384 -1.35201191444307340817e+02,
385 }
386
387
388 var q1R2 = [6]float64{
389 -1.78381727510958865572e-07,
390 -1.02517042607985553460e-01,
391 -2.75220568278187460720e+00,
392 -1.96636162643703720221e+01,
393 -4.23253133372830490089e+01,
394 -2.13719211703704061733e+01,
395 }
396 var q1S2 = [6]float64{
397 2.95333629060523854548e+01,
398 2.52981549982190529136e+02,
399 7.57502834868645436472e+02,
400 7.39393205320467245656e+02,
401 1.55949003336666123687e+02,
402 -4.95949898822628210127e+00,
403 }
404
405 func qone(x float64) float64 {
406 var p, q *[6]float64
407 if x >= 8 {
408 p = &q1R8
409 q = &q1S8
410 } else if x >= 4.5454 {
411 p = &q1R5
412 q = &q1S5
413 } else if x >= 2.8571 {
414 p = &q1R3
415 q = &q1S3
416 } else if x >= 2 {
417 p = &q1R2
418 q = &q1S2
419 }
420 z := 1 / (x * x)
421 r := p[0] + z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))))
422 s := 1 + z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))))
423 return (0.375 + r/s) / x
424 }
425
View as plain text