w_jn.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* @(#)w_jn.c 5.1 93/09/24 */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. #if defined(LIBM_SCCS) && !defined(lint)
  13. static char rcsid[] = "$NetBSD: w_jn.c,v 1.6 1995/05/10 20:49:19 jtc Exp $";
  14. #endif
  15. /*
  16. * wrapper jn(int n, double x), yn(int n, double x)
  17. * floating point Bessel's function of the 1st and 2nd kind
  18. * of order n
  19. *
  20. * Special cases:
  21. * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
  22. * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
  23. * Note 2. About jn(n,x), yn(n,x)
  24. * For n=0, j0(x) is called,
  25. * for n=1, j1(x) is called,
  26. * for n<x, forward recursion us used starting
  27. * from values of j0(x) and j1(x).
  28. * for n>x, a continued fraction approximation to
  29. * j(n,x)/j(n-1,x) is evaluated and then backward
  30. * recursion is used starting from a supposed value
  31. * for j(n,x). The resulting value of j(0,x) is
  32. * compared with the actual value to correct the
  33. * supposed value of j(n,x).
  34. *
  35. * yn(n,x) is similar in all respects, except
  36. * that forward recursion is used for all
  37. * values of n>1.
  38. *
  39. */
  40. #include "math.h"
  41. #include "math_private.h"
  42. #ifdef __STDC__
  43. double jn(int n, double x) /* wrapper jn */
  44. #else
  45. double jn(n,x) /* wrapper jn */
  46. double x; int n;
  47. #endif
  48. {
  49. #ifdef _IEEE_LIBM
  50. return __ieee754_jn(n,x);
  51. #else
  52. double z;
  53. z = __ieee754_jn(n,x);
  54. if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
  55. if(fabs(x)>X_TLOSS) {
  56. return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
  57. } else
  58. return z;
  59. #endif
  60. }
  61. libm_hidden_def(jn)
  62. #ifdef __STDC__
  63. double yn(int n, double x) /* wrapper yn */
  64. #else
  65. double yn(n,x) /* wrapper yn */
  66. double x; int n;
  67. #endif
  68. {
  69. #ifdef _IEEE_LIBM
  70. return __ieee754_yn(n,x);
  71. #else
  72. double z;
  73. z = __ieee754_yn(n,x);
  74. if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
  75. if(x <= 0.0){
  76. if(x==0.0)
  77. /* d= -one/(x-x); */
  78. return __kernel_standard((double)n,x,12);
  79. else
  80. /* d = zero/(x-x); */
  81. return __kernel_standard((double)n,x,13);
  82. }
  83. if(x>X_TLOSS) {
  84. return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
  85. } else
  86. return z;
  87. #endif
  88. }
  89. libm_hidden_def(yn)