i0f.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* i0f.c
  2. *
  3. * Modified Bessel function of order zero
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, i0();
  10. *
  11. * y = i0f( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns modified Bessel function of order zero of the
  18. * argument.
  19. *
  20. * The function is defined as i0(x) = j0( 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 4.0e-7 7.9e-8
  33. *
  34. */
  35. /* i0ef.c
  36. *
  37. * Modified Bessel function of order zero,
  38. * exponentially scaled
  39. *
  40. *
  41. *
  42. * SYNOPSIS:
  43. *
  44. * float x, y, i0ef();
  45. *
  46. * y = i0ef( x );
  47. *
  48. *
  49. *
  50. * DESCRIPTION:
  51. *
  52. * Returns exponentially scaled modified Bessel function
  53. * of order zero of the argument.
  54. *
  55. * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
  56. *
  57. *
  58. *
  59. * ACCURACY:
  60. *
  61. * Relative error:
  62. * arithmetic domain # trials peak rms
  63. * IEEE 0,30 100000 3.7e-7 7.0e-8
  64. * See i0f().
  65. *
  66. */
  67. /* i0.c */
  68. /*
  69. Cephes Math Library Release 2.2: June, 1992
  70. Copyright 1984, 1987, 1992 by Stephen L. Moshier
  71. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  72. */
  73. #include <math.h>
  74. /* Chebyshev coefficients for exp(-x) I0(x)
  75. * in the interval [0,8].
  76. *
  77. * lim(x->0){ exp(-x) I0(x) } = 1.
  78. */
  79. static float A[] =
  80. {
  81. -1.30002500998624804212E-8f,
  82. 6.04699502254191894932E-8f,
  83. -2.67079385394061173391E-7f,
  84. 1.11738753912010371815E-6f,
  85. -4.41673835845875056359E-6f,
  86. 1.64484480707288970893E-5f,
  87. -5.75419501008210370398E-5f,
  88. 1.88502885095841655729E-4f,
  89. -5.76375574538582365885E-4f,
  90. 1.63947561694133579842E-3f,
  91. -4.32430999505057594430E-3f,
  92. 1.05464603945949983183E-2f,
  93. -2.37374148058994688156E-2f,
  94. 4.93052842396707084878E-2f,
  95. -9.49010970480476444210E-2f,
  96. 1.71620901522208775349E-1f,
  97. -3.04682672343198398683E-1f,
  98. 6.76795274409476084995E-1f
  99. };
  100. /* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
  101. * in the inverted interval [8,infinity].
  102. *
  103. * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
  104. */
  105. static float B[] =
  106. {
  107. 3.39623202570838634515E-9f,
  108. 2.26666899049817806459E-8f,
  109. 2.04891858946906374183E-7f,
  110. 2.89137052083475648297E-6f,
  111. 6.88975834691682398426E-5f,
  112. 3.36911647825569408990E-3f,
  113. 8.04490411014108831608E-1f
  114. };
  115. float chbevlf(float, float *, int), expf(float), sqrtf(float);
  116. float i0f( float x )
  117. {
  118. float y;
  119. if( x < 0 )
  120. x = -x;
  121. if( x <= 8.0f )
  122. {
  123. y = 0.5f*x - 2.0f;
  124. return( expf(x) * chbevlf( y, A, 18 ) );
  125. }
  126. return( expf(x) * chbevlf( 32.0f/x - 2.0f, B, 7 ) / sqrtf(x) );
  127. }
  128. float chbevlf(float, float *, int), expf(float), sqrtf(float);
  129. float i0ef( float x )
  130. {
  131. float y;
  132. if( x < 0 )
  133. x = -x;
  134. if( x <= 8.0f )
  135. {
  136. y = 0.5f*x - 2.0f;
  137. return( chbevlf( y, A, 18 ) );
  138. }
  139. return( chbevlf( 32.0f/x - 2.0f, B, 7 ) / sqrtf(x) );
  140. }