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