zbesk.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* zbesk.f -- translated by f2c (version 20100827).
  2. This file no longer depends on f2c.
  3. */
  4. #include "slatec-internal.hpp"
  5. /* Table of constant values */
  6. static integer const c__4 = 4;
  7. static integer const c__15 = 15;
  8. static integer const c__16 = 16;
  9. static integer const c__5 = 5;
  10. static integer const c__14 = 14;
  11. static integer const c__9 = 9;
  12. static integer const c__1 = 1;
  13. static integer const c__2 = 2;
  14. int zbesk_(double *zr, double *zi, double const *fnu,
  15. integer const *kode, integer const *n, double *cyr, double *cyi, integer *
  16. nz, integer *ierr)
  17. {
  18. /* System generated locals */
  19. integer i__1, i__2;
  20. double d__1;
  21. /* Local variables */
  22. integer k, k1, k2;
  23. double aa, bb, fn, az;
  24. integer nn;
  25. double rl;
  26. integer mr, nw;
  27. double dig, arg, aln, r1m5, ufl;
  28. integer nuf;
  29. double tol, alim, elim;
  30. double fnul;
  31. /* ***BEGIN PROLOGUE ZBESK */
  32. /* ***PURPOSE Compute a sequence of the Bessel functions K(a,z) for */
  33. /* complex argument z and real nonnegative orders a=b,b+1, */
  34. /* b+2,... where b>0. A scaling option is available to */
  35. /* help avoid overflow. */
  36. /* ***LIBRARY SLATEC */
  37. /* ***CATEGORY C10B4 */
  38. /* ***TYPE COMPLEX (CBESK-C, ZBESK-C) */
  39. /* ***KEYWORDS BESSEL FUNCTIONS OF COMPLEX ARGUMENT, K BESSEL FUNCTIONS, */
  40. /* MODIFIED BESSEL FUNCTIONS */
  41. /* ***AUTHOR Amos, D. E., (SNL) */
  42. /* ***DESCRIPTION */
  43. /* ***A DOUBLE PRECISION ROUTINE*** */
  44. /* On KODE=1, ZBESK computes an N member sequence of complex */
  45. /* Bessel functions CY(L)=K(FNU+L-1,Z) for real nonnegative */
  46. /* orders FNU+L-1, L=1,...,N and complex Z.NE.0 in the cut */
  47. /* plane -pi<arg(Z)<=pi where Z=ZR+i*ZI. On KODE=2, CBESJ */
  48. /* returns the scaled functions */
  49. /* CY(L) = exp(Z)*K(FNU+L-1,Z), L=1,...,N */
  50. /* which remove the exponential growth in both the left and */
  51. /* right half planes as Z goes to infinity. Definitions and */
  52. /* notation are found in the NBS Handbook of Mathematical */
  53. /* Functions (Ref. 1). */
  54. /* Input */
  55. /* ZR - DOUBLE PRECISION REAL part of nonzero argument Z */
  56. /* ZI - DOUBLE PRECISION imag part of nonzero argument Z */
  57. /* FNU - DOUBLE PRECISION initial order, FNU>=0 */
  58. /* KODE - A parameter to indicate the scaling option */
  59. /* KODE=1 returns */
  60. /* CY(L)=K(FNU+L-1,Z), L=1,...,N */
  61. /* =2 returns */
  62. /* CY(L)=K(FNU+L-1,Z)*EXP(Z), L=1,...,N */
  63. /* N - Number of terms in the sequence, N>=1 */
  64. /* Output */
  65. /* CYR - DOUBLE PRECISION REAL part of result vector */
  66. /* CYI - DOUBLE PRECISION imag part of result vector */
  67. /* NZ - Number of underflows set to zero */
  68. /* NZ=0 Normal return */
  69. /* NZ>0 CY(L)=0 for NZ values of L (if Re(Z)>0 */
  70. /* then CY(L)=0 for L=1,...,NZ; in the */
  71. /* complementary half plane the underflows */
  72. /* may not be in an uninterrupted sequence) */
  73. /* IERR - Error flag */
  74. /* IERR=0 Normal return - COMPUTATION COMPLETED */
  75. /* IERR=1 Input error - NO COMPUTATION */
  76. /* IERR=2 Overflow - NO COMPUTATION */
  77. /* (abs(Z) too small and/or FNU+N-1 */
  78. /* too large) */
  79. /* IERR=3 Precision warning - COMPUTATION COMPLETED */
  80. /* (Result has half precision or less */
  81. /* because abs(Z) or FNU+N-1 is large) */
  82. /* IERR=4 Precision error - NO COMPUTATION */
  83. /* (Result has no precision because */
  84. /* abs(Z) or FNU+N-1 is too large) */
  85. /* IERR=5 Algorithmic error - NO COMPUTATION */
  86. /* (Termination condition not met) */
  87. /* *Long Description: */
  88. /* Equations of the reference are implemented to compute K(a,z) */
  89. /* for small orders a and a+1 in the right half plane Re(z)>=0. */
  90. /* Forward recurrence generates higher orders. The formula */
  91. /* K(a,z*exp((t)) = exp(-t)*K(a,z) - t*I(a,z), Re(z)>0 */
  92. /* t = i*pi or -i*pi */
  93. /* continues K to the left half plane. */
  94. /* For large orders, K(a,z) is computed by means of its uniform */
  95. /* asymptotic expansion. */
  96. /* For negative orders, the formula */
  97. /* K(-a,z) = K(a,z) */
  98. /* can be used. */
  99. /* CBESK assumes that a significant digit sinh function is */
  100. /* available. */
  101. /* In most complex variable computation, one must evaluate ele- */
  102. /* mentary functions. When the magnitude of Z or FNU+N-1 is */
  103. /* large, losses of significance by argument reduction occur. */
  104. /* Consequently, if either one exceeds U1=SQRT(0.5/UR), then */
  105. /* losses exceeding half precision are likely and an error flag */
  106. /* IERR=3 is triggered where UR=MAX(D1MACH(4),1.0D-18) is double */
  107. /* precision unit roundoff limited to 18 digits precision. Also, */
  108. /* if either is larger than U2=0.5/UR, then all significance is */
  109. /* lost and IERR=4. In order to use the INT function, arguments */
  110. /* must be further restricted not to exceed the largest machine */
  111. /* integer, U3=I1MACH(9). Thus, the magnitude of Z and FNU+N-1 */
  112. /* is restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2, and */
  113. /* U3 approximate 2.0E+3, 4.2E+6, 2.1E+9 in single precision */
  114. /* and 4.7E+7, 2.3E+15 and 2.1E+9 in double precision. This */
  115. /* makes U2 limiting in single precision and U3 limiting in */
  116. /* double precision. This means that one can expect to retain, */
  117. /* in the worst cases on IEEE machines, no digits in single pre- */
  118. /* cision and only 6 digits in double precision. Similar con- */
  119. /* siderations hold for other machines. */
  120. /* The approximate relative error in the magnitude of a complex */
  121. /* Bessel function can be expressed as P*10**S where P=MAX(UNIT */
  122. /* ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre- */
  123. /* sents the increase in error due to argument reduction in the */
  124. /* elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))), */
  125. /* ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF */
  126. /* ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may */
  127. /* have only absolute accuracy. This is most likely to occur */
  128. /* when one component (in magnitude) is larger than the other by */
  129. /* several orders of magnitude. If one component is 10**K larger */
  130. /* than the other, then one can expect only MAX(ABS(LOG10(P))-K, */
  131. /* 0) significant digits; or, stated another way, when K exceeds */
  132. /* the exponent of P, no significant digits remain in the smaller */
  133. /* component. However, the phase angle retains absolute accuracy */
  134. /* because, in complex arithmetic with precision P, the smaller */
  135. /* component will not (as a rule) decrease below P times the */
  136. /* magnitude of the larger component. In these extreme cases, */
  137. /* the principal phase angle is on the order of +P, -P, PI/2-P, */
  138. /* or -PI/2+P. */
  139. /* ***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe- */
  140. /* matical Functions, National Bureau of Standards */
  141. /* Applied Mathematics Series 55, U. S. Department */
  142. /* of Commerce, Tenth Printing (1972) or later. */
  143. /* 2. D. E. Amos, Computation of Bessel Functions of */
  144. /* Complex Argument, Report SAND83-0086, Sandia National */
  145. /* Laboratories, Albuquerque, NM, May 1983. */
  146. /* 3. D. E. Amos, Computation of Bessel Functions of */
  147. /* Complex Argument and Large Order, Report SAND83-0643, */
  148. /* Sandia National Laboratories, Albuquerque, NM, May */
  149. /* 1983. */
  150. /* 4. D. E. Amos, A Subroutine Package for Bessel Functions */
  151. /* of a Complex Argument and Nonnegative Order, Report */
  152. /* SAND85-1018, Sandia National Laboratory, Albuquerque, */
  153. /* NM, May 1985. */
  154. /* 5. D. E. Amos, A portable package for Bessel functions */
  155. /* of a complex argument and nonnegative order, ACM */
  156. /* Transactions on Mathematical Software, 12 (September */
  157. /* 1986), pp. 265-273. */
  158. /* ***ROUTINES CALLED D1MACH, I1MACH, ZABS, ZACON, ZBKNU, ZBUNK, ZUOIK */
  159. /* ***REVISION HISTORY (YYMMDD) */
  160. /* 830501 DATE WRITTEN */
  161. /* 890801 REVISION DATE from Version 3.2 */
  162. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  163. /* 920128 Category corrected. (WRB) */
  164. /* 920811 Prologue revised. (DWL) */
  165. /* ***END PROLOGUE ZBESK */
  166. /* COMPLEX CY,Z */
  167. /* ***FIRST EXECUTABLE STATEMENT ZBESK */
  168. /* Parameter adjustments */
  169. --cyi;
  170. --cyr;
  171. /* Function Body */
  172. *ierr = 0;
  173. *nz = 0;
  174. if (*zi == (float)0. && *zr == (float)0.) {
  175. *ierr = 1;
  176. }
  177. if (*fnu < 0.) {
  178. *ierr = 1;
  179. }
  180. if (*kode < 1 || *kode > 2) {
  181. *ierr = 1;
  182. }
  183. if (*n < 1) {
  184. *ierr = 1;
  185. }
  186. if (*ierr != 0) {
  187. return 0;
  188. }
  189. nn = *n;
  190. /* ----------------------------------------------------------------------- */
  191. /* SET PARAMETERS RELATED TO MACHINE CONSTANTS. */
  192. /* TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18. */
  193. /* ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT. */
  194. /* EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND */
  195. /* EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR */
  196. /* UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE. */
  197. /* RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z. */
  198. /* DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG). */
  199. /* FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU */
  200. /* ----------------------------------------------------------------------- */
  201. /* Computing MAX */
  202. d__1 = d1mach_(4);
  203. tol = max(d__1,1e-18);
  204. k1 = i1mach_(15);
  205. k2 = i1mach_(16);
  206. r1m5 = d1mach_(5);
  207. /* Computing MIN */
  208. i__1 = abs(k1), i__2 = abs(k2);
  209. k = min(i__1,i__2);
  210. elim = (k * r1m5 - 3.) * 2.303;
  211. k1 = i1mach_(14) - 1;
  212. aa = r1m5 * k1;
  213. dig = min(aa,18.);
  214. aa *= 2.303;
  215. /* Computing MAX */
  216. d__1 = -aa;
  217. alim = elim + max(d__1,-41.45);
  218. fnul = (dig - 3.) * 6. + 10.;
  219. rl = dig * 1.2 + 3.;
  220. /* ----------------------------------------------------------------------- */
  221. /* TEST FOR PROPER RANGE */
  222. /* ----------------------------------------------------------------------- */
  223. az = zabs_(zr, zi);
  224. fn = *fnu + (nn - 1);
  225. aa = .5 / tol;
  226. bb = i1mach_(9) * .5;
  227. aa = min(aa,bb);
  228. if (az > aa) {
  229. goto L260;
  230. }
  231. if (fn > aa) {
  232. goto L260;
  233. }
  234. aa = sqrt(aa);
  235. if (az > aa) {
  236. *ierr = 3;
  237. }
  238. if (fn > aa) {
  239. *ierr = 3;
  240. }
  241. /* ----------------------------------------------------------------------- */
  242. /* OVERFLOW TEST ON THE LAST MEMBER OF THE SEQUENCE */
  243. /* ----------------------------------------------------------------------- */
  244. /* UFL = EXP(-ELIM) */
  245. ufl = d1mach_(1) * 1e3;
  246. if (az < ufl) {
  247. goto L180;
  248. }
  249. if (*fnu > fnul) {
  250. goto L80;
  251. }
  252. if (fn <= 1.) {
  253. goto L60;
  254. }
  255. if (fn > 2.) {
  256. goto L50;
  257. }
  258. if (az > tol) {
  259. goto L60;
  260. }
  261. arg = az * .5;
  262. aln = -fn * log(arg);
  263. if (aln > elim) {
  264. goto L180;
  265. }
  266. goto L60;
  267. L50:
  268. zuoik_(zr, zi, fnu, kode, &c__2, &nn, &cyr[1], &cyi[1], &nuf, &tol, &elim,
  269. &alim);
  270. if (nuf < 0) {
  271. goto L180;
  272. }
  273. *nz += nuf;
  274. nn -= nuf;
  275. /* ----------------------------------------------------------------------- */
  276. /* HERE NN=N OR NN=0 SINCE NUF=0,NN, OR -1 ON RETURN FROM CUOIK */
  277. /* IF NUF=NN, THEN CY(I)=CZERO FOR ALL I */
  278. /* ----------------------------------------------------------------------- */
  279. if (nn == 0) {
  280. goto L100;
  281. }
  282. L60:
  283. if (*zr < 0.) {
  284. goto L70;
  285. }
  286. /* ----------------------------------------------------------------------- */
  287. /* RIGHT HALF PLANE COMPUTATION, REAL(Z).GE.0. */
  288. /* ----------------------------------------------------------------------- */
  289. zbknu_(zr, zi, fnu, kode, &nn, &cyr[1], &cyi[1], &nw, &tol, &elim, &alim);
  290. if (nw < 0) {
  291. goto L200;
  292. }
  293. *nz = nw;
  294. return 0;
  295. /* ----------------------------------------------------------------------- */
  296. /* LEFT HALF PLANE COMPUTATION */
  297. /* PI/2.LT.ARG(Z).LE.PI AND -PI.LT.ARG(Z).LT.-PI/2. */
  298. /* ----------------------------------------------------------------------- */
  299. L70:
  300. if (*nz != 0) {
  301. goto L180;
  302. }
  303. mr = 1;
  304. if (*zi < 0.) {
  305. mr = -1;
  306. }
  307. zacon_(zr, zi, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &rl, &fnul, &
  308. tol, &elim, &alim);
  309. if (nw < 0) {
  310. goto L200;
  311. }
  312. *nz = nw;
  313. return 0;
  314. /* ----------------------------------------------------------------------- */
  315. /* UNIFORM ASYMPTOTIC EXPANSIONS FOR FNU.GT.FNUL */
  316. /* ----------------------------------------------------------------------- */
  317. L80:
  318. mr = 0;
  319. if (*zr >= 0.) {
  320. goto L90;
  321. }
  322. mr = 1;
  323. if (*zi < 0.) {
  324. mr = -1;
  325. }
  326. L90:
  327. zbunk_(zr, zi, fnu, kode, &mr, &nn, &cyr[1], &cyi[1], &nw, &tol, &elim, &
  328. alim);
  329. if (nw < 0) {
  330. goto L200;
  331. }
  332. *nz += nw;
  333. return 0;
  334. L100:
  335. if (*zr < 0.) {
  336. goto L180;
  337. }
  338. return 0;
  339. L180:
  340. *nz = 0;
  341. *ierr = 2;
  342. return 0;
  343. L200:
  344. if (nw == -1) {
  345. goto L180;
  346. }
  347. *nz = 0;
  348. *ierr = 5;
  349. return 0;
  350. L260:
  351. *nz = 0;
  352. *ierr = 4;
  353. return 0;
  354. } /* zbesk_ */