FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot/src/amos_airy.c at master · gnuplot/gnuplot · GitHub
gnuplot
gnuplot
Repository navigation
Code
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot
/
src
/
amos_airy.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
467 lines (387 loc) · 12.5 KB
Breadcrumbs
gnuplot
/
src
/
amos_airy.c
Copy path
File metadata and controls
467 lines (387 loc) · 12.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/*
* Bessel functions and related special functions.
* The routines in this file are wrappers for implementations in an
* external library detected at configuration/build time.
* AMOS - A Portable Package for Bessel Functions of a Complex Argument
* and Nonnegative Order
* D. E. Amos, Sandia National Laboratories, SAND85-1018 (1985)
* The amos routines have been packaged by various projects in slightly
* different ways.
* The zairy_() routine (note Fortran naming and parameter passing conventions)
* is found, for example, in libopenspecfun. We use it to calculate Ai(z).
* Similarly zbiry_() is used to calcualte Bi(z).
*
* The cexint_() routine is also from the AMOS collection, but is not part
* of the Bessel function subset and not included in libopenspecfun.
* I could not find source for a version of the source that splits the
* real and imaginary parts of the arguments as with the zxxxx.f Bessel
* routines; this one accepts and returns a CMPLX argument rather than separate
* real and imaginary parts.
* D. E. Amos, ALGORITHM 683 A Portable FORTRAN Subroutine
* for Exponential Integrals of a Complex Argument
* ACM Trans. Math. Software 16:178-182 (1990)
*
* IERR codes from libamos Bessel functions
* 0 no error
* 1 input error, no computation
* 2 overflow predicted from input value
* 3 overflow from computation
* 4 input value out of range, no computation
* 5 other error
* IERR codes from cexint
* 2 underflow
* 4-5 argument reduction caused loss of significance
* 6 failed to converge
*
* Ethan A Merritt - March 2020
*/
#include
"eval.h"
#include
"stdfn.h"
/* for not_a_number() */
#ifdef
HAVE_AMOS
extern
void
zairy_
(
double
*
zr
,
double
*
zi
,
int32_t
*
id
,
int32_t
*
kode
,
double
*
air
,
double
*
aii
,
int32_t
*
underflow
,
int32_t
*
ierr
);
extern
void
zbiry_
(
double
*
zr
,
double
*
zi
,
int32_t
*
id
,
int32_t
*
kode
,
double
*
air
,
double
*
aii
,
int32_t
*
ierr
);
extern
void
zbesh_
(
double
*
zr
,
double
*
zi
,
double
*
nu
,
int32_t
*
kode
,
int32_t
*
kind
,
int32_t
*
length
,
double
*
zbr
,
double
*
zbi
,
int32_t
*
underflow
,
int32_t
*
ierr
);
extern
void
zbesi_
(
double
*
zr
,
double
*
zi
,
double
*
nu
,
int32_t
*
kode
,
int32_t
*
length
,
double
*
zbr
,
double
*
zbi
,
int32_t
*
underflow
,
int32_t
*
ierr
);
extern
void
zbesj_
(
double
*
zr
,
double
*
zi
,
double
*
nu
,
int32_t
*
kode
,
int32_t
*
length
,
double
*
zbr
,
double
*
zbi
,
int32_t
*
underflow
,
int32_t
*
ierr
);
extern
void
zbesk_
(
double
*
zr
,
double
*
zi
,
double
*
nu
,
int32_t
*
kode
,
int32_t
*
length
,
double
*
zbr
,
double
*
zbi
,
int32_t
*
underflow
,
int32_t
*
ierr
);
extern
void
zbesy_
(
double
*
zr
,
double
*
zi
,
double
*
nu
,
int32_t
*
kode
,
int32_t
*
length
,
double
*
zbr
,
double
*
zbi
,
int32_t
*
underflow
,
double
*
wr
,
double
*
wi
,
int32_t
*
ierr
);
#if
defined(
HAVE_CEXINT
)
&&
defined(
HAVE_COMPLEX_H
)
#include
<complex.h>
#include
<util.h>
/* for int_error() */
extern
void
cexint_
(
double
complex
*
z
,
int32_t
*
norder
,
int32_t
*
kode
,
double
*
tol
,
int32_t
*
length
,
double
complex
*
cy
,
int32_t
*
ierr
);
#endif
void
f_amos_Ai
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
,
ai
;
int32_t
id
,
kode
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
pop
(
&
a
);
id
=
0
;
/* 0 = Ai 1 = delAi/delZ */
kode
=
1
;
/* 1 = unscaled 2 = scaled */
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
/* Fortran calling conventions! */
zairy_
(
&
z
.
real
,
&
z
.
imag
,
&
id
,
&
kode
,
&
ai
.
real
,
&
ai
.
imag
,
&
underflow
,
&
ierr
);
if
(
underflow
!=
0
||
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zairy( {%.3f, %.3f} ): underflow = %d ierr = %d\n"
,
z
.
real
,
z
.
imag
,
underflow
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
ai
.
real
,
ai
.
imag
);
}
push
(
&
a
);
}
void
f_amos_Bi
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
,
bi
;
int32_t
id
,
kode
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
pop
(
&
a
);
id
=
0
;
/* 0 = Bi 1 = delBi/delZ */
kode
=
1
;
/* 1 = unscaled 2 = scaled */
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
/* Fortran calling conventions! */
zbiry_
(
&
z
.
real
,
&
z
.
imag
,
&
id
,
&
kode
,
&
bi
.
real
,
&
bi
.
imag
,
&
ierr
);
if
(
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zbiry( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
bi
.
real
,
bi
.
imag
);
}
push
(
&
a
);
}
/*
* Modified Bessel function of the second kind K_nu(z)
* val = BesselK( nu, z )
* The underlying libamos routine besk fills in an array of values
* val[j] corresponding to a sequence functions BesselK( nu+j, z )
* but we ask for only the j=0 case.
*/
#define
NJ
1
void
f_amos_BesselK
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
;
struct
cmplx
Bk
[
NJ
];
double
nu
;
int32_t
kode
,
length
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
/* ... unpack arguments ... */
pop
(
&
a
);
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
nu
=
real
(
pop
(
&
a
));
kode
=
1
;
/* 1 = unscaled 2 = scaled */
length
=
NJ
;
/* number of members in the returned sequence of functions */
/* Fortran calling conventions! */
zbesk_
(
&
z
.
real
,
&
z
.
imag
,
&
nu
,
&
kode
,
&
length
,
&
Bk
[
0
].
real
,
&
Bk
[
0
].
imag
,
&
underflow
,
&
ierr
);
if
(
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zbesk( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
Bk
[
0
].
real
,
Bk
[
0
].
imag
);
}
push
(
&
a
);
}
/*
* Hankel functions of the first and second kinds
* val = Hankel1( nu, z ) = Jnu(z) + iYnu(z)
* val = Hankel2( nu, z ) = Jnu(z) - iYnu(z)
* The underlying libamos routine besi fills in an array of values
* val[j] corresponding to a sequence functions Hankel( kind, nu+j, z )
* but we ask for only the j=0 case.
*/
void
f_amos_Hankel
(
int
k
,
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
;
struct
cmplx
H
[
NJ
];
double
nu
;
int32_t
kode
,
kind
,
length
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
/* ... unpack arguments ... */
pop
(
&
a
);
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
nu
=
real
(
pop
(
&
a
));
kode
=
1
;
/* 1 = unscaled 2 = scaled */
kind
=
k
;
/* 1 = first kind, 2 = second kind */
length
=
NJ
;
/* number of members in the returned sequence of functions */
/* Fortran calling conventions! */
zbesh_
(
&
z
.
real
,
&
z
.
imag
,
&
nu
,
&
kode
,
&
kind
,
&
length
,
&
H
[
0
].
real
,
&
H
[
0
].
imag
,
&
underflow
,
&
ierr
);
if
(
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zbesh( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
H
[
0
].
real
,
H
[
0
].
imag
);
}
push
(
&
a
);
}
void
f_Hankel1
(
union
argument
*
arg
) {
f_amos_Hankel
(
1
,
arg
); }
void
f_Hankel2
(
union
argument
*
arg
) {
f_amos_Hankel
(
2
,
arg
); }
/*
* Modified Bessel function of the first kind I_nu(z)
* with complex argument z.
* val = BesselI( nu, z )
* The underlying libamos routine besi fills in an array of values
* val[j] corresponding to a sequence functions BesselI( nu+j, z )
* but we ask for only the j=0 case.
*/
void
f_amos_BesselI
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
;
struct
cmplx
Bi
[
NJ
];
double
nu
;
int32_t
kode
,
length
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
/* ... unpack arguments ... */
pop
(
&
a
);
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
nu
=
real
(
pop
(
&
a
));
kode
=
1
;
/* 1 = unscaled 2 = scaled */
length
=
NJ
;
/* number of members in the returned sequence of functions */
/* Fortran calling conventions! */
zbesi_
(
&
z
.
real
,
&
z
.
imag
,
&
nu
,
&
kode
,
&
length
,
&
Bi
[
0
].
real
,
&
Bi
[
0
].
imag
,
&
underflow
,
&
ierr
);
if
(
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zbesi( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
Bi
[
0
].
real
,
Bi
[
0
].
imag
);
}
push
(
&
a
);
}
/*
* Modified Bessel function of the first kind J_nu(z)
* with complex argument z.
* val = BesselJ( nu, z )
* The underlying libamos routine besi fills in an array of values
* val[j] corresponding to a sequence functions BesselJ( nu+j, z )
* but we ask for only the j=0 case.
*/
void
f_amos_BesselJ
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
;
struct
cmplx
Bj
[
NJ
];
double
nu
;
int32_t
kode
,
length
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
/* ... unpack arguments ... */
pop
(
&
a
);
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
nu
=
real
(
pop
(
&
a
));
kode
=
1
;
/* 1 = unscaled 2 = scaled */
length
=
NJ
;
/* number of members in the returned sequence of functions */
/* Fortran calling conventions! */
zbesj_
(
&
z
.
real
,
&
z
.
imag
,
&
nu
,
&
kode
,
&
length
,
&
Bj
[
0
].
real
,
&
Bj
[
0
].
imag
,
&
underflow
,
&
ierr
);
if
(
ierr
!=
0
) {
FPRINTF
((
stderr
,
"zbesj( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
Bj
[
0
].
real
,
Bj
[
0
].
imag
);
}
push
(
&
a
);
}
/*
* Modified Bessel function of the second kind Y_nu(z)
* with complex argument z.
* val = BesselY( nu, z )
* The underlying libamos routine besi fills in an array of values
* val[j] corresponding to a sequence functions BesselJ( nu+j, z )
* but we ask for only the j=0 case.
*/
void
f_amos_BesselY
(
union
argument
*
arg
)
{
struct
value
a
;
struct
cmplx
z
;
struct
cmplx
By
[
NJ
];
double
WorkR
[
NJ
],
WorkI
[
NJ
];
/* Scratch space for zbesy_ */
double
nu
;
int32_t
kode
,
length
,
underflow
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
/* ... unpack arguments ... */
pop
(
&
a
);
if
(
a
.
type
==
INTGR
) {
z
.
real
=
a
.
v
.
int_val
;
z
.
imag
=
0
;
}
else
{
z
.
real
=
a
.
v
.
cmplx_val
.
real
;
z
.
imag
=
a
.
v
.
cmplx_val
.
imag
;
}
nu
=
real
(
pop
(
&
a
));
kode
=
1
;
/* 1 = unscaled 2 = scaled */
length
=
NJ
;
/* number of members in the returned sequence of functions */
/* Fortran calling conventions! */
zbesy_
(
&
z
.
real
,
&
z
.
imag
,
&
nu
,
&
kode
,
&
length
,
&
By
[
0
].
real
,
&
By
[
0
].
imag
,
&
underflow
,
&
WorkR
[
0
],
&
WorkI
[
0
],
&
ierr
);
if
(
ierr
!=
0
) {
fprintf
(
stderr
,
"zbesy( {%.3f, %.3f} ): ierr = %d\n"
,
z
.
real
,
z
.
imag
,
ierr
);
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
By
[
0
].
real
,
By
[
0
].
imag
);
}
push
(
&
a
);
}
#if
defined(
HAVE_CEXINT
)
&&
defined(
HAVE_COMPLEX_H
)
void
f_amos_cexint
(
union
argument
*
arg
)
{
struct
value
a
;
double
complex
z
,
cy
;
double
tolerance
;
int32_t
norder
,
kode
,
length
,
ierr
;
(
void
)
arg
;
/* avoid -Wunused warning */
pop
(
&
a
);
/* complex z */
kode
=
1
;
/* 1 = unscaled 2 = scaled */
length
=
NJ
;
/* number of members in the returned sequence of functions */
tolerance
=
1.e-8
;
/* FIXME: not sure what is reasonable to ask for */
if
(
a
.
type
==
INTGR
) {
z
=
(
double
)
a
.
v
.
int_val
;
}
else
{
z
=
a
.
v
.
cmplx_val
.
real
+
I
*
a
.
v
.
cmplx_val
.
imag
;
}
if
(
carg
(
z
)
<
-
M_PI
||
carg
(
z
)
>
M_PI
)
int_error
(
NO_CARET
,
"cexint requires arg(z) in [-pi:pi]"
);
pop
(
&
a
);
/* integer norder */
if
(
a
.
type
==
INTGR
)
norder
=
a
.
v
.
int_val
;
if
(
a
.
type
!=
INTGR
||
norder
<
0
)
int_error
(
NO_CARET
,
"cexint requires integer n >= 0"
);
/* Special case for n = 0.
* E0(z) = exp(-z)/z by definition, so just return that
*/
if
(
norder
==
0
) {
cy
=
cexp
(
-
z
)/
z
;
push
(
Gcomplex
(
&
a
,
creal
(
cy
),
cimag
(
cy
)));
return
;
}
/* Fortran calling conventions! */
cexint_
(
&
z
,
&
norder
,
&
kode
,
&
tolerance
,
&
length
,
&
cy
,
&
ierr
);
/* ierr == 2 means underflow, in which case cy has already been set to 0 */
if
(
ierr
==
1
||
ierr
>
2
) {
FPRINTF
((
stderr
,
"f_amos_cexint( %d, {%g, %g} ): ierr = %d\n"
,
norder
,
creal
(
z
),
cimag
(
z
),
ierr
));
undefined
=
TRUE;
Gcomplex
(
&
a
,
not_a_number
(),
0.0
);
}
else
{
Gcomplex
(
&
a
,
creal
(
cy
),
cimag
(
cy
));
}
push
(
&
a
);
}
#endif
#undef
NJ
#endif
/* HAVE_AMOS */
Back
|
FazBrowse Home
|
New Git URL