fresnlf.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* fresnlf.c
  2. *
  3. * Fresnel integral
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, S, C;
  10. * void fresnlf();
  11. *
  12. * fresnlf( x, _&S, _&C );
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Evaluates the Fresnel integrals
  18. *
  19. * x
  20. * -
  21. * | |
  22. * C(x) = | cos(pi/2 t**2) dt,
  23. * | |
  24. * -
  25. * 0
  26. *
  27. * x
  28. * -
  29. * | |
  30. * S(x) = | sin(pi/2 t**2) dt.
  31. * | |
  32. * -
  33. * 0
  34. *
  35. *
  36. * The integrals are evaluated by power series for small x.
  37. * For x >= 1 auxiliary functions f(x) and g(x) are employed
  38. * such that
  39. *
  40. * C(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 )
  41. * S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 )
  42. *
  43. *
  44. *
  45. * ACCURACY:
  46. *
  47. * Relative error.
  48. *
  49. * Arithmetic function domain # trials peak rms
  50. * IEEE S(x) 0, 10 30000 1.1e-6 1.9e-7
  51. * IEEE C(x) 0, 10 30000 1.1e-6 2.0e-7
  52. */
  53. /*
  54. Cephes Math Library Release 2.1: January, 1989
  55. Copyright 1984, 1987, 1989 by Stephen L. Moshier
  56. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  57. */
  58. #include <math.h>
  59. /* S(x) for small x */
  60. static float sn[7] = {
  61. 1.647629463788700E-009,
  62. -1.522754752581096E-007,
  63. 8.424748808502400E-006,
  64. -3.120693124703272E-004,
  65. 7.244727626597022E-003,
  66. -9.228055941124598E-002,
  67. 5.235987735681432E-001
  68. };
  69. /* C(x) for small x */
  70. static float cn[7] = {
  71. 1.416802502367354E-008,
  72. -1.157231412229871E-006,
  73. 5.387223446683264E-005,
  74. -1.604381798862293E-003,
  75. 2.818489036795073E-002,
  76. -2.467398198317899E-001,
  77. 9.999999760004487E-001
  78. };
  79. /* Auxiliary function f(x) */
  80. static float fn[8] = {
  81. -1.903009855649792E+012,
  82. 1.355942388050252E+011,
  83. -4.158143148511033E+009,
  84. 7.343848463587323E+007,
  85. -8.732356681548485E+005,
  86. 8.560515466275470E+003,
  87. -1.032877601091159E+002,
  88. 2.999401847870011E+000
  89. };
  90. /* Auxiliary function g(x) */
  91. static float gn[8] = {
  92. -1.860843997624650E+011,
  93. 1.278350673393208E+010,
  94. -3.779387713202229E+008,
  95. 6.492611570598858E+006,
  96. -7.787789623358162E+004,
  97. 8.602931494734327E+002,
  98. -1.493439396592284E+001,
  99. 9.999841934744914E-001
  100. };
  101. extern float PIF, PIO2F;
  102. #define fabsf(x) ( (x) < 0 ? -(x) : (x) )
  103. #ifdef ANSIC
  104. float polevlf( float, float *, int );
  105. float cosf(float), sinf(float);
  106. #else
  107. float polevlf(), cosf(), sinf();
  108. #endif
  109. void fresnlf( float xxa, float *ssa, float *cca )
  110. {
  111. float f, g, cc, ss, c, s, t, u, x, x2;
  112. x = xxa;
  113. x = fabsf(x);
  114. x2 = x * x;
  115. if( x2 < 2.5625 )
  116. {
  117. t = x2 * x2;
  118. ss = x * x2 * polevlf( t, sn, 6);
  119. cc = x * polevlf( t, cn, 6);
  120. goto done;
  121. }
  122. if( x > 36974.0 )
  123. {
  124. cc = 0.5;
  125. ss = 0.5;
  126. goto done;
  127. }
  128. /* Asymptotic power series auxiliary functions
  129. * for large argument
  130. */
  131. x2 = x * x;
  132. t = PIF * x2;
  133. u = 1.0/(t * t);
  134. t = 1.0/t;
  135. f = 1.0 - u * polevlf( u, fn, 7);
  136. g = t * polevlf( u, gn, 7);
  137. t = PIO2F * x2;
  138. c = cosf(t);
  139. s = sinf(t);
  140. t = PIF * x;
  141. cc = 0.5 + (f * s - g * c)/t;
  142. ss = 0.5 - (f * c + g * s)/t;
  143. done:
  144. if( xxa < 0.0 )
  145. {
  146. cc = -cc;
  147. ss = -ss;
  148. }
  149. *cca = cc;
  150. *ssa = ss;
  151. #if !ANSIC
  152. return 0;
  153. #endif
  154. }