w_jn.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef __STDC__
  62. double yn(int n, double x) /* wrapper yn */
  63. #else
  64. double yn(n,x) /* wrapper yn */
  65. double x; int n;
  66. #endif
  67. {
  68. #ifdef _IEEE_LIBM
  69. return __ieee754_yn(n,x);
  70. #else
  71. double z;
  72. z = __ieee754_yn(n,x);
  73. if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
  74. if(x <= 0.0){
  75. if(x==0.0)
  76. /* d= -one/(x-x); */
  77. return __kernel_standard((double)n,x,12);
  78. else
  79. /* d = zero/(x-x); */
  80. return __kernel_standard((double)n,x,13);
  81. }
  82. if(x>X_TLOSS) {
  83. return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
  84. } else
  85. return z;
  86. #endif
  87. }