zasyi.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* zasyi.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__1 = 1;
  7. int zasyi_(double *zr, double *zi, double const *fnu,
  8. integer const *kode, integer const *n, double *yr, double *yi, integer * nz,
  9. double *rl, double *tol, double *elim, double * alim)
  10. {
  11. /* Initialized data */
  12. static double const pi = 3.14159265358979324;
  13. static double const rtpi = .159154943091895336;
  14. static double const zeror = 0.;
  15. static double const zeroi = 0.;
  16. static double const coner = 1.;
  17. static double const conei = 0.;
  18. /* System generated locals */
  19. integer i__1, i__2;
  20. double d__1, d__2;
  21. /* Local variables */
  22. integer i__, j, k, m;
  23. double s, aa, bb;
  24. integer ib;
  25. double ak, bk;
  26. integer il, jl;
  27. double az;
  28. integer nn;
  29. double p1i, s2i, p1r, s2r, cki, dki, fdn, arg, aez, arm, ckr, dkr,
  30. czi, ezi, sgn;
  31. integer inu;
  32. double raz, czr, ezr, sqk, sti, rzi, tzi, str, rzr, tzr, ak1i, ak1r,
  33. cs1i, cs2i, cs1r, cs2r, dnu2, rtr1, dfnu, atol;
  34. integer koded;
  35. /* ***BEGIN PROLOGUE ZASYI */
  36. /* ***SUBSIDIARY */
  37. /* ***PURPOSE Subsidiary to ZBESI and ZBESK */
  38. /* ***LIBRARY SLATEC */
  39. /* ***TYPE ALL (CASYI-A, ZASYI-A) */
  40. /* ***AUTHOR Amos, D. E., (SNL) */
  41. /* ***DESCRIPTION */
  42. /* ZASYI COMPUTES THE I BESSEL FUNCTION FOR REAL(Z).GE.0.0 BY */
  43. /* MEANS OF THE ASYMPTOTIC EXPANSION FOR LARGE ABS(Z) IN THE */
  44. /* REGION ABS(Z).GT.MAX(RL,FNU*FNU/2). NZ=0 IS A NORMAL RETURN. */
  45. /* NZ.LT.0 INDICATES AN OVERFLOW ON KODE=1. */
  46. /* ***SEE ALSO ZBESI, ZBESK */
  47. /* ***ROUTINES CALLED D1MACH, ZABS, ZDIV, ZEXP, ZMLT, ZSQRT */
  48. /* ***REVISION HISTORY (YYMMDD) */
  49. /* 830501 DATE WRITTEN */
  50. /* 910415 Prologue converted to Version 4.0 format. (BAB) */
  51. /* 930122 Added ZEXP and ZSQRT to EXTERNAL statement. (RWC) */
  52. /* ***END PROLOGUE ZASYI */
  53. /* COMPLEX AK1,CK,CONE,CS1,CS2,CZ,CZERO,DK,EZ,P1,RZ,S2,Y,Z */
  54. /* Parameter adjustments */
  55. --yi;
  56. --yr;
  57. /* Function Body */
  58. /* ***FIRST EXECUTABLE STATEMENT ZASYI */
  59. *nz = 0;
  60. az = zabs_(zr, zi);
  61. arm = d1mach_(1) * 1e3;
  62. rtr1 = sqrt(arm);
  63. il = min(2,*n);
  64. dfnu = *fnu + (*n - il);
  65. /* ----------------------------------------------------------------------- */
  66. /* OVERFLOW TEST */
  67. /* ----------------------------------------------------------------------- */
  68. raz = 1. / az;
  69. str = *zr * raz;
  70. sti = -(*zi) * raz;
  71. ak1r = rtpi * str * raz;
  72. ak1i = rtpi * sti * raz;
  73. zsqrt_(&ak1r, &ak1i, &ak1r, &ak1i);
  74. czr = *zr;
  75. czi = *zi;
  76. if (*kode != 2) {
  77. goto L10;
  78. }
  79. czr = zeror;
  80. czi = *zi;
  81. L10:
  82. if (abs(czr) > *elim) {
  83. goto L100;
  84. }
  85. dnu2 = dfnu + dfnu;
  86. koded = 1;
  87. if (abs(czr) > *alim && *n > 2) {
  88. goto L20;
  89. }
  90. koded = 0;
  91. zexp_(&czr, &czi, &str, &sti);
  92. zmlt_(&ak1r, &ak1i, &str, &sti, &ak1r, &ak1i);
  93. L20:
  94. fdn = 0.;
  95. if (dnu2 > rtr1) {
  96. fdn = dnu2 * dnu2;
  97. }
  98. ezr = *zr * 8.;
  99. ezi = *zi * 8.;
  100. /* ----------------------------------------------------------------------- */
  101. /* WHEN Z IS IMAGINARY, THE ERROR TEST MUST BE MADE RELATIVE TO THE */
  102. /* FIRST RECIPROCAL POWER SINCE THIS IS THE LEADING TERM OF THE */
  103. /* EXPANSION FOR THE IMAGINARY PART. */
  104. /* ----------------------------------------------------------------------- */
  105. aez = az * 8.;
  106. s = *tol / aez;
  107. jl = (integer) (*rl + *rl + 2);
  108. p1r = zeror;
  109. p1i = zeroi;
  110. if (*zi == 0.) {
  111. goto L30;
  112. }
  113. /* ----------------------------------------------------------------------- */
  114. /* CALCULATE EXP(PI*(0.5+FNU+N-IL)*I) TO MINIMIZE LOSSES OF */
  115. /* SIGNIFICANCE WHEN FNU OR N IS LARGE */
  116. /* ----------------------------------------------------------------------- */
  117. inu = (integer) (*fnu);
  118. arg = (*fnu - inu) * pi;
  119. inu = inu + *n - il;
  120. ak = -sin(arg);
  121. bk = cos(arg);
  122. if (*zi < 0.) {
  123. bk = -bk;
  124. }
  125. p1r = ak;
  126. p1i = bk;
  127. if (inu % 2 == 0) {
  128. goto L30;
  129. }
  130. p1r = -p1r;
  131. p1i = -p1i;
  132. L30:
  133. i__1 = il;
  134. for (k = 1; k <= i__1; ++k) {
  135. sqk = fdn - 1.;
  136. atol = s * abs(sqk);
  137. sgn = 1.;
  138. cs1r = coner;
  139. cs1i = conei;
  140. cs2r = coner;
  141. cs2i = conei;
  142. ckr = coner;
  143. cki = conei;
  144. ak = 0.;
  145. aa = 1.;
  146. bb = aez;
  147. dkr = ezr;
  148. dki = ezi;
  149. i__2 = jl;
  150. for (j = 1; j <= i__2; ++j) {
  151. zdiv_(&ckr, &cki, &dkr, &dki, &str, &sti);
  152. ckr = str * sqk;
  153. cki = sti * sqk;
  154. cs2r += ckr;
  155. cs2i += cki;
  156. sgn = -sgn;
  157. cs1r += ckr * sgn;
  158. cs1i += cki * sgn;
  159. dkr += ezr;
  160. dki += ezi;
  161. aa = aa * abs(sqk) / bb;
  162. bb += aez;
  163. ak += 8.;
  164. sqk -= ak;
  165. if (aa <= atol) {
  166. goto L50;
  167. }
  168. /* L40: */
  169. }
  170. goto L110;
  171. L50:
  172. s2r = cs1r;
  173. s2i = cs1i;
  174. if (*zr + *zr >= *elim) {
  175. goto L60;
  176. }
  177. tzr = *zr + *zr;
  178. tzi = *zi + *zi;
  179. d__1 = -tzr;
  180. d__2 = -tzi;
  181. zexp_(&d__1, &d__2, &str, &sti);
  182. zmlt_(&str, &sti, &p1r, &p1i, &str, &sti);
  183. zmlt_(&str, &sti, &cs2r, &cs2i, &str, &sti);
  184. s2r += str;
  185. s2i += sti;
  186. L60:
  187. fdn = fdn + dfnu * 8. + 4.;
  188. p1r = -p1r;
  189. p1i = -p1i;
  190. m = *n - il + k;
  191. yr[m] = s2r * ak1r - s2i * ak1i;
  192. yi[m] = s2r * ak1i + s2i * ak1r;
  193. /* L70: */
  194. }
  195. if (*n <= 2) {
  196. return 0;
  197. }
  198. nn = *n;
  199. k = nn - 2;
  200. ak = (double) k;
  201. str = *zr * raz;
  202. sti = -(*zi) * raz;
  203. rzr = (str + str) * raz;
  204. rzi = (sti + sti) * raz;
  205. ib = 3;
  206. i__1 = nn;
  207. for (i__ = ib; i__ <= i__1; ++i__) {
  208. yr[k] = (ak + *fnu) * (rzr * yr[k + 1] - rzi * yi[k + 1]) + yr[k + 2];
  209. yi[k] = (ak + *fnu) * (rzr * yi[k + 1] + rzi * yr[k + 1]) + yi[k + 2];
  210. ak += -1.;
  211. --k;
  212. /* L80: */
  213. }
  214. if (koded == 0) {
  215. return 0;
  216. }
  217. zexp_(&czr, &czi, &ckr, &cki);
  218. i__1 = nn;
  219. for (i__ = 1; i__ <= i__1; ++i__) {
  220. str = yr[i__] * ckr - yi[i__] * cki;
  221. yi[i__] = yr[i__] * cki + yi[i__] * ckr;
  222. yr[i__] = str;
  223. /* L90: */
  224. }
  225. return 0;
  226. L100:
  227. *nz = -1;
  228. return 0;
  229. L110:
  230. *nz = -2;
  231. return 0;
  232. } /* zasyi_ */