123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- #include "slatec-internal.hpp"
- static integer const c__1 = 1;
- static integer const c__2 = 2;
- static integer const c__4 = 4;
- static integer const c__15 = 15;
- static integer const c__16 = 16;
- static integer const c__5 = 5;
- int zbesy_(double *zr, double *zi, double const *fnu,
- integer const *kode, integer const *n, double *cyr, double *cyi, integer *
- nz, double *cwrkr, double *cwrki, integer *ierr)
- {
-
- integer i__1, i__2;
- double d__1, d__2;
-
- integer i__, k, k1, k2;
- double aa, bb, ey, c1i, c2i, c1r, c2r;
- integer nz1, nz2;
- double exi, r1m5, exr, sti, tay, tol, str, hcii, elim, atol, rtol, ascle;
-
- --cwrki;
- --cwrkr;
- --cyi;
- --cyr;
-
- *ierr = 0;
- *nz = 0;
- if (*zr == 0. && *zi == 0.) {
- *ierr = 1;
- }
- if (*fnu < 0.) {
- *ierr = 1;
- }
- if (*kode < 1 || *kode > 2) {
- *ierr = 1;
- }
- if (*n < 1) {
- *ierr = 1;
- }
- if (*ierr != 0) {
- return 0;
- }
- hcii = .5;
- zbesh_(zr, zi, fnu, kode, &c__1, n, &cyr[1], &cyi[1], &nz1, ierr);
- if (*ierr != 0 && *ierr != 3) {
- goto L170;
- }
- zbesh_(zr, zi, fnu, kode, &c__2, n, &cwrkr[1], &cwrki[1], &nz2, ierr);
- if (*ierr != 0 && *ierr != 3) {
- goto L170;
- }
- *nz = min(nz1,nz2);
- if (*kode == 2) {
- goto L60;
- }
- i__1 = *n;
- for (i__ = 1; i__ <= i__1; ++i__) {
- str = cwrkr[i__] - cyr[i__];
- sti = cwrki[i__] - cyi[i__];
- cyr[i__] = -sti * hcii;
- cyi[i__] = str * hcii;
- }
- return 0;
- L60:
- d__1 = d1mach_(4);
- tol = max(d__1,1e-18);
- k1 = i1mach_(15);
- k2 = i1mach_(16);
- i__1 = abs(k1), i__2 = abs(k2);
- k = min(i__1,i__2);
- r1m5 = d1mach_(5);
- elim = (k * r1m5 - 3.) * 2.303;
- exr = cos(*zr);
- exi = sin(*zr);
- ey = 0.;
- tay = (d__1 = *zi + *zi, abs(d__1));
- if (tay < elim) {
- ey = exp(-tay);
- }
- if (*zi < 0.) {
- goto L90;
- }
- c1r = exr * ey;
- c1i = exi * ey;
- c2r = exr;
- c2i = -exi;
- L70:
- *nz = 0;
- rtol = 1. / tol;
- ascle = d1mach_(1) * rtol * 1e3;
- i__1 = *n;
- for (i__ = 1; i__ <= i__1; ++i__) {
- aa = cwrkr[i__];
- bb = cwrki[i__];
- atol = 1.;
- d__1 = abs(aa), d__2 = abs(bb);
- if (max(d__1,d__2) > ascle) {
- goto L75;
- }
- aa *= rtol;
- bb *= rtol;
- atol = tol;
- L75:
- str = (aa * c2r - bb * c2i) * atol;
- sti = (aa * c2i + bb * c2r) * atol;
- aa = cyr[i__];
- bb = cyi[i__];
- atol = 1.;
- d__1 = abs(aa), d__2 = abs(bb);
- if (max(d__1,d__2) > ascle) {
- goto L85;
- }
- aa *= rtol;
- bb *= rtol;
- atol = tol;
- L85:
- str -= (aa * c1r - bb * c1i) * atol;
- sti -= (aa * c1i + bb * c1r) * atol;
- cyr[i__] = -sti * hcii;
- cyi[i__] = str * hcii;
- if (str == 0. && sti == 0. && ey == 0.) {
- ++(*nz);
- }
- }
- return 0;
- L90:
- c1r = exr;
- c1i = exi;
- c2r = exr * ey;
- c2i = -exi * ey;
- goto L70;
- L170:
- *nz = 0;
- return 0;
- }
|