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