Source file
src/math/j0.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
76
77 func J0(x float64) float64 {
78 const (
79 Huge = 1e300
80 TwoM27 = 1.0 / (1 << 27)
81 TwoM13 = 1.0 / (1 << 13)
82 Two129 = 1 << 129
83
84 R02 = 1.56249999999999947958e-02
85 R03 = -1.89979294238854721751e-04
86 R04 = 1.82954049532700665670e-06
87 R05 = -4.61832688532103189199e-09
88 S01 = 1.56191029464890010492e-02
89 S02 = 1.16926784663337450260e-04
90 S03 = 5.13546550207318111446e-07
91 S04 = 1.16614003333790000205e-09
92 )
93
94 switch {
95 case IsNaN(x):
96 return x
97 case IsInf(x, 0):
98 return 0
99 case x == 0:
100 return 1
101 }
102
103 x = Abs(x)
104 if x >= 2 {
105 s, c := Sincos(x)
106 ss := s - c
107 cc := s + c
108
109
110 if x < MaxFloat64/2 {
111 z := -Cos(x + x)
112 if s*c < 0 {
113 cc = z / ss
114 } else {
115 ss = z / cc
116 }
117 }
118
119
120
121
122 var z float64
123 if x > Two129 {
124 z = (1 / SqrtPi) * cc / Sqrt(x)
125 } else {
126 u := pzero(x)
127 v := qzero(x)
128 z = (1 / SqrtPi) * (u*cc - v*ss) / Sqrt(x)
129 }
130 return z
131 }
132 if x < TwoM13 {
133 if x < TwoM27 {
134 return 1
135 }
136 return 1 - 0.25*x*x
137 }
138 z := x * x
139 r := z * (R02 + z*(R03+z*(R04+z*R05)))
140 s := 1 + z*(S01+z*(S02+z*(S03+z*S04)))
141 if x < 1 {
142 return 1 + z*(-0.25+(r/s))
143 }
144 u := 0.5 * x
145 return (1+u)*(1-u) + z*(r/s)
146 }
147
148
149
150
151
152
153
154
155
156 func Y0(x float64) float64 {
157 const (
158 TwoM27 = 1.0 / (1 << 27)
159 Two129 = 1 << 129
160 U00 = -7.38042951086872317523e-02
161 U01 = 1.76666452509181115538e-01
162 U02 = -1.38185671945596898896e-02
163 U03 = 3.47453432093683650238e-04
164 U04 = -3.81407053724364161125e-06
165 U05 = 1.95590137035022920206e-08
166 U06 = -3.98205194132103398453e-11
167 V01 = 1.27304834834123699328e-02
168 V02 = 7.60068627350353253702e-05
169 V03 = 2.59150851840457805467e-07
170 V04 = 4.41110311332675467403e-10
171 )
172
173 switch {
174 case x < 0 || IsNaN(x):
175 return NaN()
176 case IsInf(x, 1):
177 return 0
178 case x == 0:
179 return Inf(-1)
180 }
181
182 if x >= 2 {
183
184
185
186
187
188
189
190
191
192
193
194
195 s, c := Sincos(x)
196 ss := s - c
197 cc := s + c
198
199
200
201
202
203 if x < MaxFloat64/2 {
204 z := -Cos(x + x)
205 if s*c < 0 {
206 cc = z / ss
207 } else {
208 ss = z / cc
209 }
210 }
211 var z float64
212 if x > Two129 {
213 z = (1 / SqrtPi) * ss / Sqrt(x)
214 } else {
215 u := pzero(x)
216 v := qzero(x)
217 z = (1 / SqrtPi) * (u*ss + v*cc) / Sqrt(x)
218 }
219 return z
220 }
221 if x <= TwoM27 {
222 return U00 + (2/Pi)*Log(x)
223 }
224 z := x * x
225 u := U00 + z*(U01+z*(U02+z*(U03+z*(U04+z*(U05+z*U06)))))
226 v := 1 + z*(V01+z*(V02+z*(V03+z*V04)))
227 return u/v + (2/Pi)*J0(x)*Log(x)
228 }
229
230
231
232
233
234
235
236
237
238
239
240 var p0R8 = [6]float64{
241 0.00000000000000000000e+00,
242 -7.03124999999900357484e-02,
243 -8.08167041275349795626e+00,
244 -2.57063105679704847262e+02,
245 -2.48521641009428822144e+03,
246 -5.25304380490729545272e+03,
247 }
248 var p0S8 = [5]float64{
249 1.16534364619668181717e+02,
250 3.83374475364121826715e+03,
251 4.05978572648472545552e+04,
252 1.16752972564375915681e+05,
253 4.76277284146730962675e+04,
254 }
255
256
257 var p0R5 = [6]float64{
258 -1.14125464691894502584e-11,
259 -7.03124940873599280078e-02,
260 -4.15961064470587782438e+00,
261 -6.76747652265167261021e+01,
262 -3.31231299649172967747e+02,
263 -3.46433388365604912451e+02,
264 }
265 var p0S5 = [5]float64{
266 6.07539382692300335975e+01,
267 1.05125230595704579173e+03,
268 5.97897094333855784498e+03,
269 9.62544514357774460223e+03,
270 2.40605815922939109441e+03,
271 }
272
273
274 var p0R3 = [6]float64{
275 -2.54704601771951915620e-09,
276 -7.03119616381481654654e-02,
277 -2.40903221549529611423e+00,
278 -2.19659774734883086467e+01,
279 -5.80791704701737572236e+01,
280 -3.14479470594888503854e+01,
281 }
282 var p0S3 = [5]float64{
283 3.58560338055209726349e+01,
284 3.61513983050303863820e+02,
285 1.19360783792111533330e+03,
286 1.12799679856907414432e+03,
287 1.73580930813335754692e+02,
288 }
289
290
291 var p0R2 = [6]float64{
292 -8.87534333032526411254e-08,
293 -7.03030995483624743247e-02,
294 -1.45073846780952986357e+00,
295 -7.63569613823527770791e+00,
296 -1.11931668860356747786e+01,
297 -3.23364579351335335033e+00,
298 }
299 var p0S2 = [5]float64{
300 2.22202997532088808441e+01,
301 1.36206794218215208048e+02,
302 2.70470278658083486789e+02,
303 1.53875394208320329881e+02,
304 1.46576176948256193810e+01,
305 }
306
307 func pzero(x float64) float64 {
308 var p *[6]float64
309 var q *[5]float64
310 if x >= 8 {
311 p = &p0R8
312 q = &p0S8
313 } else if x >= 4.5454 {
314 p = &p0R5
315 q = &p0S5
316 } else if x >= 2.8571 {
317 p = &p0R3
318 q = &p0S3
319 } else if x >= 2 {
320 p = &p0R2
321 q = &p0S2
322 }
323 z := 1 / (x * x)
324 r := p[0] + z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))))
325 s := 1 + z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))))
326 return 1 + r/s
327 }
328
329
330
331
332
333
334
335
336
337
338
339 var q0R8 = [6]float64{
340 0.00000000000000000000e+00,
341 7.32421874999935051953e-02,
342 1.17682064682252693899e+01,
343 5.57673380256401856059e+02,
344 8.85919720756468632317e+03,
345 3.70146267776887834771e+04,
346 }
347 var q0S8 = [6]float64{
348 1.63776026895689824414e+02,
349 8.09834494656449805916e+03,
350 1.42538291419120476348e+05,
351 8.03309257119514397345e+05,
352 8.40501579819060512818e+05,
353 -3.43899293537866615225e+05,
354 }
355
356
357 var q0R5 = [6]float64{
358 1.84085963594515531381e-11,
359 7.32421766612684765896e-02,
360 5.83563508962056953777e+00,
361 1.35111577286449829671e+02,
362 1.02724376596164097464e+03,
363 1.98997785864605384631e+03,
364 }
365 var q0S5 = [6]float64{
366 8.27766102236537761883e+01,
367 2.07781416421392987104e+03,
368 1.88472887785718085070e+04,
369 5.67511122894947329769e+04,
370 3.59767538425114471465e+04,
371 -5.35434275601944773371e+03,
372 }
373
374
375 var q0R3 = [6]float64{
376 4.37741014089738620906e-09,
377 7.32411180042911447163e-02,
378 3.34423137516170720929e+00,
379 4.26218440745412650017e+01,
380 1.70808091340565596283e+02,
381 1.66733948696651168575e+02,
382 }
383 var q0S3 = [6]float64{
384 4.87588729724587182091e+01,
385 7.09689221056606015736e+02,
386 3.70414822620111362994e+03,
387 6.46042516752568917582e+03,
388 2.51633368920368957333e+03,
389 -1.49247451836156386662e+02,
390 }
391
392
393 var q0R2 = [6]float64{
394 1.50444444886983272379e-07,
395 7.32234265963079278272e-02,
396 1.99819174093815998816e+00,
397 1.44956029347885735348e+01,
398 3.16662317504781540833e+01,
399 1.62527075710929267416e+01,
400 }
401 var q0S2 = [6]float64{
402 3.03655848355219184498e+01,
403 2.69348118608049844624e+02,
404 8.44783757595320139444e+02,
405 8.82935845112488550512e+02,
406 2.12666388511798828631e+02,
407 -5.31095493882666946917e+00,
408 }
409
410 func qzero(x float64) float64 {
411 var p, q *[6]float64
412 if x >= 8 {
413 p = &q0R8
414 q = &q0S8
415 } else if x >= 4.5454 {
416 p = &q0R5
417 q = &q0S5
418 } else if x >= 2.8571 {
419 p = &q0R3
420 q = &q0S3
421 } else if x >= 2 {
422 p = &q0R2
423 q = &q0S2
424 }
425 z := 1 / (x * x)
426 r := p[0] + z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))))
427 s := 1 + z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))))
428 return (-0.125 + r/s) / x
429 }
430
View as plain text