i1f.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* i1f.c
  2. *
  3. * Modified Bessel function of order one
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, i1f();
  10. *
  11. * y = i1f( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns modified Bessel function of order one of the
  18. * argument.
  19. *
  20. * The function is defined as i1(x) = -i j1( ix ).
  21. *
  22. * The range is partitioned into the two intervals [0,8] and
  23. * (8, infinity). Chebyshev polynomial expansions are employed
  24. * in each interval.
  25. *
  26. *
  27. *
  28. * ACCURACY:
  29. *
  30. * Relative error:
  31. * arithmetic domain # trials peak rms
  32. * IEEE 0, 30 100000 1.5e-6 1.6e-7
  33. *
  34. *
  35. */
  36. /* i1ef.c
  37. *
  38. * Modified Bessel function of order one,
  39. * exponentially scaled
  40. *
  41. *
  42. *
  43. * SYNOPSIS:
  44. *
  45. * float x, y, i1ef();
  46. *
  47. * y = i1ef( x );
  48. *
  49. *
  50. *
  51. * DESCRIPTION:
  52. *
  53. * Returns exponentially scaled modified Bessel function
  54. * of order one of the argument.
  55. *
  56. * The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
  57. *
  58. *
  59. *
  60. * ACCURACY:
  61. *
  62. * Relative error:
  63. * arithmetic domain # trials peak rms
  64. * IEEE 0, 30 30000 1.5e-6 1.5e-7
  65. * See i1().
  66. *
  67. */
  68. /* i1.c 2 */
  69. /*
  70. Cephes Math Library Release 2.0: March, 1987
  71. Copyright 1985, 1987 by Stephen L. Moshier
  72. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  73. */
  74. #include <math.h>
  75. /* Chebyshev coefficients for exp(-x) I1(x) / x
  76. * in the interval [0,8].
  77. *
  78. * lim(x->0){ exp(-x) I1(x) / x } = 1/2.
  79. */
  80. static float A[] =
  81. {
  82. 9.38153738649577178388E-9f,
  83. -4.44505912879632808065E-8f,
  84. 2.00329475355213526229E-7f,
  85. -8.56872026469545474066E-7f,
  86. 3.47025130813767847674E-6f,
  87. -1.32731636560394358279E-5f,
  88. 4.78156510755005422638E-5f,
  89. -1.61760815825896745588E-4f,
  90. 5.12285956168575772895E-4f,
  91. -1.51357245063125314899E-3f,
  92. 4.15642294431288815669E-3f,
  93. -1.05640848946261981558E-2f,
  94. 2.47264490306265168283E-2f,
  95. -5.29459812080949914269E-2f,
  96. 1.02643658689847095384E-1f,
  97. -1.76416518357834055153E-1f,
  98. 2.52587186443633654823E-1f
  99. };
  100. /* Chebyshev coefficients for exp(-x) sqrt(x) I1(x)
  101. * in the inverted interval [8,infinity].
  102. *
  103. * lim(x->inf){ exp(-x) sqrt(x) I1(x) } = 1/sqrt(2pi).
  104. */
  105. static float B[] =
  106. {
  107. -3.83538038596423702205E-9f,
  108. -2.63146884688951950684E-8f,
  109. -2.51223623787020892529E-7f,
  110. -3.88256480887769039346E-6f,
  111. -1.10588938762623716291E-4f,
  112. -9.76109749136146840777E-3f,
  113. 7.78576235018280120474E-1f
  114. };
  115. /* i1.c */
  116. #define fabsf(x) ( (x) < 0 ? -(x) : (x) )
  117. #ifdef ANSIC
  118. float chbevlf(float, float *, int);
  119. float expf(float), sqrtf(float);
  120. #else
  121. float chbevlf(), expf(), sqrtf();
  122. #endif
  123. float i1f(float xx)
  124. {
  125. float x, y, z;
  126. x = xx;
  127. z = fabsf(x);
  128. if( z <= 8.0f )
  129. {
  130. y = 0.5f*z - 2.0f;
  131. z = chbevlf( y, A, 17 ) * z * expf(z);
  132. }
  133. else
  134. {
  135. z = expf(z) * chbevlf( 32.0f/z - 2.0f, B, 7 ) / sqrtf(z);
  136. }
  137. if( x < 0.0f )
  138. z = -z;
  139. return( z );
  140. }
  141. /* i1e() */
  142. float i1ef( float xx )
  143. {
  144. float x, y, z;
  145. x = xx;
  146. z = fabsf(x);
  147. if( z <= 8.0f )
  148. {
  149. y = 0.5f*z - 2.0f;
  150. z = chbevlf( y, A, 17 ) * z;
  151. }
  152. else
  153. {
  154. z = chbevlf( 32.0f/z - 2.0f, B, 7 ) / sqrtf(z);
  155. }
  156. if( x < 0.0f )
  157. z = -z;
  158. return( z );
  159. }