forked from postwait/numlua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamos.c
9096 lines (8648 loc) · 263 KB
/
amos.c
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
/* {=================================================================
*
* amos.c
* f2c translation of SLATEC Bessel related functions
* Luis Carvalho (lexcarvalho@gmail.com)
*
* ==================================================================} */
#include <stdlib.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
static double d1mach_ (int *i)
{
switch (*i) {
case 1: return DBL_MIN;
case 2: return DBL_MAX;
case 3: return DBL_EPSILON / FLT_RADIX;
case 4: return DBL_EPSILON;
case 5: return log10((double) FLT_RADIX);
}
return 0; /* not reached */
}
static int i1mach_ (int *i)
{
switch (*i) {
case 9: return INT_MAX;
case 14: return DBL_MANT_DIG;
case 15: return DBL_MIN_EXP;
case 16: return DBL_MAX_EXP;
}
return 0; /* not reached */
}
/* Table of constant values */
static int c__0 = 0;
static int c__1 = 1;
static int c__2 = 2;
static int c__4 = 4;
static int c__5 = 5;
static int c__9 = 9;
static int c__14 = 14;
static int c__15 = 15;
static int c__16 = 16;
static double c_b10 = .5;
static double c_b11 = 0.;
static double dgamln_(double *z__, int *ierr)
{
/* Initialized data */
static double gln[100] = { 0.,0.,.693147180559945309,
1.791759469228055,3.17805383034794562,4.78749174278204599,
6.579251212010101,8.5251613610654143,10.6046029027452502,
12.8018274800814696,15.1044125730755153,17.5023078458738858,
19.9872144956618861,22.5521638531234229,25.1912211827386815,
27.8992713838408916,30.6718601060806728,33.5050734501368889,
36.3954452080330536,39.339884187199494,42.335616460753485,
45.380138898476908,48.4711813518352239,51.6066755677643736,
54.7847293981123192,58.0036052229805199,61.261701761002002,
64.5575386270063311,67.889743137181535,71.257038967168009,
74.6582363488301644,78.0922235533153106,81.5579594561150372,
85.0544670175815174,88.5808275421976788,92.1361756036870925,
95.7196945421432025,99.3306124547874269,102.968198614513813,
106.631760260643459,110.320639714757395,114.034211781461703,
117.771881399745072,121.533081515438634,125.317271149356895,
129.123933639127215,132.95257503561631,136.802722637326368,
140.673923648234259,144.565743946344886,148.477766951773032,
152.409592584497358,156.360836303078785,160.331128216630907,
164.320112263195181,168.327445448427652,172.352797139162802,
176.395848406997352,180.456291417543771,184.533828861449491,
188.628173423671591,192.739047287844902,196.866181672889994,
201.009316399281527,205.168199482641199,209.342586752536836,
213.532241494563261,217.736934113954227,221.956441819130334,
226.190548323727593,230.439043565776952,234.701723442818268,
238.978389561834323,243.268849002982714,247.572914096186884,
251.890402209723194,256.221135550009525,260.564940971863209,
264.921649798552801,269.291097651019823,273.673124285693704,
278.067573440366143,282.474292687630396,286.893133295426994,
291.323950094270308,295.766601350760624,300.220948647014132,
304.686856765668715,309.164193580146922,313.652829949879062,
318.152639620209327,322.663499126726177,327.185287703775217,
331.717887196928473,336.261181979198477,340.815058870799018,
345.379407062266854,349.954118040770237,354.539085519440809,
359.134205369575399 };
static double cf[22] = { .0833333333333333333,-.00277777777777777778,
7.93650793650793651e-4,-5.95238095238095238e-4,
8.41750841750841751e-4,-.00191752691752691753,
.00641025641025641026,-.0295506535947712418,.179644372368830573,
-1.39243221690590112,13.402864044168392,-156.848284626002017,
2193.10333333333333,-36108.7712537249894,691472.268851313067,
-15238221.5394074162,382900751.391414141,-10882266035.7843911,
347320283765.002252,-12369602142269.2745,488788064793079.335,
-21320333960919373.9 };
static double con = 1.83787706640934548;
/* System generated locals */
int i__1;
double ret_val = 0;
/* Local variables */
static int i__, k;
static double s, t1, fz, zm;
static int mz, nz;
static double zp;
static int i1m;
static double fln, tlg, rln, trm, tst, zsq, zinc, zmin, zdmy, wdtol;
/* ***BEGIN PROLOGUE DGAMLN */
/* ***DATE WRITTEN 830501 (YYMMDD) */
/* ***REVISION DATE 830501 (YYMMDD) */
/* ***CATEGORY NO. B5F */
/* ***KEYWORDS GAMMA FUNCTION,LOGARITHM OF GAMMA FUNCTION */
/* ***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES */
/* ***PURPOSE TO COMPUTE THE LOGARITHM OF THE GAMMA FUNCTION */
/* ***DESCRIPTION */
/* **** A DOUBLE PRECISION ROUTINE **** */
/* DGAMLN COMPUTES THE NATURAL LOG OF THE GAMMA FUNCTION FOR */
/* Z.GT.0. THE ASYMPTOTIC EXPANSION IS USED TO GENERATE VALUES */
/* GREATER THAN ZMIN WHICH ARE ADJUSTED BY THE RECURSION */
/* G(Z+1)=Z*G(Z) FOR Z.LE.ZMIN. THE FUNCTION WAS MADE AS */
/* PORTABLE AS POSSIBLE BY COMPUTIMG ZMIN FROM THE NUMBER OF BASE */
/* 10 DIGITS IN A WORD, RLN=AMAX1(-ALOG10(R1MACH(4)),0.5E-18) */
/* LIMITED TO 18 DIGITS OF (RELATIVE) ACCURACY. */
/* SINCE INTEGER ARGUMENTS ARE COMMON, A TABLE LOOK UP ON 100 */
/* VALUES IS USED FOR SPEED OF EXECUTION. */
/* DESCRIPTION OF ARGUMENTS */
/* INPUT Z IS D0UBLE PRECISION */
/* Z - ARGUMENT, Z.GT.0.0D0 */
/* OUTPUT DGAMLN IS DOUBLE PRECISION */
/* DGAMLN - NATURAL LOG OF THE GAMMA FUNCTION AT Z.NE.0.0D0 */
/* IERR - ERROR FLAG */
/* IERR=0, NORMAL RETURN, COMPUTATION COMPLETED */
/* IERR=1, Z.LE.0.0D0, NO COMPUTATION */
/* ***REFERENCES COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT */
/* BY D. E. AMOS, SAND83-0083, MAY, 1983. */
/* ***ROUTINES CALLED I1MACH,D1MACH */
/* ***END PROLOGUE DGAMLN */
/* LNGAMMA(N), N=1,100 */
/* COEFFICIENTS OF ASYMPTOTIC EXPANSION */
/* LN(2*PI) */
/* ***FIRST EXECUTABLE STATEMENT DGAMLN */
*ierr = 0;
if (*z__ <= 0.) {
goto L70;
}
if (*z__ > 101.) {
goto L10;
}
nz = (int) (*z__);
fz = *z__ - (double) (nz);
if (fz > 0.) {
goto L10;
}
if (nz > 100) {
goto L10;
}
ret_val = gln[nz - 1];
return ret_val;
L10:
wdtol = d1mach_(&c__4);
wdtol = max(wdtol,5e-19);
i1m = i1mach_(&c__14);
rln = d1mach_(&c__5) * (double) i1m;
fln = min(rln,20.);
fln = max(fln,3.);
fln += -3.;
zm = fln * .3875 + 1.8;
mz = (int) (zm) + 1;
zmin = (double) mz;
zdmy = *z__;
zinc = 0.;
if (*z__ >= zmin) {
goto L20;
}
zinc = zmin - (double) nz;
zdmy = *z__ + zinc;
L20:
zp = 1. / zdmy;
t1 = cf[0] * zp;
s = t1;
if (zp < wdtol) {
goto L40;
}
zsq = zp * zp;
tst = t1 * wdtol;
for (k = 2; k <= 22; ++k) {
zp *= zsq;
trm = cf[k - 1] * zp;
if (fabs(trm) < tst) {
goto L40;
}
s += trm;
/* L30: */
}
L40:
if (zinc != 0.) {
goto L50;
}
tlg = log(*z__);
ret_val = *z__ * (tlg - 1.) + (con - tlg) * .5 + s;
return ret_val;
L50:
zp = 1.;
nz = (int) (zinc);
i__1 = nz;
for (i__ = 1; i__ <= i__1; ++i__) {
zp *= *z__ + (double) (i__ - 1);
/* L60: */
}
tlg = log(zdmy);
ret_val = zdmy * (tlg - 1.) - log(zp) + (con - tlg) * .5 + s;
return ret_val;
L70:
*ierr = 1;
return ret_val;
} /* dgamln_ */
static double xzabs_(double *zr, double *zi)
{
/* System generated locals */
double ret_val;
/* Local variables */
static double q, s, u, v;
/* ***BEGIN PROLOGUE XZABS */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* XZABS COMPUTES THE ABSOLUTE VALUE OR MAGNITUDE OF A DOUBLE */
/* PRECISION COMPLEX VARIABLE CMPLX(ZR,ZI) */
/* ***ROUTINES CALLED (NONE) */
/* ***END PROLOGUE XZABS */
u = fabs(*zr);
v = fabs(*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;
} /* xzabs_ */
static int xzexp_(double *ar, double *ai, double *br, double *bi)
{
/* Local variables */
static double ca, cb, zm;
/* ***BEGIN PROLOGUE XZEXP */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* DOUBLE PRECISION COMPLEX EXPONENTIAL FUNCTION B=EXP(A) */
/* ***ROUTINES CALLED (NONE) */
/* ***END PROLOGUE XZEXP */
zm = exp(*ar);
ca = zm * cos(*ai);
cb = zm * sin(*ai);
*br = ca;
*bi = cb;
return 0;
} /* xzexp_ */
static int xzlog_(double *ar, double *ai, double *br, double *bi, int *ierr)
{
/* Initialized data */
static double dpi = 3.141592653589793238462643383;
static double dhpi = 1.570796326794896619231321696;
/* Local variables */
static double zm;
static double dtheta;
/* ***BEGIN PROLOGUE XZLOG */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* DOUBLE PRECISION COMPLEX LOGARITHM B=CLOG(A) */
/* IERR=0,NORMAL RETURN IERR=1, Z=CMPLX(0.0,0.0) */
/* ***ROUTINES CALLED XZABS */
/* ***END PROLOGUE XZLOG */
*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((fabs(*ai)));
if (*ai < 0.) {
*bi = -(*bi);
}
return 0;
L20:
if (*ar > 0.) {
goto L30;
}
*br = log((fabs(*ar)));
*bi = dpi;
return 0;
L30:
*br = log(*ar);
*bi = 0.;
return 0;
L40:
if (*ar < 0.) {
dtheta += dpi;
}
L50:
zm = xzabs_(ar, ai);
*br = log(zm);
*bi = dtheta;
return 0;
L60:
*ierr = 1;
return 0;
} /* xzlog_ */
static int xzsqrt_(double *ar, double *ai, double *br, double *bi)
{
/* Initialized data */
static double drt = .7071067811865475244008443621;
static double dpi = 3.141592653589793238462643383;
/* Local variables */
static double zm;
static double dtheta;
/* ***BEGIN PROLOGUE XZSQRT */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* DOUBLE PRECISION COMPLEX SQUARE ROOT, B=CSQRT(A) */
/* ***ROUTINES CALLED XZABS */
/* ***END PROLOGUE XZSQRT */
zm = xzabs_(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((fabs(*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;
} /* xzsqrt_ */
static int zdiv_(double *ar, double *ai, double *br,
double *bi, double *cr, double *ci)
{
static double ca, cb, cc, cd, bm;
/* ***BEGIN PROLOGUE ZDIV */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* DOUBLE PRECISION COMPLEX DIVIDE C=A/B. */
/* ***ROUTINES CALLED XZABS */
/* ***END PROLOGUE ZDIV */
bm = 1. / xzabs_(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_ */
static int zmlt_(double *ar, double *ai, double *br,
double *bi, double *cr, double *ci)
{
static double ca, cb;
/* ***BEGIN PROLOGUE ZMLT */
/* ***REFER TO ZBESH,ZBESI,ZBESJ,ZBESK,ZBESY,ZAIRY,ZBIRY */
/* DOUBLE PRECISION COMPLEX MULTIPLY, C=A*B. */
/* ***ROUTINES CALLED (NONE) */
/* ***END PROLOGUE ZMLT */
ca = *ar * *br - *ai * *bi;
cb = *ar * *bi + *ai * *br;
*cr = ca;
*ci = cb;
return 0;
} /* zmlt_ */
static int zrati_(double *zr, double *zi, double *fnu,
int *n, double *cyr, double *cyi, double *tol)
{
/* Initialized data */
static double czeror = 0.;
static double czeroi = 0.;
static double coner = 1.;
static double conei = 0.;
static double rt2 = 1.41421356237309505;
/* System generated locals */
int i__1;
double d__1;
/* Local variables */
static int i__, k;
static double ak;
static int id, kk;
static double az, ap1, ap2, p1i, p2i, t1i, p1r, p2r, t1r, arg, rak,
rho;
static int inu;
static double pti, tti, rzi, ptr, ttr, rzr, rap1, flam, dfnu, fdnu;
static int magz, idnu;
static double fnup;
static double test, test1, amagz;
static int itime;
static double cdfnui, cdfnur;
/* ***BEGIN PROLOGUE ZRATI */
/* ***REFER TO ZBESI,ZBESK,ZBESH */
/* ZRATI COMPUTES RATIOS OF I BESSEL FUNCTIONS BY BACKWARD */
/* RECURRENCE. THE STARTING INDEX IS DETERMINED BY FORWARD */
/* RECURRENCE AS DESCRIBED IN J. RES. OF NAT. BUR. OF STANDARDS-B, */
/* MATHEMATICAL SCIENCES, VOL 77B, P111-114, SEPTEMBER, 1973, */
/* BESSEL FUNCTIONS I AND J OF COMPLEX ARGUMENT AND INTEGER ORDER, */
/* BY D. J. SOOKNE. */
/* ***ROUTINES CALLED XZABS,ZDIV */
/* ***END PROLOGUE ZRATI */
/* COMPLEX Z,CY(1),CONE,CZERO,P1,P2,T1,RZ,PT,CDFNU */
/* Parameter adjustments */
--cyi;
--cyr;
/* Function Body */
az = xzabs_(zr, zi);
inu = (int) (*fnu);
idnu = inu + *n - 1;
magz = (int) (az);
amagz = (double) (magz + 1);
fdnu = (double) (idnu);
fnup = max(amagz,fdnu);
id = idnu - magz - 1;
itime = 1;
k = 1;
ptr = 1. / az;
rzr = ptr * (*zr + *zr) * ptr;
rzi = -ptr * (*zi + *zi) * ptr;
t1r = rzr * fnup;
t1i = rzi * fnup;
p2r = -t1r;
p2i = -t1i;
p1r = coner;
p1i = conei;
t1r += rzr;
t1i += rzi;
if (id > 0) {
id = 0;
}
ap2 = xzabs_(&p2r, &p2i);
ap1 = xzabs_(&p1r, &p1i);
/* ----------------------------------------------------------------------- */
/* THE OVERFLOW TEST ON K(FNU+I-1,Z) BEFORE THE CALL TO CBKNU */
/* GUARANTEES THAT P2 IS ON SCALE. SCALE TEST1 AND ALL SUBSEQUENT */
/* P2 VALUES BY AP1 TO ENSURE THAT AN OVERFLOW DOES NOT OCCUR */
/* PREMATURELY. */
/* ----------------------------------------------------------------------- */
arg = (ap2 + ap2) / (ap1 * *tol);
test1 = sqrt(arg);
test = test1;
rap1 = 1. / ap1;
p1r *= rap1;
p1i *= rap1;
p2r *= rap1;
p2i *= rap1;
ap2 *= rap1;
L10:
++k;
ap1 = ap2;
ptr = p2r;
pti = p2i;
p2r = p1r - (t1r * ptr - t1i * pti);
p2i = p1i - (t1r * pti + t1i * ptr);
p1r = ptr;
p1i = pti;
t1r += rzr;
t1i += rzi;
ap2 = xzabs_(&p2r, &p2i);
if (ap1 <= test) {
goto L10;
}
if (itime == 2) {
goto L20;
}
ak = xzabs_(&t1r, &t1i) * .5;
flam = ak + sqrt(ak * ak - 1.);
/* Computing MIN */
d__1 = ap2 / ap1;
rho = min(d__1,flam);
test = test1 * sqrt(rho / (rho * rho - 1.));
itime = 2;
goto L10;
L20:
kk = k + 1 - id;
ak = (double) (kk);
t1r = ak;
t1i = czeroi;
dfnu = *fnu + (double) (*n - 1);
p1r = 1. / ap2;
p1i = czeroi;
p2r = czeror;
p2i = czeroi;
i__1 = kk;
for (i__ = 1; i__ <= i__1; ++i__) {
ptr = p1r;
pti = p1i;
rap1 = dfnu + t1r;
ttr = rzr * rap1;
tti = rzi * rap1;
p1r = ptr * ttr - pti * tti + p2r;
p1i = ptr * tti + pti * ttr + p2i;
p2r = ptr;
p2i = pti;
t1r -= coner;
/* L30: */
}
if (p1r != czeror || p1i != czeroi) {
goto L40;
}
p1r = *tol;
p1i = *tol;
L40:
zdiv_(&p2r, &p2i, &p1r, &p1i, &cyr[*n], &cyi[*n]);
if (*n == 1) {
return 0;
}
k = *n - 1;
ak = (double) (k);
t1r = ak;
t1i = czeroi;
cdfnur = *fnu * rzr;
cdfnui = *fnu * rzi;
i__1 = *n;
for (i__ = 2; i__ <= i__1; ++i__) {
ptr = cdfnur + (t1r * rzr - t1i * rzi) + cyr[k + 1];
pti = cdfnui + (t1r * rzi + t1i * rzr) + cyi[k + 1];
ak = xzabs_(&ptr, &pti);
if (ak != czeror) {
goto L50;
}
ptr = *tol;
pti = *tol;
ak = *tol * rt2;
L50:
rak = coner / ak;
cyr[k] = rak * ptr * rak;
cyi[k] = -rak * pti * rak;
t1r -= coner;
--k;
/* L60: */
}
return 0;
} /* zrati_ */
static int zshch_(double *zr, double *zi, double *cshr,
double *cshi, double *cchr, double *cchi)
{
/* Local variables */
static double ch, cn, sh, sn;
/* ***BEGIN PROLOGUE ZSHCH */
/* ***REFER TO ZBESK,ZBESH */
/* ZSHCH COMPUTES THE COMPLEX HYPERBOLIC FUNCTIONS CSH=SINH(X+I*Y) */
/* AND CCH=COSH(X+I*Y), WHERE I**2=-1. */
/* ***ROUTINES CALLED (NONE) */
/* ***END PROLOGUE ZSHCH */
sh = sinh(*zr);
ch = cosh(*zr);
sn = sin(*zi);
cn = cos(*zi);
*cshr = sh * cn;
*cshi = ch * sn;
*cchr = ch * cn;
*cchi = sh * sn;
return 0;
} /* zshch_ */
static int zuchk_(double *yr, double *yi, int *nz, double *ascle, double *tol)
{
static double wi, ss, st, wr;
/* ***BEGIN PROLOGUE ZUCHK */
/* ***REFER TO ZSERI,ZUOIK,ZUNK1,ZUNK2,ZUNI1,ZUNI2,ZKSCL */
/* Y ENTERS AS A SCALED QUANTITY WHOSE MAGNITUDE IS GREATER THAN */
/* EXP(-ALIM)=ASCLE=1.0E+3*D1MACH(1)/TOL. THE TEST IS MADE TO SEE */
/* IF THE MAGNITUDE OF THE REAL OR IMAGINARY PART WOULD UNDERFLOW */
/* WHEN Y IS SCALED (BY TOL) TO ITS PROPER VALUE. Y IS ACCEPTED */
/* IF THE UNDERFLOW IS AT LEAST ONE PRECISION BELOW THE MAGNITUDE */
/* OF THE LARGEST COMPONENT; OTHERWISE THE PHASE ANGLE DOES NOT HAVE */
/* ABSOLUTE ACCURACY AND AN UNDERFLOW IS ASSUMED. */
/* ***ROUTINES CALLED (NONE) */
/* ***END PROLOGUE ZUCHK */
/* COMPLEX Y */
*nz = 0;
wr = fabs(*yr);
wi = fabs(*yi);
st = min(wr,wi);
if (st > *ascle) {
return 0;
}
ss = max(wr,wi);
st /= *tol;
if (ss < st) {
*nz = 1;
}
return 0;
} /* zuchk_ */
static int zs1s2_(double *zrr, double *zri, double *s1r,
double *s1i, double *s2r, double *s2i, int *nz,
double *ascle, double *alim, int *iuf)
{
/* Initialized data */
static double zeror = 0.;
static double zeroi = 0.;
/* Local variables */
static double aa, c1i, as1, as2, c1r, aln, s1di, s1dr;
static int idum;
/* ***BEGIN PROLOGUE ZS1S2 */
/* ***REFER TO ZBESK,ZAIRY */
/* 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. */
/* ***ROUTINES CALLED XZABS,XZEXP,XZLOG */
/* ***END PROLOGUE ZS1S2 */
/* COMPLEX CZERO,C1,S1,S1D,S2,ZR */
*nz = 0;
as1 = xzabs_(s1r, s1i);
as2 = xzabs_(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;
}
xzlog_(&s1dr, &s1di, &c1r, &c1i, &idum);
c1r = c1r - *zrr - *zrr;
c1i = c1i - *zri - *zri;
xzexp_(&c1r, &c1i, s1r, s1i);
as1 = xzabs_(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_ */
static 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)
{
/* Initialized data */
static double zeror = 0.;
static double zeroi = 0.;
/* System generated locals */
int i__1;
/* Local variables */
static int i__, ic;
static double as, fn;
static int kk, nn, nw;
static double s1i, s2i, s1r, s2r, acs, cki, elm, csi, ckr, cyi[2],
zdi, csr, cyr[2], zdr, str, alas;
static int idum;
static double helim, celmr;
/* ***BEGIN PROLOGUE ZKSCL */
/* ***REFER TO ZBESK */
/* SET K FUNCTIONS TO ZERO ON UNDERFLOW, CONTINUE RECURRENCE */
/* ON SCALED FUNCTIONS UNTIL TWO MEMBERS COME ON SCALE, THEN */
/* RETURN WITH MIN(NZ+2,N) VALUES SCALED BY 1/TOL. */
/* ***ROUTINES CALLED ZUCHK,XZABS,XZLOG */
/* ***END PROLOGUE ZKSCL */
/* COMPLEX CK,CS,CY,CZERO,RZ,S1,S2,Y,ZR,ZD,CELM */
/* Parameter adjustments */
--yi;
--yr;
/* Function Body */
*nz = 0;
ic = 0;
nn = min(2,*n);
i__1 = nn;
for (i__ = 1; i__ <= i__1; ++i__) {
s1r = yr[i__];
s1i = yi[i__];
cyr[i__ - 1] = s1r;
cyi[i__ - 1] = s1i;
as = xzabs_(&s1r, &s1i);
acs = -(*zrr) + log(as);
++(*nz);
yr[i__] = zeror;
yi[i__] = zeroi;
if (acs < -(*elim)) {
goto L10;
}
xzlog_(&s1r, &s1i, &csr, &csi, &idum);
csr -= *zrr;
csi -= *zri;
str = exp(csr) / *tol;
csr = str * cos(csi);
csi = str * sin(csi);
zuchk_(&csr, &csi, &nw, ascle, tol);
if (nw != 0) {
goto L10;
}
yr[i__] = csr;
yi[i__] = csi;
ic = i__;
--(*nz);
L10:
;
}
if (*n == 1) {
return 0;
}
if (ic > 1) {
goto L20;
}
yr[1] = zeror;
yi[1] = zeroi;
*nz = 2;
L20:
if (*n == 2) {
return 0;
}
if (*nz == 0) {
return 0;
}
fn = *fnu + 1.;
ckr = fn * *rzr;
cki = fn * *rzi;
s1r = cyr[0];
s1i = cyi[0];
s2r = cyr[1];
s2i = cyi[1];
helim = *elim * .5;
elm = exp(-(*elim));
celmr = elm;
zdr = *zrr;
zdi = *zri;
/* FIND TWO CONSECUTIVE Y VALUES ON SCALE. SCALE RECURRENCE IF */
/* S2 GETS LARGER THAN EXP(ELIM/2) */
i__1 = *n;
for (i__ = 3; i__ <= i__1; ++i__) {
kk = i__;
csr = s2r;
csi = s2i;
s2r = ckr * csr - cki * csi + s1r;
s2i = cki * csr + ckr * csi + s1i;
s1r = csr;
s1i = csi;
ckr += *rzr;
cki += *rzi;
as = xzabs_(&s2r, &s2i);
alas = log(as);
acs = -zdr + alas;
++(*nz);
yr[i__] = zeror;
yi[i__] = zeroi;
if (acs < -(*elim)) {
goto L25;
}
xzlog_(&s2r, &s2i, &csr, &csi, &idum);
csr -= zdr;
csi -= zdi;
str = exp(csr) / *tol;
csr = str * cos(csi);
csi = str * sin(csi);
zuchk_(&csr, &csi, &nw, ascle, tol);
if (nw != 0) {
goto L25;
}
yr[i__] = csr;
yi[i__] = csi;
--(*nz);
if (ic == kk - 1) {
goto L40;
}
ic = kk;
goto L30;
L25:
if (alas < helim) {
goto L30;
}
zdr -= *elim;
s1r *= celmr;
s1i *= celmr;
s2r *= celmr;
s2i *= celmr;
L30:
;
}
*nz = *n;
if (ic == *n) {
*nz = *n - 1;
}
goto L45;
L40:
*nz = kk - 2;
L45:
i__1 = *nz;
for (i__ = 1; i__ <= i__1; ++i__) {
yr[i__] = zeror;
yi[i__] = zeroi;
/* L50: */
}
return 0;
} /* zkscl_ */
static int zbknu_(double *zr, double *zi, double *fnu,
int *kode, int *n, double *yr, double *yi, int *nz,
double *tol, double *elim, double *alim)
{
/* Initialized data */
static int kmax = 30;
static double spi = 1.90985931710274403;
static double hpi = 1.57079632679489662;
static double fpi = 1.89769999331517738;
static double tth = .666666666666666666;
static double cc[8] = { .577215664901532861,-.0420026350340952355,
-.0421977345555443367,.00721894324666309954,
-2.15241674114950973e-4,-2.01348547807882387e-5,
1.13302723198169588e-6,6.11609510448141582e-9 };
static double czeror = 0.;
static double czeroi = 0.;
static double coner = 1.;
static double conei = 0.;
static double ctwor = 2.;
static double r1 = 2.;
static double dpi = 3.14159265358979324;
static double rthpi = 1.25331413731550025;
/* System generated locals */
int i__1;
double d__1;
/* Local variables */
static int i__, j, k;
static double s, a1, a2, g1, g2, t1, t2, aa, bb, fc, ak, bk;
static int ic;
static double fi, fk, as;
static int kk;