-
Notifications
You must be signed in to change notification settings - Fork 0
/
bessel-library.hpp
11155 lines (10679 loc) · 341 KB
/
bessel-library.hpp
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Bessel library: A C++ library with routines to evaluate Bessel functions of real or complex arguments (https://github.com/jodesarro/bessel-library)
// MIT License Copyright (c) 2021 Jhonas Olivati de Sarro (https://github.com/jodesarro/bessel-library/blob/main/LICENSE)
// See Refs. [[1–3](#references)] for more information concerning Bessel functions and their computation.
//-v------------------------------------------------------------------------
// CHANGELOG
// 0.1.3 Jun 09, 2024 (current version)
// - Inclusion of Hankel functions cyl_h1 and cyl_h2 for integer or real orders and real or complex arguments.
// - Inclusion of Airy functions airy_ai and airy_bi for real or complex arguments.
// - Functions mod_i and mod_k were consistently renamed to cyl_i and cyl_k.
// - The flags now print the number of components set to zero due to underflow.
// - Routines zairy_, zbesh_, zbesj_, zbesy_, zbesi_, zbesk_ and zbiry_, based on version 930101 of D. E. Amos routines (https://doi.org/10.1145/7921.214331, ACM domain)
// were changed (reverted) to be based on slatec ([3], public domain) versions to avoid copyright conflicts between ACM and MIT licenses and permissions. The
// versions 0.1.1 and 0.1.2 of this code, and github commits related to them, shall be deleted and must be disconsidered and discarded by all users.
// - Revision and reorganization of all slatec functions.
// - Creation of functions d1mach and i1mach to make easier to compare with original slatec versions.
// 0.1.2 Jun 06, 2024
// - Inclusion of modified Bessel functions mod_i and mod_k for integer or real orders and real or complex arguments.
// 0.1.1 May 27, 2024
// - Routines zairy_, zbesh_, zbesj_, and zbesy_, updated to the version 930101 of D. E. Amos routines (https://doi.org/10.1145/7921.214331).
// - Inclusion of routines zbesi_, zbesk_, zbiry_ accordingly to version 930101 of D. E. Amos routines (https://doi.org/10.1145/7921.214331).
// - Inclusion of C++ callable functions to overload cyl_j and cyl_y for real arguments.
// - Static declarations removed for thread safety.
// 0.1.0 May 26, 2024
// - Routines for cyl_j based on Ref. [2] were replaced by D. E. Amos Fortran 77 routines of SLATEC library [3].
// - D. E. Amos routines zairy_.f, zbesh_.f, zbesj_.f, zbesy_.f, and all their dependencies, were converted to C using f2c (Availabe at: https://www.netlib.org/f2c/. Accessed: May 25, 2024).
// - Replacement of all functions d1mach amd i1mach by C macros of float.h.
// - Corrections of the translated f2c version and elimination of external dependencies.
// - Reorganization of the whole code to be easily callable from C++.
// - Inclusion of cylindrical Bessel functions of the second kind (or Neumann functions) cyl_y.
// - Calculation of negative orders for cyl_j and cyl_y through Eq. (5.5.4) of Ref. [2].
// - Now, cyl, Bessel functions of the first and second kinds, cyl_j and cyl_y, are available also for real (positive or negative) orders.
// - Inclusion of cyl_j and cyl_y that returns an array of an int sequence of orders.
// - Inclusion of parameters to print flag messages, and to return scaled versions of cyl_j and cyl_y.
// - Inclusion of namespace bessel::slatec to call all slatec routines.
// 0.0.0 until May 12, 2024
// - Routines for cylindrical Bessel functions of the first kind and int order written based on Ref. [2].
// CHANGELOG
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// REFERENCES
// [1] M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions With Formulas,
// Graphs, and Mathematical Tables. Washington, D. C.: National Bureau of Standards, 1972.
// [2] S. Zhang and J. Jin, Computation of Special Functions. New York: Wiley, 1996.
// [3] SLATEC Common Mathematical Library, Version 4.1, July 1993. Comprehensive software library containing
// over 1400 general purpose mathematical and statistical routines written in Fortran 77. Available
// at https://www.netlib.org/slatec/ (Accessed: May 25, 2024).
// REFERENCES
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// FORTRAN TRANSLATED TO C CODE
//-v------------------------------------------------------------------------
// C LIBRARIES
#define _USE_MATH_DEFINES // For M_PI, and other constant macros.
#include <math.h> // For functions such as sin(), cos(), abs(), ... .
#include <float.h> // For macro constants such as DBL_MIN, DBL_MAX_EXP, ... .
// C LIBRARIES
//-^------------------------------------------------------------------------
namespace bessel::slatec
{
//-v------------------------------------------------------------------------
// MAIN D. E. AMOS (SLATEC) ROUTINES DECLARATIONS
int zbesj_(double *zr, double *zi, double *fnu, int *kode, int *n, double *cyr, double *cyi, int *nz, int *ierr);
int zbesy_(double *zr, double *zi, double *fnu, int *kode, int *n, double *cyr, double *cyi, int *nz, double *cwrkr, double *cwrki, int *ierr);
int zbesh_(double *zr, double *zi, double *fnu, int *kode, int *m, int *n, double *cyr, double *cyi, int *nz, int *ierr);
int zbesi_(double *zr, double *zi, double *fnu, int *kode, int *n, double *cyr, double *cyi, int *nz, int *ierr);
int zbesk_(double *zr, double *zi, double *fnu, int *kode, int *n, double *cyr, double *cyi, int *nz, int *ierr);
int zairy_(double *zr, double *zi, int *id, int *kode, double *air, double *aii, int *nz, int *ierr);
int zbiry_(double *zr, double *zi, int *id, int *kode, double *bir, double *bii, int *ierr);
// MAIN D. E. AMOS (SLATEC) ROUTINES DECLARATIONS
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// DEPENDENCY AMOS/SLATEC ROUTINES DECLARATIONS
double zabs_(double *zr, double *zi);
int zexp_(double *ar, double *ai, double *br, double *bi);
int zdiv_(double *ar, double *ai, double *br, double *bi, double *cr, double *ci);
int zsqrt_(double *ar, double *ai, double *br, double *bi);
int zlog_(double *ar, double *ai, double *br, double *bi, int *ierr);
int zs1s2_(double *zrr, double *zri, double *s1r, double *s1i, double *s2r, double *s2i, int *nz, double *ascle, double *alim, int *iuf);
int zasyi_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, double *rl, double *tol, double *elim, double *alim);
int zacai_(double *zr, double *zi, double *fnu, int *kode, int *mr, int *n, double *yr, double *yi, int *nz, double *rl, double *tol, double *elim, double *alim);
int zuni1_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, int *nlast, double *fnul, double *tol, double *elim, double *alim);
int zuni2_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, int *nlast, double *fnul, double *tol, double *elim, double *alim);
int zbuni_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, int *nui, int *nlast, double *fnul, double *tol, double *elim, double *alim);
int zmlri_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, double *tol);
int zmlt_(double *ar, double *ai, double *br, double *bi, double *cr, double *ci);
double dgamln_(double *z__, int *ierr);
int zseri_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, double *tol, double *elim, double *alim);
int zunik_(double *zrr, double *zri, double *fnu, int *ikflg, int *ipmtr, double *tol, int *init, double *phir, double *phii, double *zeta1r, double *zeta1i, double *zeta2r, double *zeta2i, double *sumr, double *sumi, double *cwrkr, double *cwrki);
int zunhj_(double *zr, double *zi, double *fnu, int *ipmtr, double *tol, double *phir, double *phii, double *argr, double *argi, double *zeta1r, double *zeta1i, double *zeta2r, double *zeta2i, double *asumr, double *asumi, double *bsumr, double *bsumi);
int zuchk_(double *yr, double *yi, int *nz, double *ascle, double *tol);
int zuoik_(double *zr, double *zi, double *fnu, int *kode, int *ikflg, int *n, double *yr, double *yi, int *nuf, double *tol, double *elim, double *alim);
int zbknu_(double *zr, double *zi, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, double *tol, double *elim, double *alim);
int zrati_(double *zr, double *zi, double *fnu, int *n, double *cyr, double *cyi, double *tol);
int zwrsk_(double *zrr, double *zri, double *fnu, int *kode, int *n, double *yr, double *yi, int *nz, double *cwr, double *cwi, double *tol, double *elim, double *alim);
int zbinu_(double *zr, double *zi, double *fnu, int *kode, int *n, double *cyr, double *cyi, int *nz, double *rl, double *fnul, double *tol, double *elim, double *alim);
int zshch_(double *zr, double *zi, double *cshr, double *cshi, double *cchr, double *cchi);
int zkscl_(double *zrr, double *zri, double *fnu, int *n, double *yr, double *yi, int *nz, double *rzr, double *rzi, double *ascle, double *tol, double *elim);
int zacon_(double *zr, double *zi, double *fnu, int *kode, int *mr, int *n, double *yr, double *yi, int *nz, double *rl, double *fnul, double *tol, double *elim, double *alim);
int zbunk_(double *zr, double *zi, double *fnu, int *kode, int *mr, int *n, double *yr, double *yi, int *nz, double *tol, double *elim, double *alim);
int zunk1_(double *zr, double *zi, double *fnu, int *kode, int *mr, int *n, double *yr, double *yi, int *nz, double *tol, double *elim, double *alim);
int zunk2_(double *zr, double *zi, double *fnu, int *kode, int *mr, int *n, double *yr, double *yi, int *nz, double *tol, double *elim, double *alim);
// DEPENDENCY AMOS/SLATEC ROUTINES DECLARATIONS
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// TABLE OF GLOBAL CONSTANT VALUES
int c__0 = 0;
int c__1 = 1;
int c__2 = 2;
int c__4 = 4;
int c__5 = 5;
int c__9 = 9;
int c__14 = 14;
int c__15 = 15;
int c__16 = 16;
double c_b10 = .5;
double c_b11 = 0.;
// TABLE OF GLOBAL CONSTANT VALUES
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// FUNCTIONS OF GLOBAL CONSTANT VALUES
double d1mach_(int *c__n)
{
switch(*c__n)
{
case 1:
return DBL_MIN; break;
case 2:
return DBL_MAX; break;
case 4:
return DBL_EPSILON; break;
case 5:
return log10(2.); break;
default:
return 0.; break;
}
}
int i1mach_(int *c__n)
{
switch(*c__n)
{
case 9:
return INT_MAX; break;
case 14:
return DBL_MANT_DIG; break;
case 15:
return -DBL_MIN_EXP; break;
case 16:
return DBL_MAX_EXP; break;
default:
return 0; break;
}
}
// FUNCTIONS OF GLOBAL CONSTANT VALUES
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// DEPENDENCY C ROUTINES
inline double max(double x, double y) { return((x) > (y) ? x : y); }
inline double min(double x, double y) { return((x) < (y) ? x : y); }
inline double d_sign(double *x, double *y) { return ((*y >= 0.) ? abs(*x) : -abs(*x)); }
inline double pow_dd(double *x, double *y) { return pow(*x,*y); }
// DEPENDENCY C ROUTINES
//-^------------------------------------------------------------------------
//-v------------------------------------------------------------------------
// DEPENDENCY AMOS/SLATEC ROUTINES ORIGINALLY TRANSLATED WITH F2C
/* zabs.f, zexp.f, zdiv.f, zsqrt.f, zlog.f,
zs1s2.f, zasyi.f, zacai.f, zuni1.f,
zuni2.f, zbuni.f, zmlri.f, zmlt.f, dgamln.f,
zseri.f, zunik.f, zunhj.f, zuchk.f, zuoik.f,
zbknu.f, zrati.f, zwrsk.f, zbinu.f, zshch.f,
zkscl.f, zacon.f, zbunk.f, zunk1.f, zunk2.f
-- translated by f2c (version 20100827).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
/* DECK ZABS */
/* Subroutine */
double zabs_(double *zr, double *zi)
{
/* System generated locals */
double ret_val;
/* Local variables */
double q, s, u, v;
/* ***BEGIN PROLOGUE ZABS */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and */
/* ZBIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (ZABS-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* ZABS COMPUTES THE ABSOLUTE VALUE OR MAGNITUDE OF A DOUBLE */
/* PRECISION COMPLEX VARIABLE CMPLX(ZR,ZI) */
/* ***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY */
/* ***ROUTINES CALLED (NONE) */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZABS */
/* ***FIRST EXECUTABLE STATEMENT ZABS */
u = abs(*zr);
v = abs(*zi);
s = u + v;
/* ----------------------------------------------------------------------- */
/* S*1.0D0 MAKES AN UNNORMALIZED UNDERFLOW ON CDC MACHINES INTO A */
/* TRUE FLOATING ZERO */
/* ----------------------------------------------------------------------- */
s *= 1.;
if (s == 0.) {
goto L20;
}
if (u > v) {
goto L10;
}
q = u / v;
ret_val = v * sqrt(q * q + 1.);
return ret_val;
L10:
q = v / u;
ret_val = u * sqrt(q * q + 1.);
return ret_val;
L20:
ret_val = 0.;
return ret_val;
} /* zabs_ */
/* DECK ZEXP */
/* Subroutine */
int zexp_(double *ar, double *ai, double *br,
double *bi)
{
/* Local variables */
double ca, cb, zm;
/* ***BEGIN PROLOGUE ZEXP */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and */
/* ZBIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (ZEXP-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* DOUBLE PRECISION COMPLEX EXPONENTIAL FUNCTION B=EXP(A) */
/* ***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY */
/* ***ROUTINES CALLED (NONE) */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZEXP */
/* ***FIRST EXECUTABLE STATEMENT ZEXP */
zm = exp(*ar);
ca = zm * cos(*ai);
cb = zm * sin(*ai);
*br = ca;
*bi = cb;
return 0;
} /* zexp_ */
/* DECK ZDIV */
/* Subroutine */
int zdiv_(double *ar, double *ai, double *br,
double *bi, double *cr, double *ci)
{
double ca, cb, cc, cd, bm;
/* ***BEGIN PROLOGUE ZDIV */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and */
/* ZBIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (ZDIV-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* DOUBLE PRECISION COMPLEX DIVIDE C=A/B. */
/* ***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY */
/* ***ROUTINES CALLED ZABS */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZDIV */
/* ***FIRST EXECUTABLE STATEMENT ZDIV */
bm = 1. / zabs_(br, bi);
cc = *br * bm;
cd = *bi * bm;
ca = (*ar * cc + *ai * cd) * bm;
cb = (*ai * cc - *ar * cd) * bm;
*cr = ca;
*ci = cb;
return 0;
} /* zdiv_ */
/* DECK ZSQRT */
/* Subroutine */
int zsqrt_(double *ar, double *ai, double *br,
double *bi)
{
/* Initialized data */
double drt = .7071067811865475244008443621;
double dpi = 3.141592653589793238462643383;
/* Local variables */
double zm;
double dtheta;
/* ***BEGIN PROLOGUE ZSQRT */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and */
/* ZBIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (ZSQRT-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* DOUBLE PRECISION COMPLEX SQUARE ROOT, B=CSQRT(A) */
/* ***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY */
/* ***ROUTINES CALLED ZABS */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZSQRT */
/* ***FIRST EXECUTABLE STATEMENT ZSQRT */
zm = zabs_(ar, ai);
zm = sqrt(zm);
if (*ar == 0.) {
goto L10;
}
if (*ai == 0.) {
goto L20;
}
dtheta = atan(*ai / *ar);
if (dtheta <= 0.) {
goto L40;
}
if (*ar < 0.) {
dtheta -= dpi;
}
goto L50;
L10:
if (*ai > 0.) {
goto L60;
}
if (*ai < 0.) {
goto L70;
}
*br = 0.;
*bi = 0.;
return 0;
L20:
if (*ar > 0.) {
goto L30;
}
*br = 0.;
*bi = sqrt((abs(*ar)));
return 0;
L30:
*br = sqrt(*ar);
*bi = 0.;
return 0;
L40:
if (*ar < 0.) {
dtheta += dpi;
}
L50:
dtheta *= .5;
*br = zm * cos(dtheta);
*bi = zm * sin(dtheta);
return 0;
L60:
*br = zm * drt;
*bi = zm * drt;
return 0;
L70:
*br = zm * drt;
*bi = -zm * drt;
return 0;
} /* zsqrt_ */
/* DECK ZLOG */
/* Subroutine */
int zlog_(double *ar, double *ai, double *br,
double *bi, int *ierr)
{
/* Initialized data */
double dpi = 3.141592653589793238462643383;
double dhpi = 1.570796326794896619231321696;
/* Local variables */
double zm;
double dtheta;
/* ***BEGIN PROLOGUE ZLOG */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and */
/* ZBIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (ZLOG-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* DOUBLE PRECISION COMPLEX LOGARITHM B=CLOG(A) */
/* IERR=0,NORMAL RETURN IERR=1, Z=CMPLX(0.0,0.0) */
/* ***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY */
/* ***ROUTINES CALLED ZABS */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZLOG */
/* ***FIRST EXECUTABLE STATEMENT ZLOG */
*ierr = 0;
if (*ar == 0.) {
goto L10;
}
if (*ai == 0.) {
goto L20;
}
dtheta = atan(*ai / *ar);
if (dtheta <= 0.) {
goto L40;
}
if (*ar < 0.) {
dtheta -= dpi;
}
goto L50;
L10:
if (*ai == 0.) {
goto L60;
}
*bi = dhpi;
*br = log((abs(*ai)));
if (*ai < 0.) {
*bi = -(*bi);
}
return 0;
L20:
if (*ar > 0.) {
goto L30;
}
*br = log((abs(*ar)));
*bi = dpi;
return 0;
L30:
*br = log(*ar);
*bi = 0.;
return 0;
L40:
if (*ar < 0.) {
dtheta += dpi;
}
L50:
zm = zabs_(ar, ai);
*br = log(zm);
*bi = dtheta;
return 0;
L60:
*ierr = 1;
return 0;
} /* zlog_ */
/* DECK ZS1S2 */
/* Subroutine */
int zs1s2_(double *zrr, double *zri, double *s1r,
double *s1i, double *s2r, double *s2i, int *nz,
double *ascle, double *alim, int *iuf)
{
/* Initialized data */
double zeror = 0.;
double zeroi = 0.;
/* Local variables */
double aa, c1i, as1, as2, c1r, aln, s1di, s1dr;
int idum;
/* ***BEGIN PROLOGUE ZS1S2 */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZAIRY and ZBESK */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (CS1S2-A, ZS1S2-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* ZS1S2 TESTS FOR A POSSIBLE UNDERFLOW RESULTING FROM THE */
/* ADDITION OF THE I AND K FUNCTIONS IN THE ANALYTIC CON- */
/* TINUATION FORMULA WHERE S1=K FUNCTION AND S2=I FUNCTION. */
/* ON KODE=1 THE I AND K FUNCTIONS ARE DIFFERENT ORDERS OF */
/* MAGNITUDE, BUT FOR KODE=2 THEY CAN BE OF THE SAME ORDER */
/* OF MAGNITUDE AND THE MAXIMUM MUST BE AT LEAST ONE */
/* PRECISION ABOVE THE UNDERFLOW LIMIT. */
/* ***SEE ALSO ZAIRY, ZBESK */
/* ***ROUTINES CALLED ZABS, ZEXP, ZLOG */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* 930122 Added ZEXP and ZLOG to EXTERNAL statement. (RWC) */
/* ***END PROLOGUE ZS1S2 */
/* COMPLEX CZERO,C1,S1,S1D,S2,ZR */
/* ***FIRST EXECUTABLE STATEMENT ZS1S2 */
*nz = 0;
as1 = zabs_(s1r, s1i);
as2 = zabs_(s2r, s2i);
if (*s1r == 0. && *s1i == 0.) {
goto L10;
}
if (as1 == 0.) {
goto L10;
}
aln = -(*zrr) - *zrr + log(as1);
s1dr = *s1r;
s1di = *s1i;
*s1r = zeror;
*s1i = zeroi;
as1 = zeror;
if (aln < -(*alim)) {
goto L10;
}
zlog_(&s1dr, &s1di, &c1r, &c1i, &idum);
c1r = c1r - *zrr - *zrr;
c1i = c1i - *zri - *zri;
zexp_(&c1r, &c1i, s1r, s1i);
as1 = zabs_(s1r, s1i);
++(*iuf);
L10:
aa = max(as1,as2);
if (aa > *ascle) {
return 0;
}
*s1r = zeror;
*s1i = zeroi;
*s2r = zeror;
*s2i = zeroi;
*nz = 1;
*iuf = 0;
return 0;
} /* zs1s2_ */
/* DECK ZASYI */
/* Subroutine */
int zasyi_(double *zr, double *zi, double *fnu,
int *kode, int *n, double *yr, double *yi, int *
nz, double *rl, double *tol, double *elim, double *
alim)
{
/* Initialized data */
double pi = 3.14159265358979324;
double rtpi = .159154943091895336;
double zeror = 0.;
double zeroi = 0.;
double coner = 1.;
double conei = 0.;
/* System generated locals */
int i__1, i__2;
double d__1, d__2;
/* Local variables */
int i__, j, k, m;
double s, aa, bb;
int ib;
double ak, bk;
int il, jl;
double az;
int nn;
double p1i, s2i, p1r, s2r, cki, dki, fdn, arg, aez, arm, ckr,
dkr, czi, ezi, sgn;
int inu;
double raz, czr, ezr, sqk, sti, rzi, tzi, str, rzr, tzr, ak1i,
ak1r, cs1i, cs2i, cs1r, cs2r, dnu2, rtr1, dfnu, atol;
int koded;
/* ***BEGIN PROLOGUE ZASYI */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESI and ZBESK */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (CASYI-A, ZASYI-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* ZASYI COMPUTES THE I BESSEL FUNCTION FOR REAL(Z).GE.0.0 BY */
/* MEANS OF THE ASYMPTOTIC EXPANSION FOR LARGE ABS(Z) IN THE */
/* REGION ABS(Z).GT.MAX(RL,FNU*FNU/2). NZ=0 IS A NORMAL RETURN. */
/* NZ.LT.0 INDICATES AN OVERFLOW ON KODE=1. */
/* ***SEE ALSO ZBESI, ZBESK */
/* ***ROUTINES CALLED D1MACH, ZABS, ZDIV, ZEXP, ZMLT, ZSQRT */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* 930122 Added ZEXP and ZSQRT to EXTERNAL statement. (RWC) */
/* ***END PROLOGUE ZASYI */
/* COMPLEX AK1,CK,CONE,CS1,CS2,CZ,CZERO,DK,EZ,P1,RZ,S2,Y,Z */
/* Parameter adjustments */
--yi;
--yr;
/* Function Body */
/* ***FIRST EXECUTABLE STATEMENT ZASYI */
*nz = 0;
az = zabs_(zr, zi);
arm = d1mach_(&c__1) * 1e3;
rtr1 = sqrt(arm);
il = min(2,*n);
dfnu = *fnu + (*n - il);
/* ----------------------------------------------------------------------- */
/* OVERFLOW TEST */
/* ----------------------------------------------------------------------- */
raz = 1. / az;
str = *zr * raz;
sti = -(*zi) * raz;
ak1r = rtpi * str * raz;
ak1i = rtpi * sti * raz;
zsqrt_(&ak1r, &ak1i, &ak1r, &ak1i);
czr = *zr;
czi = *zi;
if (*kode != 2) {
goto L10;
}
czr = zeror;
czi = *zi;
L10:
if (abs(czr) > *elim) {
goto L100;
}
dnu2 = dfnu + dfnu;
koded = 1;
if (abs(czr) > *alim && *n > 2) {
goto L20;
}
koded = 0;
zexp_(&czr, &czi, &str, &sti);
zmlt_(&ak1r, &ak1i, &str, &sti, &ak1r, &ak1i);
L20:
fdn = 0.;
if (dnu2 > rtr1) {
fdn = dnu2 * dnu2;
}
ezr = *zr * 8.;
ezi = *zi * 8.;
/* ----------------------------------------------------------------------- */
/* WHEN Z IS IMAGINARY, THE ERROR TEST MUST BE MADE RELATIVE TO THE */
/* FIRST RECIPROCAL POWER SINCE THIS IS THE LEADING TERM OF THE */
/* EXPANSION FOR THE IMAGINARY PART. */
/* ----------------------------------------------------------------------- */
aez = az * 8.;
s = *tol / aez;
jl = (int) (*rl + *rl + 2);
p1r = zeror;
p1i = zeroi;
if (*zi == 0.) {
goto L30;
}
/* ----------------------------------------------------------------------- */
/* CALCULATE EXP(PI*(0.5+FNU+N-IL)*I) TO MINIMIZE LOSSES OF */
/* SIGNIFICANCE WHEN FNU OR N IS LARGE */
/* ----------------------------------------------------------------------- */
inu = (int) (*fnu);
arg = (*fnu - inu) * pi;
inu = inu + *n - il;
ak = -sin(arg);
bk = cos(arg);
if (*zi < 0.) {
bk = -bk;
}
p1r = ak;
p1i = bk;
if (inu % 2 == 0) {
goto L30;
}
p1r = -p1r;
p1i = -p1i;
L30:
i__1 = il;
for (k = 1; k <= i__1; ++k) {
sqk = fdn - 1.;
atol = s * abs(sqk);
sgn = 1.;
cs1r = coner;
cs1i = conei;
cs2r = coner;
cs2i = conei;
ckr = coner;
cki = conei;
ak = 0.;
aa = 1.;
bb = aez;
dkr = ezr;
dki = ezi;
i__2 = jl;
for (j = 1; j <= i__2; ++j) {
zdiv_(&ckr, &cki, &dkr, &dki, &str, &sti);
ckr = str * sqk;
cki = sti * sqk;
cs2r += ckr;
cs2i += cki;
sgn = -sgn;
cs1r += ckr * sgn;
cs1i += cki * sgn;
dkr += ezr;
dki += ezi;
aa = aa * abs(sqk) / bb;
bb += aez;
ak += 8.;
sqk -= ak;
if (aa <= atol) {
goto L50;
}
/* L40: */
}
goto L110;
L50:
s2r = cs1r;
s2i = cs1i;
if (*zr + *zr >= *elim) {
goto L60;
}
tzr = *zr + *zr;
tzi = *zi + *zi;
d__1 = -tzr;
d__2 = -tzi;
zexp_(&d__1, &d__2, &str, &sti);
zmlt_(&str, &sti, &p1r, &p1i, &str, &sti);
zmlt_(&str, &sti, &cs2r, &cs2i, &str, &sti);
s2r += str;
s2i += sti;
L60:
fdn = fdn + dfnu * 8. + 4.;
p1r = -p1r;
p1i = -p1i;
m = *n - il + k;
yr[m] = s2r * ak1r - s2i * ak1i;
yi[m] = s2r * ak1i + s2i * ak1r;
/* L70: */
}
if (*n <= 2) {
return 0;
}
nn = *n;
k = nn - 2;
ak = (double) k;
str = *zr * raz;
sti = -(*zi) * raz;
rzr = (str + str) * raz;
rzi = (sti + sti) * raz;
ib = 3;
i__1 = nn;
for (i__ = ib; i__ <= i__1; ++i__) {
yr[k] = (ak + *fnu) * (rzr * yr[k + 1] - rzi * yi[k + 1]) + yr[k + 2];
yi[k] = (ak + *fnu) * (rzr * yi[k + 1] + rzi * yr[k + 1]) + yi[k + 2];
ak += -1.;
--k;
/* L80: */
}
if (koded == 0) {
return 0;
}
zexp_(&czr, &czi, &ckr, &cki);
i__1 = nn;
for (i__ = 1; i__ <= i__1; ++i__) {
str = yr[i__] * ckr - yi[i__] * cki;
yi[i__] = yr[i__] * cki + yi[i__] * ckr;
yr[i__] = str;
/* L90: */
}
return 0;
L100:
*nz = -1;
return 0;
L110:
*nz = -2;
return 0;
} /* zasyi_ */
/* DECK ZACAI */
/* Subroutine */
int zacai_(double *zr, double *zi, double *fnu,
int *kode, int *mr, int *n, double *yr, double *
yi, int *nz, double *rl, double *tol, double *elim,
double *alim)
{
/* Initialized data */
double pi = 3.14159265358979324;
/* Local variables */
double az;
int nn, nw;
double yy, c1i, c2i, c1r, c2r, arg;
int iuf;
double cyi[2], fmr, sgn;
int inu;
double cyr[2], zni, znr, dfnu;
double ascle, csgni, csgnr, cspni, cspnr;
/* ***BEGIN PROLOGUE ZACAI */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZAIRY */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (CACAI-A, ZACAI-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* ZACAI APPLIES THE ANALYTIC CONTINUATION FORMULA */
/* K(FNU,ZN*EXP(MP))=K(FNU,ZN)*EXP(-MP*FNU) - MP*I(FNU,ZN) */
/* MP=PI*MR*CMPLX(0.0,1.0) */
/* TO CONTINUE THE K FUNCTION FROM THE RIGHT HALF TO THE LEFT */
/* HALF Z PLANE FOR USE WITH ZAIRY WHERE FNU=1/3 OR 2/3 AND N=1. */
/* ZACAI IS THE SAME AS ZACON WITH THE PARTS FOR LARGER ORDERS AND */
/* RECURRENCE REMOVED. A RECURSIVE CALL TO ZACON CAN RESULT IF ZACON */
/* IS CALLED FROM ZAIRY. */
/* ***SEE ALSO ZAIRY */
/* ***ROUTINES CALLED D1MACH, ZABS, ZASYI, ZBKNU, ZMLRI, ZS1S2, ZSERI */
/* ***REVISION HISTORY (YYMMDD) */
/* 830501 DATE WRITTEN */
/* 910415 Prologue converted to Version 4.0 format. (BAB) */
/* ***END PROLOGUE ZACAI */
/* COMPLEX CSGN,CSPN,C1,C2,Y,Z,ZN,CY */
/* Parameter adjustments */
--yi;
--yr;
/* Function Body */
/* ***FIRST EXECUTABLE STATEMENT ZACAI */
*nz = 0;
znr = -(*zr);
zni = -(*zi);
az = zabs_(zr, zi);
nn = *n;
dfnu = *fnu + (*n - 1);
if (az <= 2.) {
goto L10;
}
if (az * az * .25 > dfnu + 1.) {
goto L20;
}
L10:
/* ----------------------------------------------------------------------- */
/* POWER SERIES FOR THE I FUNCTION */
/* ----------------------------------------------------------------------- */
zseri_(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, tol, elim, alim);
goto L40;
L20:
if (az < *rl) {
goto L30;
}
/* ----------------------------------------------------------------------- */
/* ASYMPTOTIC EXPANSION FOR LARGE Z FOR THE I FUNCTION */
/* ----------------------------------------------------------------------- */
zasyi_(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, rl, tol, elim,
alim);
if (nw < 0) {
goto L80;
}
goto L40;
L30:
/* ----------------------------------------------------------------------- */
/* MILLER ALGORITHM NORMALIZED BY THE SERIES FOR THE I FUNCTION */
/* ----------------------------------------------------------------------- */
zmlri_(&znr, &zni, fnu, kode, &nn, &yr[1], &yi[1], &nw, tol);
if (nw < 0) {
goto L80;
}
L40:
/* ----------------------------------------------------------------------- */
/* ANALYTIC CONTINUATION TO THE LEFT HALF PLANE FOR THE K FUNCTION */
/* ----------------------------------------------------------------------- */
zbknu_(&znr, &zni, fnu, kode, &c__1, cyr, cyi, &nw, tol, elim, alim);
if (nw != 0) {
goto L80;
}
fmr = (double) (*mr);
sgn = -d_sign(&pi, &fmr);
csgnr = 0.;
csgni = sgn;
if (*kode == 1) {
goto L50;
}
yy = -zni;
csgnr = -csgni * sin(yy);
csgni *= cos(yy);
L50:
/* ----------------------------------------------------------------------- */
/* CALCULATE CSPN=EXP(FNU*PI*I) TO MINIMIZE LOSSES OF SIGNIFICANCE */
/* WHEN FNU IS LARGE */
/* ----------------------------------------------------------------------- */
inu = (int) (*fnu);
arg = (*fnu - inu) * sgn;
cspnr = cos(arg);
cspni = sin(arg);
if (inu % 2 == 0) {
goto L60;
}
cspnr = -cspnr;
cspni = -cspni;
L60:
c1r = cyr[0];
c1i = cyi[0];
c2r = yr[1];
c2i = yi[1];
if (*kode == 1) {
goto L70;
}
iuf = 0;
ascle = d1mach_(&c__1) * 1e3 / *tol;
zs1s2_(&znr, &zni, &c1r, &c1i, &c2r, &c2i, &nw, &ascle, alim, &iuf);
*nz += nw;
L70:
yr[1] = cspnr * c1r - cspni * c1i + csgnr * c2r - csgni * c2i;
yi[1] = cspnr * c1i + cspni * c1r + csgnr * c2i + csgni * c2r;
return 0;
L80:
*nz = -1;
if (nw == -2) {
*nz = -2;
}
return 0;
} /* zacai_ */
/* DECK ZUNI1 */
/* Subroutine */
int zuni1_(double *zr, double *zi, double *fnu,
int *kode, int *n, double *yr, double *yi, int *
nz, int *nlast, double *fnul, double *tol, double *
elim, double *alim)
{
/* Initialized data */
double zeror = 0.;
double zeroi = 0.;
double coner = 1.;
/* System generated locals */
int i__1;
/* Local variables */
int i__, k, m, nd;
double fn;
int nn, nw;
double c2i, c2m, c1r, c2r, s1i, s2i, rs1, s1r, s2r, cyi[2];
int nuf;
double bry[3], cyr[2], sti, rzi, str, rzr, aphi, cscl, phii,
crsc;
double phir;
int init;
double csrr[3], cssr[3], rast, sumi, sumr;
int iflag;
double ascle, cwrki[16];
double cwrkr[16];
double zeta1i, zeta2i, zeta1r, zeta2r;
/* ***BEGIN PROLOGUE ZUNI1 */
/* ***SUBSIDIARY */
/* ***PURPOSE Subsidiary to ZBESI and ZBESK */
/* ***LIBRARY SLATEC */
/* ***TYPE ALL (CUNI1-A, ZUNI1-A) */
/* ***AUTHOR Amos, D. E., (SNL) */
/* ***DESCRIPTION */
/* ZUNI1 COMPUTES I(FNU,Z) BY MEANS OF THE UNIFORM ASYMPTOTIC */
/* EXPANSION FOR I(FNU,Z) IN -PI/3.LE.ARG Z.LE.PI/3. */
/* FNUL IS THE SMALLEST ORDER PERMITTED FOR THE ASYMPTOTIC */
/* EXPANSION. NLAST=0 MEANS ALL OF THE Y VALUES WERE SET. */
/* NLAST.NE.0 IS THE NUMBER LEFT TO BE COMPUTED BY ANOTHER */
/* FORMULA FOR ORDERS FNU TO FNU+NLAST-1 BECAUSE FNU+NLAST-1.LT.FNUL. */