ynl.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* ynl.c
  2. *
  3. * Bessel function of second kind of integer order
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * long double x, y, ynl();
  10. * int n;
  11. *
  12. * y = ynl( n, x );
  13. *
  14. *
  15. *
  16. * DESCRIPTION:
  17. *
  18. * Returns Bessel function of order n, where n is a
  19. * (possibly negative) integer.
  20. *
  21. * The function is evaluated by forward recurrence on
  22. * n, starting with values computed by the routines
  23. * y0l() and y1l().
  24. *
  25. * If n = 0 or 1 the routine for y0l or y1l is called
  26. * directly.
  27. *
  28. *
  29. *
  30. * ACCURACY:
  31. *
  32. *
  33. * Absolute error, except relative error when y > 1.
  34. * x >= 0, -30 <= n <= +30.
  35. * arithmetic domain # trials peak rms
  36. * IEEE -30, 30 10000 1.3e-18 1.8e-19
  37. *
  38. *
  39. * ERROR MESSAGES:
  40. *
  41. * message condition value returned
  42. * ynl singularity x = 0 MAXNUML
  43. * ynl overflow MAXNUML
  44. *
  45. * Spot checked against tables for x, n between 0 and 100.
  46. *
  47. */
  48. /*
  49. Cephes Math Library Release 2.1: December, 1988
  50. Copyright 1984, 1987 by Stephen L. Moshier
  51. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  52. */
  53. #include <math.h>
  54. extern long double MAXNUML;
  55. #ifdef ANSIPROT
  56. extern long double y0l ( long double );
  57. extern long double y1l ( long double );
  58. #else
  59. long double y0l(), y1l();
  60. #endif
  61. long double ynl( n, x )
  62. int n;
  63. long double x;
  64. {
  65. long double an, anm1, anm2, r;
  66. int k, sign;
  67. if( n < 0 )
  68. {
  69. n = -n;
  70. if( (n & 1) == 0 ) /* -1**n */
  71. sign = 1;
  72. else
  73. sign = -1;
  74. }
  75. else
  76. sign = 1;
  77. if( n == 0 )
  78. return( sign * y0l(x) );
  79. if( n == 1 )
  80. return( sign * y1l(x) );
  81. /* test for overflow */
  82. if( x <= 0.0L )
  83. {
  84. mtherr( "ynl", SING );
  85. return( -MAXNUML );
  86. }
  87. /* forward recurrence on n */
  88. anm2 = y0l(x);
  89. anm1 = y1l(x);
  90. k = 1;
  91. r = 2 * k;
  92. do
  93. {
  94. an = r * anm1 / x - anm2;
  95. anm2 = anm1;
  96. anm1 = an;
  97. r += 2.0L;
  98. ++k;
  99. }
  100. while( k < n );
  101. return( sign * an );
  102. }