dawsn.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* dawsn.c
  2. *
  3. * Dawson's Integral
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, dawsn();
  10. *
  11. * y = dawsn( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Approximates the integral
  18. *
  19. * x
  20. * -
  21. * 2 | | 2
  22. * dawsn(x) = exp( -x ) | exp( t ) dt
  23. * | |
  24. * -
  25. * 0
  26. *
  27. * Three different rational approximations are employed, for
  28. * the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
  29. *
  30. *
  31. * ACCURACY:
  32. *
  33. * Relative error:
  34. * arithmetic domain # trials peak rms
  35. * IEEE 0,10 10000 6.9e-16 1.0e-16
  36. * DEC 0,10 6000 7.4e-17 1.4e-17
  37. *
  38. *
  39. */
  40. /* dawsn.c */
  41. /*
  42. Cephes Math Library Release 2.8: June, 2000
  43. Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
  44. */
  45. #include "mconf.h"
  46. /* Dawson's integral, interval 0 to 3.25 */
  47. #ifdef UNK
  48. static double AN[10] = {
  49. 1.13681498971755972054E-11, 8.49262267667473811108E-10,
  50. 1.94434204175553054283E-8, 9.53151741254484363489E-7,
  51. 3.07828309874913200438E-6, 3.52513368520288738649E-4,
  52. -8.50149846724410912031E-4, 4.22618223005546594270E-2,
  53. -9.17480371773452345351E-2, 9.99999999999999994612E-1,
  54. };
  55. static double AD[11] = {
  56. 2.40372073066762605484E-11, 1.48864681368493396752E-9,
  57. 5.21265281010541664570E-8, 1.27258478273186970203E-6,
  58. 2.32490249820789513991E-5, 3.25524741826057911661E-4,
  59. 3.48805814657162590916E-3, 2.79448531198828973716E-2,
  60. 1.58874241960120565368E-1, 5.74918629489320327824E-1,
  61. 1.00000000000000000539E0,
  62. };
  63. #endif
  64. #ifdef DEC
  65. static unsigned short AN[40] = {
  66. 0027107, 0176630, 0075752, 0107612, 0030551, 0070604, 0166707, 0127727,
  67. 0031647, 0002210, 0117120, 0056376, 0033177, 0156026, 0141275, 0140627,
  68. 0033516, 0112200, 0037035, 0165515, 0035270, 0150613, 0016423, 0105634,
  69. 0135536, 0156227, 0023515, 0044413, 0037055, 0015273, 0105147, 0064025,
  70. 0137273, 0163145, 0014460, 0166465, 0040200, 0000000, 0000000, 0000000,
  71. };
  72. static unsigned short AD[44] = {
  73. 0027323, 0067372, 0115566, 0131320, 0030714, 0114432, 0074206, 0006637,
  74. 0032137, 0160671, 0044203, 0026344, 0033252, 0146656, 0020247, 0100231,
  75. 0034303, 0003346, 0123260, 0022433, 0035252, 0125460, 0173041, 0155415,
  76. 0036144, 0113747, 0125203, 0124617, 0036744, 0166232, 0143671, 0133670,
  77. 0037442, 0127755, 0162625, 0000100, 0040023, 0026736, 0003604, 0106265,
  78. 0040200, 0000000, 0000000, 0000000,
  79. };
  80. #endif
  81. #ifdef IBMPC
  82. static unsigned short AN[40] = {
  83. 0x51f1, 0x0f7d, 0xffb3, 0x3da8, 0xf5fb, 0x9db8, 0x2e30, 0x3e0d,
  84. 0x0ba0, 0x13ca, 0xe091, 0x3e54, 0xb833, 0xd857, 0xfb82, 0x3eaf,
  85. 0xbd6a, 0x07c3, 0xd290, 0x3ec9, 0x7174, 0x63a2, 0x1a31, 0x3f37,
  86. 0xa921, 0xe4e9, 0xdb92, 0xbf4b, 0xed03, 0x714c, 0xa357, 0x3fa5,
  87. 0x1da7, 0xa326, 0x7ccc, 0xbfb7, 0x0000, 0x0000, 0x0000, 0x3ff0,
  88. };
  89. static unsigned short AD[44] = {
  90. 0xd65a, 0x536e, 0x6ddf, 0x3dba, 0xc1b4, 0x4f10, 0x9323, 0x3e19, 0x659c,
  91. 0x2910, 0xfc37, 0x3e6b, 0xf013, 0xc414, 0x59b5, 0x3eb5, 0x04a3, 0xd4d6,
  92. 0x60dc, 0x3ef8, 0x3b62, 0x1ec4, 0x5566, 0x3f35, 0x7532, 0xf550, 0x92fc,
  93. 0x3f6c, 0x36f7, 0x58f7, 0x9d93, 0x3f9c, 0xa008, 0xbcb2, 0x55fd, 0x3fc4,
  94. 0x9197, 0xc0f0, 0x65bb, 0x3fe2, 0x0000, 0x0000, 0x0000, 0x3ff0,
  95. };
  96. #endif
  97. #ifdef MIEEE
  98. static unsigned short AN[40] = {
  99. 0x3da8, 0xffb3, 0x0f7d, 0x51f1, 0x3e0d, 0x2e30, 0x9db8, 0xf5fb,
  100. 0x3e54, 0xe091, 0x13ca, 0x0ba0, 0x3eaf, 0xfb82, 0xd857, 0xb833,
  101. 0x3ec9, 0xd290, 0x07c3, 0xbd6a, 0x3f37, 0x1a31, 0x63a2, 0x7174,
  102. 0xbf4b, 0xdb92, 0xe4e9, 0xa921, 0x3fa5, 0xa357, 0x714c, 0xed03,
  103. 0xbfb7, 0x7ccc, 0xa326, 0x1da7, 0x3ff0, 0x0000, 0x0000, 0x0000,
  104. };
  105. static unsigned short AD[44] = {
  106. 0x3dba, 0x6ddf, 0x536e, 0xd65a, 0x3e19, 0x9323, 0x4f10, 0xc1b4, 0x3e6b,
  107. 0xfc37, 0x2910, 0x659c, 0x3eb5, 0x59b5, 0xc414, 0xf013, 0x3ef8, 0x60dc,
  108. 0xd4d6, 0x04a3, 0x3f35, 0x5566, 0x1ec4, 0x3b62, 0x3f6c, 0x92fc, 0xf550,
  109. 0x7532, 0x3f9c, 0x9d93, 0x58f7, 0x36f7, 0x3fc4, 0x55fd, 0xbcb2, 0xa008,
  110. 0x3fe2, 0x65bb, 0xc0f0, 0x9197, 0x3ff0, 0x0000, 0x0000, 0x0000,
  111. };
  112. #endif
  113. /* interval 3.25 to 6.25 */
  114. #ifdef UNK
  115. static double BN[11] = {
  116. 5.08955156417900903354E-1, -2.44754418142697847934E-1,
  117. 9.41512335303534411857E-2, -2.18711255142039025206E-2,
  118. 3.66207612329569181322E-3, -4.23209114460388756528E-4,
  119. 3.59641304793896631888E-5, -2.14640351719968974225E-6,
  120. 9.10010780076391431042E-8, -2.40274520828250956942E-9,
  121. 3.59233385440928410398E-11,
  122. };
  123. static double BD[10] = {
  124. /* 1.00000000000000000000E0,*/
  125. -6.31839869873368190192E-1, 2.36706788228248691528E-1,
  126. -5.31806367003223277662E-2, 8.48041718586295374409E-3,
  127. -9.47996768486665330168E-4, 7.81025592944552338085E-5,
  128. -4.55875153252442634831E-6, 1.89100358111421846170E-7,
  129. -4.91324691331920606875E-9, 7.18466403235734541950E-11,
  130. };
  131. #endif
  132. #ifdef DEC
  133. static unsigned short BN[44] = {
  134. 0040002, 0045342, 0113762, 0004360, 0137572, 0120346, 0172745, 0144046,
  135. 0037300, 0151134, 0123440, 0117047, 0136663, 0025423, 0014755, 0046026,
  136. 0036157, 0177561, 0027535, 0046744, 0135335, 0161052, 0071243, 0146535,
  137. 0034426, 0154060, 0164506, 0135625, 0133420, 0005356, 0100017, 0151334,
  138. 0032303, 0066137, 0024013, 0046212, 0131045, 0016612, 0066270, 0047574,
  139. 0027435, 0177025, 0060625, 0116363,
  140. };
  141. static unsigned short BD[40] = {
  142. /*0040200,0000000,0000000,0000000,*/
  143. 0140041, 0140101, 0174552, 0037073, 0037562, 0061503, 0124271, 0160756,
  144. 0137131, 0151760, 0073210, 0110534, 0036412, 0170562, 0117017, 0155377,
  145. 0135570, 0101374, 0074056, 0037276, 0034643, 0145376, 0001516, 0060636,
  146. 0133630, 0173540, 0121344, 0155231, 0032513, 0005602, 0134516, 0007144,
  147. 0131250, 0150540, 0075747, 0105341, 0027635, 0177020, 0012465, 0125402,
  148. };
  149. #endif
  150. #ifdef IBMPC
  151. static unsigned short BN[44] = {
  152. 0x411e, 0x52fe, 0x495c, 0x3fe0, 0xb905, 0xdebc, 0x541c, 0xbfcf, 0x13c5,
  153. 0x94e4, 0x1a4b, 0x3fb8, 0xa983, 0x633d, 0x6562, 0xbf96, 0xa9bd, 0x25eb,
  154. 0xffee, 0x3f6d, 0x79ac, 0x4e54, 0xbc45, 0xbf3b, 0xd773, 0x1d28, 0xdb06,
  155. 0x3f02, 0xfa5b, 0xd001, 0x015d, 0xbec2, 0x6991, 0xe501, 0x6d8b, 0x3e78,
  156. 0x09f0, 0x4d97, 0xa3b1, 0xbe24, 0xb39e, 0xac32, 0xbfc2, 0x3dc3,
  157. };
  158. static unsigned short BD[40] = {
  159. /*0x0000,0x0000,0x0000,0x3ff0,*/
  160. 0x47c7, 0x3f2d, 0x3808, 0xbfe4, 0x3c3e, 0x7517, 0x4c68, 0x3fce,
  161. 0x122b, 0x0ed1, 0x3a7e, 0xbfab, 0xfb60, 0x53c1, 0x5e2e, 0x3f81,
  162. 0xc7d8, 0x8f05, 0x105f, 0xbf4f, 0xcc34, 0xc069, 0x795f, 0x3f14,
  163. 0x9b53, 0x145c, 0x1eec, 0xbed3, 0xc1cd, 0x5729, 0x6170, 0x3e89,
  164. 0xf15c, 0x0f7c, 0x1a2c, 0xbe35, 0xb560, 0x02a6, 0xbfc2, 0x3dd3,
  165. };
  166. #endif
  167. #ifdef MIEEE
  168. static unsigned short BN[44] = {
  169. 0x3fe0, 0x495c, 0x52fe, 0x411e, 0xbfcf, 0x541c, 0xdebc, 0xb905, 0x3fb8,
  170. 0x1a4b, 0x94e4, 0x13c5, 0xbf96, 0x6562, 0x633d, 0xa983, 0x3f6d, 0xffee,
  171. 0x25eb, 0xa9bd, 0xbf3b, 0xbc45, 0x4e54, 0x79ac, 0x3f02, 0xdb06, 0x1d28,
  172. 0xd773, 0xbec2, 0x015d, 0xd001, 0xfa5b, 0x3e78, 0x6d8b, 0xe501, 0x6991,
  173. 0xbe24, 0xa3b1, 0x4d97, 0x09f0, 0x3dc3, 0xbfc2, 0xac32, 0xb39e,
  174. };
  175. static unsigned short BD[40] = {
  176. /*0x3ff0,0x0000,0x0000,0x0000,*/
  177. 0xbfe4, 0x3808, 0x3f2d, 0x47c7, 0x3fce, 0x4c68, 0x7517, 0x3c3e,
  178. 0xbfab, 0x3a7e, 0x0ed1, 0x122b, 0x3f81, 0x5e2e, 0x53c1, 0xfb60,
  179. 0xbf4f, 0x105f, 0x8f05, 0xc7d8, 0x3f14, 0x795f, 0xc069, 0xcc34,
  180. 0xbed3, 0x1eec, 0x145c, 0x9b53, 0x3e89, 0x6170, 0x5729, 0xc1cd,
  181. 0xbe35, 0x1a2c, 0x0f7c, 0xf15c, 0x3dd3, 0xbfc2, 0x02a6, 0xb560,
  182. };
  183. #endif
  184. /* 6.25 to infinity */
  185. #ifdef UNK
  186. static double CN[5] = {
  187. -5.90592860534773254987E-1, 6.29235242724368800674E-1,
  188. -1.72858975380388136411E-1, 1.64837047825189632310E-2,
  189. -4.86827613020462700845E-4,
  190. };
  191. static double CD[5] = {
  192. /* 1.00000000000000000000E0,*/
  193. -2.69820057197544900361E0, 1.73270799045947845857E0,
  194. -3.93708582281939493482E-1, 3.44278924041233391079E-2,
  195. -9.73655226040941223894E-4,
  196. };
  197. #endif
  198. #ifdef DEC
  199. static unsigned short CN[20] = {
  200. 0140027, 0030427, 0176477, 0074402, 0040041, 0012617, 0112375,
  201. 0162657, 0137461, 0000761, 0074120, 0135160, 0036607, 0004325,
  202. 0117246, 0115525, 0135377, 0036345, 0064750, 0047732,
  203. };
  204. static unsigned short CD[20] = {
  205. /*0040200,0000000,0000000,0000000,*/
  206. 0140454, 0127521, 0071653, 0133415, 0040335, 0144540, 0016105,
  207. 0045241, 0137711, 0112053, 0155034, 0062237, 0037015, 0002102,
  208. 0177442, 0074546, 0135577, 0036345, 0064750, 0052152,
  209. };
  210. #endif
  211. #ifdef IBMPC
  212. static unsigned short CN[20] = {
  213. 0xef20, 0xffa7, 0xe622, 0xbfe2, 0xbcb6, 0xf29f, 0x22b1,
  214. 0x3fe4, 0x174e, 0x2f0a, 0x203e, 0xbfc6, 0xd36b, 0xb3d4,
  215. 0xe11a, 0x3f90, 0x09fb, 0xad3d, 0xe79c, 0xbf3f,
  216. };
  217. static unsigned short CD[20] = {
  218. /*0x0000,0x0000,0x0000,0x3ff0,*/
  219. 0x76e2, 0x2e75, 0x95ea, 0xc005, 0xa954, 0x0388, 0xb92c,
  220. 0x3ffb, 0x8c94, 0x7b43, 0x3285, 0xbfd9, 0x4f2d, 0x5fe4,
  221. 0xa088, 0x3fa1, 0x0a8d, 0xad3d, 0xe79c, 0xbf4f,
  222. };
  223. #endif
  224. #ifdef MIEEE
  225. static unsigned short CN[20] = {
  226. 0xbfe2, 0xe622, 0xffa7, 0xef20, 0x3fe4, 0x22b1, 0xf29f,
  227. 0xbcb6, 0xbfc6, 0x203e, 0x2f0a, 0x174e, 0x3f90, 0xe11a,
  228. 0xb3d4, 0xd36b, 0xbf3f, 0xe79c, 0xad3d, 0x09fb,
  229. };
  230. static unsigned short CD[20] = {
  231. /*0x3ff0,0x0000,0x0000,0x0000,*/
  232. 0xc005, 0x95ea, 0x2e75, 0x76e2, 0x3ffb, 0xb92c, 0x0388,
  233. 0xa954, 0xbfd9, 0x3285, 0x7b43, 0x8c94, 0x3fa1, 0xa088,
  234. 0x5fe4, 0x4f2d, 0xbf4f, 0xe79c, 0xad3d, 0x0a8d,
  235. };
  236. #endif
  237. #ifdef ANSIPROT
  238. extern double chbevl(double, void *, int);
  239. extern double sqrt(double);
  240. extern double fabs(double);
  241. extern double polevl(double, void *, int);
  242. extern double p1evl(double, void *, int);
  243. #else
  244. double chbevl(), sqrt(), fabs(), polevl(), p1evl();
  245. #endif
  246. extern double PI, MACHEP;
  247. double dawsn(xx) double xx;
  248. {
  249. double x, y;
  250. int sign;
  251. sign = 1;
  252. if (xx < 0.0) {
  253. sign = -1;
  254. xx = -xx;
  255. }
  256. if (xx < 3.25) {
  257. x = xx * xx;
  258. y = xx * polevl(x, AN, 9) / polevl(x, AD, 10);
  259. return (sign * y);
  260. }
  261. x = 1.0 / (xx * xx);
  262. if (xx < 6.25) {
  263. y = 1.0 / xx + x * polevl(x, BN, 10) / (p1evl(x, BD, 10) * xx);
  264. return (sign * 0.5 * y);
  265. }
  266. if (xx > 1.0e9)
  267. return ((sign * 0.5) / xx);
  268. /* 6.25 to infinity */
  269. y = 1.0 / xx + x * polevl(x, CN, 4) / (p1evl(x, CD, 5) * xx);
  270. return (sign * 0.5 * y);
  271. }