w_jn.c 2.1 KB

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