ei.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. /* ei.c
  2. *
  3. * Exponential integral
  4. *
  5. *
  6. * SYNOPSIS:
  7. *
  8. * double x, y, ei();
  9. *
  10. * y = ei( x );
  11. *
  12. *
  13. *
  14. * DESCRIPTION:
  15. *
  16. * x
  17. * - t
  18. * | | e
  19. * Ei(x) = -|- --- dt .
  20. * | | t
  21. * -
  22. * -inf
  23. *
  24. * Not defined for x <= 0.
  25. * See also expn.c.
  26. *
  27. *
  28. *
  29. * ACCURACY:
  30. *
  31. * Relative error:
  32. * arithmetic domain # trials peak rms
  33. * IEEE 0,100 50000 8.6e-16 1.3e-16
  34. *
  35. */
  36. /*
  37. Cephes Math Library Release 2.8: May, 1999
  38. Copyright 1999 by Stephen L. Moshier
  39. */
  40. #include <math.h>
  41. #ifdef ANSIPROT
  42. extern double log ( double );
  43. extern double exp ( double );
  44. extern double polevl ( double, void *, int );
  45. extern double p1evl ( double, void *, int );
  46. #else
  47. extern double log(), exp(), polevl(), p1evl();
  48. #endif
  49. #define EUL 5.772156649015328606065e-1
  50. /* 0 < x <= 2
  51. Ei(x) - EUL - ln(x) = x A(x)/B(x)
  52. Theoretical peak relative error 9.73e-18 */
  53. #if UNK
  54. static double A[6] = {
  55. -5.350447357812542947283E0,
  56. 2.185049168816613393830E2,
  57. -4.176572384826693777058E3,
  58. 5.541176756393557601232E4,
  59. -3.313381331178144034309E5,
  60. 1.592627163384945414220E6,
  61. };
  62. static double B[6] = {
  63. /* 1.000000000000000000000E0, */
  64. -5.250547959112862969197E1,
  65. 1.259616186786790571525E3,
  66. -1.756549581973534652631E4,
  67. 1.493062117002725991967E5,
  68. -7.294949239640527645655E5,
  69. 1.592627163384945429726E6,
  70. };
  71. #endif
  72. #if DEC
  73. static short A[24] = {
  74. 0140653,0033335,0060230,0144217,
  75. 0042132,0100502,0035625,0167413,
  76. 0143202,0102224,0037176,0175403,
  77. 0044130,0071704,0077421,0170343,
  78. 0144641,0144504,0041200,0045154,
  79. 0045302,0064631,0047234,0142052,
  80. };
  81. static short B[24] = {
  82. /* 0040200,0000000,0000000,0000000, */
  83. 0141522,0002634,0070442,0142614,
  84. 0042635,0071667,0146532,0027705,
  85. 0143611,0035375,0156025,0114015,
  86. 0044421,0147215,0106177,0046330,
  87. 0145062,0014556,0144216,0103725,
  88. 0045302,0064631,0047234,0142052,
  89. };
  90. #endif
  91. #if IBMPC
  92. static short A[24] = {
  93. 0x1912,0xac13,0x66db,0xc015,
  94. 0xbde1,0x4772,0x5028,0x406b,
  95. 0xdf60,0x87cf,0x5092,0xc0b0,
  96. 0x3e1c,0x8fe2,0x0e78,0x40eb,
  97. 0x094e,0x8850,0x3928,0xc114,
  98. 0x9885,0x29d3,0x4d33,0x4138,
  99. };
  100. static short B[24] = {
  101. /* 0x0000,0x0000,0x0000,0x3ff0, */
  102. 0x58b1,0x8e24,0x40b3,0xc04a,
  103. 0x45f9,0xf9ab,0xae76,0x4093,
  104. 0xb302,0xbb82,0x275f,0xc0d1,
  105. 0xe99b,0xb18f,0x39d1,0x4102,
  106. 0xd0fb,0xd911,0x432d,0xc126,
  107. 0x9885,0x29d3,0x4d33,0x4138,
  108. };
  109. #endif
  110. #if MIEEE
  111. static short A[24] = {
  112. 0xc015,0x66db,0xac13,0x1912,
  113. 0x406b,0x5028,0x4772,0xbde1,
  114. 0xc0b0,0x5092,0x87cf,0xdf60,
  115. 0x40eb,0x0e78,0x8fe2,0x3e1c,
  116. 0xc114,0x3928,0x8850,0x094e,
  117. 0x4138,0x4d33,0x29d3,0x9885,
  118. };
  119. static short B[24] = {
  120. /* 0x3ff0,0x0000,0x0000,0x0000, */
  121. 0xc04a,0x40b3,0x8e24,0x58b1,
  122. 0x4093,0xae76,0xf9ab,0x45f9,
  123. 0xc0d1,0x275f,0xbb82,0xb302,
  124. 0x4102,0x39d1,0xb18f,0xe99b,
  125. 0xc126,0x432d,0xd911,0xd0fb,
  126. 0x4138,0x4d33,0x29d3,0x9885,
  127. };
  128. #endif
  129. #if 0
  130. /* 0 < x <= 4
  131. Ei(x) - EUL - ln(x) = x A(x)/B(x)
  132. Theoretical peak relative error 4.75e-17 */
  133. #if UNK
  134. static double A[7] = {
  135. -6.831869820732773831942E0,
  136. 2.920190530726774500309E2,
  137. -1.195883839286649567993E4,
  138. 1.761045255472548975666E5,
  139. -2.623034438354006526979E6,
  140. 1.472430336917880803157E7,
  141. -8.205359388213261174960E7,
  142. };
  143. static double B[7] = {
  144. /* 1.000000000000000000000E0, */
  145. -7.731946237840033971071E1,
  146. 2.751808700543578450827E3,
  147. -5.829268609072186897994E4,
  148. 7.916610857961870631379E5,
  149. -6.873926904825733094076E6,
  150. 3.523770183971164032710E7,
  151. -8.205359388213260785363E7,
  152. };
  153. #endif
  154. #if DEC
  155. static short A[28] = {
  156. 0140732,0117255,0072522,0071743,
  157. 0042222,0001160,0052302,0002334,
  158. 0143472,0155532,0101650,0155462,
  159. 0044453,0175041,0121220,0172022,
  160. 0145440,0014351,0140337,0157550,
  161. 0046140,0126317,0057202,0100233,
  162. 0146634,0100473,0036072,0067054,
  163. };
  164. static short B[28] = {
  165. /* 0040200,0000000,0000000,0000000, */
  166. 0141632,0121620,0111247,0010115,
  167. 0043053,0176360,0067773,0027324,
  168. 0144143,0132257,0121644,0036204,
  169. 0045101,0043321,0057553,0151231,
  170. 0145721,0143215,0147505,0050610,
  171. 0046406,0065721,0072675,0152744,
  172. 0146634,0100473,0036072,0067052,
  173. };
  174. #endif
  175. #if IBMPC
  176. static short A[28] = {
  177. 0x4e7c,0xaeaa,0x53d5,0xc01b,
  178. 0x409b,0x0a98,0x404e,0x4072,
  179. 0x1b66,0x5075,0x5b6b,0xc0c7,
  180. 0x1e82,0x3452,0x7f44,0x4105,
  181. 0xfbed,0x381b,0x031d,0xc144,
  182. 0x5013,0xebd0,0x1599,0x416c,
  183. 0x4dc5,0x6787,0x9027,0xc193,
  184. };
  185. static short B[28] = {
  186. /* 0x0000,0x0000,0x0000,0x3ff0, */
  187. 0xe20a,0x1254,0x5472,0xc053,
  188. 0x65db,0x0dff,0x7f9e,0x40a5,
  189. 0x8791,0xf474,0x7695,0xc0ec,
  190. 0x7a53,0x2bed,0x28da,0x4128,
  191. 0xaa31,0xb9e8,0x38d1,0xc15a,
  192. 0xbabd,0x2eb7,0xcd7a,0x4180,
  193. 0x4dc5,0x6787,0x9027,0xc193,
  194. };
  195. #endif
  196. #if MIEEE
  197. static short A[28] = {
  198. 0xc01b,0x53d5,0xaeaa,0x4e7c,
  199. 0x4072,0x404e,0x0a98,0x409b,
  200. 0xc0c7,0x5b6b,0x5075,0x1b66,
  201. 0x4105,0x7f44,0x3452,0x1e82,
  202. 0xc144,0x031d,0x381b,0xfbed,
  203. 0x416c,0x1599,0xebd0,0x5013,
  204. 0xc193,0x9027,0x6787,0x4dc5,
  205. };
  206. static short B[28] = {
  207. /* 0x3ff0,0x0000,0x0000,0x0000, */
  208. 0xc053,0x5472,0x1254,0xe20a,
  209. 0x40a5,0x7f9e,0x0dff,0x65db,
  210. 0xc0ec,0x7695,0xf474,0x8791,
  211. 0x4128,0x28da,0x2bed,0x7a53,
  212. 0xc15a,0x38d1,0xb9e8,0xaa31,
  213. 0x4180,0xcd7a,0x2eb7,0xbabd,
  214. 0xc193,0x9027,0x6787,0x4dc5,
  215. };
  216. #endif
  217. #endif /* 0 */
  218. #if 0
  219. /* 0 < x <= 8
  220. Ei(x) - EUL - ln(x) = x A(x)/B(x)
  221. Theoretical peak relative error 2.14e-17 */
  222. #if UNK
  223. static double A[9] = {
  224. -1.111230942210860450145E1,
  225. 3.688203982071386319616E2,
  226. -4.924786153494029574350E4,
  227. 1.050677503345557903241E6,
  228. -3.626713709916703688968E7,
  229. 4.353499908839918635414E8,
  230. -6.454613717232006895409E9,
  231. 3.408243056457762907071E10,
  232. -1.995466674647028468613E11,
  233. };
  234. static double B[9] = {
  235. /* 1.000000000000000000000E0, */
  236. -1.356757648138514017969E2,
  237. 8.562181317107341736606E3,
  238. -3.298257180413775117555E5,
  239. 8.543534058481435917210E6,
  240. -1.542380618535140055068E8,
  241. 1.939251779195993632028E9,
  242. -1.636096210465615015435E10,
  243. 8.396909743075306970605E10,
  244. -1.995466674647028425886E11,
  245. };
  246. #endif
  247. #if DEC
  248. static short A[36] = {
  249. 0141061,0146004,0173357,0151553,
  250. 0042270,0064402,0147366,0126701,
  251. 0144100,0057734,0106615,0144356,
  252. 0045200,0040654,0003332,0004456,
  253. 0146412,0054440,0043130,0140263,
  254. 0047317,0113517,0033422,0065123,
  255. 0150300,0056313,0065235,0131147,
  256. 0050775,0167423,0146222,0075760,
  257. 0151471,0153642,0003442,0147667,
  258. };
  259. static short B[36] = {
  260. /* 0040200,0000000,0000000,0000000, */
  261. 0142007,0126376,0166077,0043600,
  262. 0043405,0144271,0125461,0014364,
  263. 0144641,0006066,0175061,0164463,
  264. 0046002,0056456,0007370,0121657,
  265. 0147023,0013706,0156647,0177115,
  266. 0047747,0026504,0103144,0054507,
  267. 0150563,0146036,0007051,0177135,
  268. 0051234,0063625,0173266,0003111,
  269. 0151471,0153642,0003442,0147666,
  270. };
  271. #endif
  272. #if IBMPC
  273. static short A[36] = {
  274. 0xfa6d,0x9edd,0x3980,0xc026,
  275. 0xd5b8,0x59de,0x0d20,0x4077,
  276. 0xb91e,0x91b1,0x0bfb,0xc0e8,
  277. 0x4126,0x80db,0x0835,0x4130,
  278. 0x1816,0x08cb,0x4b24,0xc181,
  279. 0x4d4a,0xe6e2,0xf2e9,0x41b9,
  280. 0xb64d,0x6d53,0x0b99,0xc1f8,
  281. 0x4f7e,0x7992,0xbde2,0x421f,
  282. 0x59f7,0x40e4,0x3af4,0xc247,
  283. };
  284. static short B[36] = {
  285. /* 0x0000,0x0000,0x0000,0x3ff0, */
  286. 0xe8f0,0xdd87,0xf59f,0xc060,
  287. 0x231e,0x3566,0xb917,0x40c0,
  288. 0x3d26,0xdf46,0x2186,0xc114,
  289. 0x1476,0xc1df,0x4ba5,0x4160,
  290. 0xffca,0xdbb4,0x62f8,0xc1a2,
  291. 0x8b29,0x90cc,0xe5a8,0x41dc,
  292. 0x3fcc,0xc1c5,0x7983,0xc20e,
  293. 0xc0c9,0xbed6,0x8cf2,0x4233,
  294. 0x59f7,0x40e4,0x3af4,0xc247,
  295. };
  296. #endif
  297. #if MIEEE
  298. static short A[36] = {
  299. 0xc026,0x3980,0x9edd,0xfa6d,
  300. 0x4077,0x0d20,0x59de,0xd5b8,
  301. 0xc0e8,0x0bfb,0x91b1,0xb91e,
  302. 0x4130,0x0835,0x80db,0x4126,
  303. 0xc181,0x4b24,0x08cb,0x1816,
  304. 0x41b9,0xf2e9,0xe6e2,0x4d4a,
  305. 0xc1f8,0x0b99,0x6d53,0xb64d,
  306. 0x421f,0xbde2,0x7992,0x4f7e,
  307. 0xc247,0x3af4,0x40e4,0x59f7,
  308. };
  309. static short B[36] = {
  310. /* 0x3ff0,0x0000,0x0000,0x0000, */
  311. 0xc060,0xf59f,0xdd87,0xe8f0,
  312. 0x40c0,0xb917,0x3566,0x231e,
  313. 0xc114,0x2186,0xdf46,0x3d26,
  314. 0x4160,0x4ba5,0xc1df,0x1476,
  315. 0xc1a2,0x62f8,0xdbb4,0xffca,
  316. 0x41dc,0xe5a8,0x90cc,0x8b29,
  317. 0xc20e,0x7983,0xc1c5,0x3fcc,
  318. 0x4233,0x8cf2,0xbed6,0xc0c9,
  319. 0xc247,0x3af4,0x40e4,0x59f7,
  320. };
  321. #endif
  322. #endif /* 0 */
  323. /* 8 <= x <= 20
  324. x exp(-x) Ei(x) - 1 = 1/x R(1/x)
  325. Theoretical peak absolute error = 1.07e-17 */
  326. #if UNK
  327. static double A2[10] = {
  328. -2.106934601691916512584E0,
  329. 1.732733869664688041885E0,
  330. -2.423619178935841904839E-1,
  331. 2.322724180937565842585E-2,
  332. 2.372880440493179832059E-4,
  333. -8.343219561192552752335E-5,
  334. 1.363408795605250394881E-5,
  335. -3.655412321999253963714E-7,
  336. 1.464941733975961318456E-8,
  337. 6.176407863710360207074E-10,
  338. };
  339. static double B2[9] = {
  340. /* 1.000000000000000000000E0, */
  341. -2.298062239901678075778E-1,
  342. 1.105077041474037862347E-1,
  343. -1.566542966630792353556E-2,
  344. 2.761106850817352773874E-3,
  345. -2.089148012284048449115E-4,
  346. 1.708528938807675304186E-5,
  347. -4.459311796356686423199E-7,
  348. 1.394634930353847498145E-8,
  349. 6.150865933977338354138E-10,
  350. };
  351. #endif
  352. #if DEC
  353. static short A2[40] = {
  354. 0140406,0154004,0035104,0173336,
  355. 0040335,0145071,0031560,0150165,
  356. 0137570,0026670,0176230,0055040,
  357. 0036676,0043416,0077122,0054476,
  358. 0035170,0150206,0034407,0175571,
  359. 0134656,0174121,0123231,0021751,
  360. 0034144,0136766,0036746,0121115,
  361. 0132704,0037632,0135077,0107300,
  362. 0031573,0126321,0117076,0004314,
  363. 0030451,0143233,0041352,0172464,
  364. };
  365. static short B2[36] = {
  366. /* 0040200,0000000,0000000,0000000, */
  367. 0137553,0051122,0120721,0170437,
  368. 0037342,0050734,0175047,0032132,
  369. 0136600,0052311,0101406,0147050,
  370. 0036064,0171657,0120001,0071165,
  371. 0135133,0010043,0151244,0066340,
  372. 0034217,0051141,0026115,0043305,
  373. 0132757,0064120,0106341,0051217,
  374. 0031557,0114261,0060663,0135017,
  375. 0030451,0011337,0001344,0175542,
  376. };
  377. #endif
  378. #if IBMPC
  379. static short A2[40] = {
  380. 0x9edc,0x8748,0xdb00,0xc000,
  381. 0x1a0f,0x266e,0xb947,0x3ffb,
  382. 0x0b44,0x1f93,0x05b7,0xbfcf,
  383. 0x4b28,0xcfca,0xc8e1,0x3f97,
  384. 0xff6f,0xc720,0x1a10,0x3f2f,
  385. 0x247d,0x34d3,0xdf0a,0xbf15,
  386. 0xd44a,0xc7bc,0x97be,0x3eec,
  387. 0xf1d8,0x5747,0x87f3,0xbe98,
  388. 0xc119,0x33c7,0x759a,0x3e4f,
  389. 0x5ea6,0x685d,0x38d3,0x3e05,
  390. };
  391. static short B2[36] = {
  392. /* 0x0000,0x0000,0x0000,0x3ff0, */
  393. 0x3e24,0x543a,0x6a4a,0xbfcd,
  394. 0xe68b,0x9f44,0x4a3b,0x3fbc,
  395. 0xd9c5,0x3060,0x0a99,0xbf90,
  396. 0x2e4f,0xf400,0x9e75,0x3f66,
  397. 0x8d9c,0x7a54,0x6204,0xbf2b,
  398. 0xa8d9,0x2589,0xea4c,0x3ef1,
  399. 0x2a52,0x119c,0xed0a,0xbe9d,
  400. 0x7742,0x2c36,0xf316,0x3e4d,
  401. 0x9f6c,0xe05c,0x225b,0x3e05,
  402. };
  403. #endif
  404. #if MIEEE
  405. static short A2[40] = {
  406. 0xc000,0xdb00,0x8748,0x9edc,
  407. 0x3ffb,0xb947,0x266e,0x1a0f,
  408. 0xbfcf,0x05b7,0x1f93,0x0b44,
  409. 0x3f97,0xc8e1,0xcfca,0x4b28,
  410. 0x3f2f,0x1a10,0xc720,0xff6f,
  411. 0xbf15,0xdf0a,0x34d3,0x247d,
  412. 0x3eec,0x97be,0xc7bc,0xd44a,
  413. 0xbe98,0x87f3,0x5747,0xf1d8,
  414. 0x3e4f,0x759a,0x33c7,0xc119,
  415. 0x3e05,0x38d3,0x685d,0x5ea6,
  416. };
  417. static short B2[36] = {
  418. /* 0x3ff0,0x0000,0x0000,0x0000, */
  419. 0xbfcd,0x6a4a,0x543a,0x3e24,
  420. 0x3fbc,0x4a3b,0x9f44,0xe68b,
  421. 0xbf90,0x0a99,0x3060,0xd9c5,
  422. 0x3f66,0x9e75,0xf400,0x2e4f,
  423. 0xbf2b,0x6204,0x7a54,0x8d9c,
  424. 0x3ef1,0xea4c,0x2589,0xa8d9,
  425. 0xbe9d,0xed0a,0x119c,0x2a52,
  426. 0x3e4d,0xf316,0x2c36,0x7742,
  427. 0x3e05,0x225b,0xe05c,0x9f6c,
  428. };
  429. #endif
  430. /* x > 20
  431. x exp(-x) Ei(x) - 1 = 1/x A3(1/x)/B3(1/x)
  432. Theoretical absolute error = 6.15e-17 */
  433. #if UNK
  434. static double A3[9] = {
  435. -7.657847078286127362028E-1,
  436. 6.886192415566705051750E-1,
  437. -2.132598113545206124553E-1,
  438. 3.346107552384193813594E-2,
  439. -3.076541477344756050249E-3,
  440. 1.747119316454907477380E-4,
  441. -6.103711682274170530369E-6,
  442. 1.218032765428652199087E-7,
  443. -1.086076102793290233007E-9,
  444. };
  445. static double B3[9] = {
  446. /* 1.000000000000000000000E0, */
  447. -1.888802868662308731041E0,
  448. 1.066691687211408896850E0,
  449. -2.751915982306380647738E-1,
  450. 3.930852688233823569726E-2,
  451. -3.414684558602365085394E-3,
  452. 1.866844370703555398195E-4,
  453. -6.345146083130515357861E-6,
  454. 1.239754287483206878024E-7,
  455. -1.086076102793126632978E-9,
  456. };
  457. #endif
  458. #if DEC
  459. static short A3[36] = {
  460. 0140104,0005167,0071746,0115510,
  461. 0040060,0044531,0140741,0154556,
  462. 0137532,0060307,0126506,0071123,
  463. 0037011,0007173,0010405,0127224,
  464. 0136111,0117715,0003654,0175577,
  465. 0035067,0031340,0102657,0147714,
  466. 0133714,0147173,0167473,0136640,
  467. 0032402,0144407,0115547,0060114,
  468. 0130625,0042347,0156431,0113425,
  469. };
  470. static short B3[36] = {
  471. /* 0040200,0000000,0000000,0000000, */
  472. 0140361,0142112,0155277,0067714,
  473. 0040210,0104532,0065676,0074326,
  474. 0137614,0162751,0142421,0131033,
  475. 0037041,0000772,0053236,0002632,
  476. 0136137,0144346,0100536,0153136,
  477. 0035103,0140270,0152211,0166215,
  478. 0133724,0164143,0145763,0021153,
  479. 0032405,0017033,0035333,0025736,
  480. 0130625,0042347,0156431,0077134,
  481. };
  482. #endif
  483. #if IBMPC
  484. static short A3[36] = {
  485. 0xd369,0xee7c,0x814e,0xbfe8,
  486. 0x3b2e,0x383c,0x092b,0x3fe6,
  487. 0xce4a,0xf5a8,0x4c18,0xbfcb,
  488. 0xb5d2,0x6220,0x21cf,0x3fa1,
  489. 0x9f70,0xa0f5,0x33f9,0xbf69,
  490. 0xf9f9,0x10b5,0xe65c,0x3f26,
  491. 0x77b4,0x7de7,0x99cf,0xbed9,
  492. 0xec09,0xf36c,0x5920,0x3e80,
  493. 0x32e3,0xfba3,0xa89c,0xbe12,
  494. };
  495. static short B3[36] = {
  496. /* 0x0000,0x0000,0x0000,0x3ff0, */
  497. 0xedf9,0x5b57,0x3889,0xbffe,
  498. 0xcf1b,0x4d77,0x112b,0x3ff1,
  499. 0x3643,0x38a2,0x9cbd,0xbfd1,
  500. 0xc0b3,0x4ad3,0x203f,0x3fa4,
  501. 0xdacc,0xd02b,0xf91c,0xbf6b,
  502. 0x3d92,0x1a91,0x7817,0x3f28,
  503. 0x644d,0x797e,0x9d0c,0xbeda,
  504. 0x657c,0x675b,0xa3c3,0x3e80,
  505. 0x2fcb,0xfba3,0xa89c,0xbe12,
  506. };
  507. #endif
  508. #if MIEEE
  509. static short A3[36] = {
  510. 0xbfe8,0x814e,0xee7c,0xd369,
  511. 0x3fe6,0x092b,0x383c,0x3b2e,
  512. 0xbfcb,0x4c18,0xf5a8,0xce4a,
  513. 0x3fa1,0x21cf,0x6220,0xb5d2,
  514. 0xbf69,0x33f9,0xa0f5,0x9f70,
  515. 0x3f26,0xe65c,0x10b5,0xf9f9,
  516. 0xbed9,0x99cf,0x7de7,0x77b4,
  517. 0x3e80,0x5920,0xf36c,0xec09,
  518. 0xbe12,0xa89c,0xfba3,0x32e3,
  519. };
  520. static short B3[36] = {
  521. /* 0x3ff0,0x0000,0x0000,0x0000, */
  522. 0xbffe,0x3889,0x5b57,0xedf9,
  523. 0x3ff1,0x112b,0x4d77,0xcf1b,
  524. 0xbfd1,0x9cbd,0x38a2,0x3643,
  525. 0x3fa4,0x203f,0x4ad3,0xc0b3,
  526. 0xbf6b,0xf91c,0xd02b,0xdacc,
  527. 0x3f28,0x7817,0x1a91,0x3d92,
  528. 0xbeda,0x9d0c,0x797e,0x644d,
  529. 0x3e80,0xa3c3,0x675b,0x657c,
  530. 0xbe12,0xa89c,0xfba3,0x2fcb,
  531. };
  532. #endif
  533. /* 16 <= x <= 32
  534. x exp(-x) Ei(x) - 1 = 1/x A4(1/x) / B4(1/x)
  535. Theoretical absolute error = 1.22e-17 */
  536. #if UNK
  537. static double A4[8] = {
  538. -2.458119367674020323359E-1,
  539. -1.483382253322077687183E-1,
  540. 7.248291795735551591813E-2,
  541. -1.348315687380940523823E-2,
  542. 1.342775069788636972294E-3,
  543. -7.942465637159712264564E-5,
  544. 2.644179518984235952241E-6,
  545. -4.239473659313765177195E-8,
  546. };
  547. static double B4[8] = {
  548. /* 1.000000000000000000000E0, */
  549. -1.044225908443871106315E-1,
  550. -2.676453128101402655055E-1,
  551. 9.695000254621984627876E-2,
  552. -1.601745692712991078208E-2,
  553. 1.496414899205908021882E-3,
  554. -8.462452563778485013756E-5,
  555. 2.728938403476726394024E-6,
  556. -4.239462431819542051337E-8,
  557. };
  558. #endif
  559. #if DEC
  560. static short A4[32] = {
  561. 0137573,0133037,0152607,0113356,
  562. 0137427,0162771,0145061,0126345,
  563. 0037224,0070754,0110451,0174104,
  564. 0136534,0164165,0072170,0063753,
  565. 0035660,0000016,0002560,0147751,
  566. 0134646,0110311,0123316,0047432,
  567. 0033461,0071250,0101031,0075202,
  568. 0132066,0012601,0077305,0170177,
  569. };
  570. static short B4[32] = {
  571. /* 0040200,0000000,0000000,0000000, */
  572. 0137325,0155602,0162437,0030710,
  573. 0137611,0004316,0071344,0176361,
  574. 0037306,0106671,0011103,0155053,
  575. 0136603,0033412,0132530,0175171,
  576. 0035704,0021532,0015516,0166130,
  577. 0134661,0074162,0036741,0073466,
  578. 0033467,0021316,0003100,0171325,
  579. 0132066,0012541,0162202,0150160,
  580. };
  581. #endif
  582. #if IBMPC
  583. static short A4[] = {
  584. 0xf2de,0xfab0,0x76c3,0xbfcf,
  585. 0x359d,0x3946,0xfcbf,0xbfc2,
  586. 0x3f09,0x9225,0x8e3d,0x3fb2,
  587. 0x0cfd,0xae8f,0x9d0e,0xbf8b,
  588. 0x19fd,0xc0ae,0x0001,0x3f56,
  589. 0xc9e3,0x34d9,0xd219,0xbf14,
  590. 0x2f50,0x1043,0x2e55,0x3ec6,
  591. 0xbe10,0x2fd8,0xc2b0,0xbe66,
  592. };
  593. static short B4[] = {
  594. /* 0x0000,0x0000,0x0000,0x3ff0, */
  595. 0xe639,0x5ca3,0xbb70,0xbfba,
  596. 0x9f9e,0xce5c,0x2119,0xbfd1,
  597. 0x7b45,0x2248,0xd1b7,0x3fb8,
  598. 0x1f4f,0x56ab,0x66e1,0xbf90,
  599. 0xdd8b,0x4369,0x846b,0x3f58,
  600. 0x2ee7,0x47bc,0x2f0e,0xbf16,
  601. 0x1e5b,0xc0c8,0xe459,0x3ec6,
  602. 0x5a0e,0x3c90,0xc2ac,0xbe66,
  603. };
  604. #endif
  605. #if MIEEE
  606. static short A4[32] = {
  607. 0xbfcf,0x76c3,0xfab0,0xf2de,
  608. 0xbfc2,0xfcbf,0x3946,0x359d,
  609. 0x3fb2,0x8e3d,0x9225,0x3f09,
  610. 0xbf8b,0x9d0e,0xae8f,0x0cfd,
  611. 0x3f56,0x0001,0xc0ae,0x19fd,
  612. 0xbf14,0xd219,0x34d9,0xc9e3,
  613. 0x3ec6,0x2e55,0x1043,0x2f50,
  614. 0xbe66,0xc2b0,0x2fd8,0xbe10,
  615. };
  616. static short B4[32] = {
  617. /* 0x3ff0,0x0000,0x0000,0x0000, */
  618. 0xbfba,0xbb70,0x5ca3,0xe639,
  619. 0xbfd1,0x2119,0xce5c,0x9f9e,
  620. 0x3fb8,0xd1b7,0x2248,0x7b45,
  621. 0xbf90,0x66e1,0x56ab,0x1f4f,
  622. 0x3f58,0x846b,0x4369,0xdd8b,
  623. 0xbf16,0x2f0e,0x47bc,0x2ee7,
  624. 0x3ec6,0xe459,0xc0c8,0x1e5b,
  625. 0xbe66,0xc2ac,0x3c90,0x5a0e,
  626. };
  627. #endif
  628. #if 0
  629. /* 20 <= x <= 40
  630. x exp(-x) Ei(x) - 1 = 1/x A4(1/x) / B4(1/x)
  631. Theoretical absolute error = 1.78e-17 */
  632. #if UNK
  633. static double A4[8] = {
  634. 2.067245813525780707978E-1,
  635. -5.153749551345223645670E-1,
  636. 1.928289589546695033096E-1,
  637. -3.124468842857260044075E-2,
  638. 2.740283734277352539912E-3,
  639. -1.377775664366875175601E-4,
  640. 3.803788980664744242323E-6,
  641. -4.611038277393688031154E-8,
  642. };
  643. static double B4[8] = {
  644. /* 1.000000000000000000000E0, */
  645. -8.544436025219516861531E-1,
  646. 2.507436807692907385181E-1,
  647. -3.647688090228423114064E-2,
  648. 3.008576950332041388892E-3,
  649. -1.452926405348421286334E-4,
  650. 3.896007735260115431965E-6,
  651. -4.611037642697098234083E-8,
  652. };
  653. #endif
  654. #if DEC
  655. static short A4[32] = {
  656. 0037523,0127633,0150301,0022031,
  657. 0140003,0167634,0170572,0170420,
  658. 0037505,0072364,0060672,0063220,
  659. 0136777,0172334,0057456,0102640,
  660. 0036063,0113125,0002476,0047251,
  661. 0135020,0074142,0042600,0043630,
  662. 0033577,0042230,0155372,0136105,
  663. 0132106,0005346,0165333,0114541,
  664. };
  665. static short B4[28] = {
  666. /* 0040200,0000000,0000000,0000000, */
  667. 0140132,0136320,0160433,0131535,
  668. 0037600,0060571,0144452,0060214,
  669. 0137025,0064310,0024220,0176472,
  670. 0036105,0025613,0115762,0166605,
  671. 0135030,0054662,0035454,0061763,
  672. 0033602,0135163,0116430,0000066,
  673. 0132106,0005345,0020602,0137133,
  674. };
  675. #endif
  676. #if IBMPC
  677. static short A4[32] = {
  678. 0x2483,0x7a18,0x75f3,0x3fca,
  679. 0x5e22,0x9e2f,0x7df3,0xbfe0,
  680. 0x4cd2,0x8c37,0xae9e,0x3fc8,
  681. 0xd0b4,0x8be5,0xfe9b,0xbf9f,
  682. 0xc9d5,0xa0a7,0x72ca,0x3f66,
  683. 0x08f3,0x48b0,0x0f0c,0xbf22,
  684. 0x5789,0x1b5f,0xe893,0x3ecf,
  685. 0x732c,0xdd5b,0xc15c,0xbe68,
  686. };
  687. static short B4[28] = {
  688. /* 0x0000,0x0000,0x0000,0x3ff0, */
  689. 0x766c,0x1c23,0x579a,0xbfeb,
  690. 0x4c11,0x3925,0x0c2f,0x3fd0,
  691. 0x1fa7,0x0512,0xad19,0xbfa2,
  692. 0x5db1,0x737e,0xa571,0x3f68,
  693. 0x8c7e,0x4765,0x0b36,0xbf23,
  694. 0x0007,0x73a3,0x574e,0x3ed0,
  695. 0x57cb,0xa430,0xc15c,0xbe68,
  696. };
  697. #endif
  698. #if MIEEE
  699. static short A4[32] = {
  700. 0x3fca,0x75f3,0x7a18,0x2483,
  701. 0xbfe0,0x7df3,0x9e2f,0x5e22,
  702. 0x3fc8,0xae9e,0x8c37,0x4cd2,
  703. 0xbf9f,0xfe9b,0x8be5,0xd0b4,
  704. 0x3f66,0x72ca,0xa0a7,0xc9d5,
  705. 0xbf22,0x0f0c,0x48b0,0x08f3,
  706. 0x3ecf,0xe893,0x1b5f,0x5789,
  707. 0xbe68,0xc15c,0xdd5b,0x732c,
  708. };
  709. static short B4[28] = {
  710. /* 0x3ff0,0x0000,0x0000,0x0000, */
  711. 0xbfeb,0x579a,0x1c23,0x766c,
  712. 0x3fd0,0x0c2f,0x3925,0x4c11,
  713. 0xbfa2,0xad19,0x0512,0x1fa7,
  714. 0x3f68,0xa571,0x737e,0x5db1,
  715. 0xbf23,0x0b36,0x4765,0x8c7e,
  716. 0x3ed0,0x574e,0x73a3,0x0007,
  717. 0xbe68,0xc15c,0xa430,0x57cb,
  718. };
  719. #endif
  720. #endif /* 0 */
  721. /* 4 <= x <= 8
  722. x exp(-x) Ei(x) - 1 = 1/x A5(1/x) / B5(1/x)
  723. Theoretical absolute error = 2.20e-17 */
  724. #if UNK
  725. static double A5[8] = {
  726. -1.373215375871208729803E0,
  727. -7.084559133740838761406E-1,
  728. 1.580806855547941010501E0,
  729. -2.601500427425622944234E-1,
  730. 2.994674694113713763365E-2,
  731. -1.038086040188744005513E-3,
  732. 4.371064420753005429514E-5,
  733. 2.141783679522602903795E-6,
  734. };
  735. static double B5[8] = {
  736. /* 1.000000000000000000000E0, */
  737. 8.585231423622028380768E-1,
  738. 4.483285822873995129957E-1,
  739. 7.687932158124475434091E-2,
  740. 2.449868241021887685904E-2,
  741. 8.832165941927796567926E-4,
  742. 4.590952299511353531215E-4,
  743. -4.729848351866523044863E-6,
  744. 2.665195537390710170105E-6,
  745. };
  746. #endif
  747. #if DEC
  748. static short A5[32] = {
  749. 0140257,0142605,0076335,0113632,
  750. 0140065,0056535,0161231,0074311,
  751. 0040312,0053741,0004357,0076405,
  752. 0137605,0031142,0165503,0136705,
  753. 0036765,0051341,0053573,0007602,
  754. 0135610,0010143,0027643,0110522,
  755. 0034467,0052762,0062024,0120161,
  756. 0033417,0135620,0036500,0062647,
  757. };
  758. static short B[32] = {
  759. /* 0040200,0000000,0000000,0000000, */
  760. 0040133,0144054,0031516,0004100,
  761. 0037745,0105522,0166622,0123146,
  762. 0037235,0071347,0157560,0157464,
  763. 0036710,0130565,0173747,0041670,
  764. 0035547,0103651,0106243,0101240,
  765. 0035360,0131267,0176263,0140257,
  766. 0133636,0132426,0102537,0102531,
  767. 0033462,0155665,0167503,0176350,
  768. };
  769. #endif
  770. #if IBMPC
  771. static short A5[32] = {
  772. 0xb2f3,0xaf9b,0xf8b0,0xbff5,
  773. 0x2f19,0xbc53,0xabab,0xbfe6,
  774. 0xefa1,0x211d,0x4afc,0x3ff9,
  775. 0x77b9,0x5d68,0xa64c,0xbfd0,
  776. 0x61f0,0x2aef,0xaa5c,0x3f9e,
  777. 0x722a,0x65f4,0x020c,0xbf51,
  778. 0x940e,0x4c82,0xeabe,0x3f06,
  779. 0x0cb5,0x07a8,0xf772,0x3ec1,
  780. };
  781. static short B5[32] = {
  782. /* 0x0000,0x0000,0x0000,0x3ff0, */
  783. 0xc108,0x8669,0x7905,0x3feb,
  784. 0x54cd,0x5db2,0xb16a,0x3fdc,
  785. 0x1be7,0xfbee,0xae5c,0x3fb3,
  786. 0xe877,0xbefc,0x162e,0x3f99,
  787. 0x7054,0x3194,0xf0f5,0x3f4c,
  788. 0x7816,0xff96,0x1656,0x3f3e,
  789. 0xf0ab,0xd0ab,0xd6a2,0xbed3,
  790. 0x7f9d,0xbde8,0x5b76,0x3ec6,
  791. };
  792. #endif
  793. #if MIEEE
  794. static short A5[32] = {
  795. 0xbff5,0xf8b0,0xaf9b,0xb2f3,
  796. 0xbfe6,0xabab,0xbc53,0x2f19,
  797. 0x3ff9,0x4afc,0x211d,0xefa1,
  798. 0xbfd0,0xa64c,0x5d68,0x77b9,
  799. 0x3f9e,0xaa5c,0x2aef,0x61f0,
  800. 0xbf51,0x020c,0x65f4,0x722a,
  801. 0x3f06,0xeabe,0x4c82,0x940e,
  802. 0x3ec1,0xf772,0x07a8,0x0cb5,
  803. };
  804. static short B5[32] = {
  805. /* 0x3ff0,0x0000,0x0000,0x0000, */
  806. 0x3feb,0x7905,0x8669,0xc108,
  807. 0x3fdc,0xb16a,0x5db2,0x54cd,
  808. 0x3fb3,0xae5c,0xfbee,0x1be7,
  809. 0x3f99,0x162e,0xbefc,0xe877,
  810. 0x3f4c,0xf0f5,0x3194,0x7054,
  811. 0x3f3e,0x1656,0xff96,0x7816,
  812. 0xbed3,0xd6a2,0xd0ab,0xf0ab,
  813. 0x3ec6,0x5b76,0xbde8,0x7f9d,
  814. };
  815. #endif
  816. /* 2 <= x <= 4
  817. x exp(-x) Ei(x) - 1 = 1/x A6(1/x) / B6(1/x)
  818. Theoretical absolute error = 4.89e-17 */
  819. #if UNK
  820. static double A6[8] = {
  821. 1.981808503259689673238E-2,
  822. -1.271645625984917501326E0,
  823. -2.088160335681228318920E0,
  824. 2.755544509187936721172E0,
  825. -4.409507048701600257171E-1,
  826. 4.665623805935891391017E-2,
  827. -1.545042679673485262580E-3,
  828. 7.059980605299617478514E-5,
  829. };
  830. static double B6[7] = {
  831. /* 1.000000000000000000000E0, */
  832. 1.476498670914921440652E0,
  833. 5.629177174822436244827E-1,
  834. 1.699017897879307263248E-1,
  835. 2.291647179034212017463E-2,
  836. 4.450150439728752875043E-3,
  837. 1.727439612206521482874E-4,
  838. 3.953167195549672482304E-5,
  839. };
  840. #endif
  841. #if DEC
  842. static short A6[32] = {
  843. 0036642,0054611,0061263,0000140,
  844. 0140242,0142510,0125732,0072035,
  845. 0140405,0122153,0037643,0104527,
  846. 0040460,0055327,0055550,0116240,
  847. 0137741,0142112,0070441,0103510,
  848. 0037077,0015234,0104750,0146765,
  849. 0135712,0101407,0107554,0020253,
  850. 0034624,0007373,0072621,0063735,
  851. };
  852. static short B6[28] = {
  853. /* 0040200,0000000,0000000,0000000, */
  854. 0040274,0176750,0110025,0061006,
  855. 0040020,0015540,0021354,0155050,
  856. 0037455,0175274,0015257,0021112,
  857. 0036673,0135523,0016042,0117203,
  858. 0036221,0151221,0046352,0144174,
  859. 0035065,0021232,0117727,0152432,
  860. 0034445,0147317,0037300,0067123,
  861. };
  862. #endif
  863. #if IBMPC
  864. static short A6[32] = {
  865. 0x600c,0x2c56,0x4b31,0x3f94,
  866. 0x4e84,0x157b,0x58a9,0xbff4,
  867. 0x712b,0x67f4,0xb48d,0xc000,
  868. 0x1394,0xeb6d,0x0b5a,0x4006,
  869. 0x30e9,0x4e24,0x3889,0xbfdc,
  870. 0x19bf,0x913d,0xe353,0x3fa7,
  871. 0x8415,0xf1ed,0x5060,0xbf59,
  872. 0x2cfc,0x6eb2,0x81df,0x3f12,
  873. };
  874. static short B6[28] = {
  875. /* 0x0000,0x0000,0x0000,0x3ff0, */
  876. 0xac41,0x1202,0x9fbd,0x3ff7,
  877. 0x9b45,0x045d,0x036c,0x3fe2,
  878. 0xe449,0x8355,0xbf57,0x3fc5,
  879. 0x53d0,0x6384,0x776a,0x3f97,
  880. 0x590f,0x299d,0x3a52,0x3f72,
  881. 0xfaa3,0x53fa,0xa453,0x3f26,
  882. 0x0dca,0xe7d8,0xb9d9,0x3f04,
  883. };
  884. #endif
  885. #if MIEEE
  886. static short A6[32] = {
  887. 0x3f94,0x4b31,0x2c56,0x600c,
  888. 0xbff4,0x58a9,0x157b,0x4e84,
  889. 0xc000,0xb48d,0x67f4,0x712b,
  890. 0x4006,0x0b5a,0xeb6d,0x1394,
  891. 0xbfdc,0x3889,0x4e24,0x30e9,
  892. 0x3fa7,0xe353,0x913d,0x19bf,
  893. 0xbf59,0x5060,0xf1ed,0x8415,
  894. 0x3f12,0x81df,0x6eb2,0x2cfc,
  895. };
  896. static short B6[28] = {
  897. /* 0x3ff0,0x0000,0x0000,0x0000, */
  898. 0x3ff7,0x9fbd,0x1202,0xac41,
  899. 0x3fe2,0x036c,0x045d,0x9b45,
  900. 0x3fc5,0xbf57,0x8355,0xe449,
  901. 0x3f97,0x776a,0x6384,0x53d0,
  902. 0x3f72,0x3a52,0x299d,0x590f,
  903. 0x3f26,0xa453,0x53fa,0xfaa3,
  904. 0x3f04,0xb9d9,0xe7d8,0x0dca,
  905. };
  906. #endif
  907. /* 32 <= x <= 64
  908. x exp(-x) Ei(x) - 1 = 1/x A7(1/x) / B7(1/x)
  909. Theoretical absolute error = 7.71e-18 */
  910. #if UNK
  911. static double A7[6] = {
  912. 1.212561118105456670844E-1,
  913. -5.823133179043894485122E-1,
  914. 2.348887314557016779211E-1,
  915. -3.040034318113248237280E-2,
  916. 1.510082146865190661777E-3,
  917. -2.523137095499571377122E-5,
  918. };
  919. static double B7[5] = {
  920. /* 1.000000000000000000000E0, */
  921. -1.002252150365854016662E0,
  922. 2.928709694872224144953E-1,
  923. -3.337004338674007801307E-2,
  924. 1.560544881127388842819E-3,
  925. -2.523137093603234562648E-5,
  926. };
  927. #endif
  928. #if DEC
  929. static short A7[24] = {
  930. 0037370,0052437,0152524,0150125,
  931. 0140025,0011174,0050154,0131330,
  932. 0037560,0103253,0167464,0062245,
  933. 0136771,0005043,0174001,0023345,
  934. 0035705,0166762,0157300,0016451,
  935. 0134323,0123764,0157767,0134477,
  936. };
  937. static short B7[20] = {
  938. /* 0040200,0000000,0000000,0000000, */
  939. 0140200,0044714,0064025,0060324,
  940. 0037625,0171457,0003712,0073131,
  941. 0137010,0127406,0150061,0141746,
  942. 0035714,0105462,0072356,0103712,
  943. 0134323,0123764,0156514,0077414,
  944. };
  945. #endif
  946. #if IBMPC
  947. static short A7[24] = {
  948. 0x9a0b,0xfaaa,0x0aa3,0x3fbf,
  949. 0x965b,0x8a0d,0xa24f,0xbfe2,
  950. 0x8c95,0x7de6,0x10d5,0x3fce,
  951. 0x24dd,0x7f00,0x2144,0xbf9f,
  952. 0x03a5,0x5bd8,0xbdbe,0x3f58,
  953. 0xf728,0x9bfe,0x74fe,0xbefa,
  954. };
  955. static short B7[20] = {
  956. /* 0x0000,0x0000,0x0000,0x3ff0, */
  957. 0xac1a,0x8d02,0x0939,0xbff0,
  958. 0x4ecb,0xe0f9,0xbe65,0x3fd2,
  959. 0x387d,0xda06,0x15e0,0xbfa1,
  960. 0xd0f9,0x4e9d,0x9166,0x3f59,
  961. 0x8fe2,0x9ba9,0x74fe,0xbefa,
  962. };
  963. #endif
  964. #if MIEEE
  965. static short A7[24] = {
  966. 0x3fbf,0x0aa3,0xfaaa,0x9a0b,
  967. 0xbfe2,0xa24f,0x8a0d,0x965b,
  968. 0x3fce,0x10d5,0x7de6,0x8c95,
  969. 0xbf9f,0x2144,0x7f00,0x24dd,
  970. 0x3f58,0xbdbe,0x5bd8,0x03a5,
  971. 0xbefa,0x74fe,0x9bfe,0xf728,
  972. };
  973. static short B7[20] = {
  974. /* 0x3ff0,0x0000,0x0000,0x0000, */
  975. 0xbff0,0x0939,0x8d02,0xac1a,
  976. 0x3fd2,0xbe65,0xe0f9,0x4ecb,
  977. 0xbfa1,0x15e0,0xda06,0x387d,
  978. 0x3f59,0x9166,0x4e9d,0xd0f9,
  979. 0xbefa,0x74fe,0x9ba9,0x8fe2,
  980. };
  981. #endif
  982. double ei (x)
  983. double x;
  984. {
  985. double f, w;
  986. if (x <= 0.0)
  987. {
  988. mtherr("ei", DOMAIN);
  989. return 0.0;
  990. }
  991. else if (x < 2.0)
  992. {
  993. /* Power series.
  994. inf n
  995. - x
  996. Ei(x) = EUL + ln x + > ----
  997. - n n!
  998. n=1
  999. */
  1000. f = polevl(x,A,5) / p1evl(x,B,6);
  1001. /* f = polevl(x,A,6) / p1evl(x,B,7); */
  1002. /* f = polevl(x,A,8) / p1evl(x,B,9); */
  1003. return (EUL + log(x) + x * f);
  1004. }
  1005. else if (x < 4.0)
  1006. {
  1007. /* Asymptotic expansion.
  1008. 1 2 6
  1009. x exp(-x) Ei(x) = 1 + --- + --- + ---- + ...
  1010. x 2 3
  1011. x x
  1012. */
  1013. w = 1.0/x;
  1014. f = polevl(w,A6,7) / p1evl(w,B6,7);
  1015. return (exp(x) * w * (1.0 + w * f));
  1016. }
  1017. else if (x < 8.0)
  1018. {
  1019. w = 1.0/x;
  1020. f = polevl(w,A5,7) / p1evl(w,B5,8);
  1021. return (exp(x) * w * (1.0 + w * f));
  1022. }
  1023. else if (x < 16.0)
  1024. {
  1025. w = 1.0/x;
  1026. f = polevl(w,A2,9) / p1evl(w,B2,9);
  1027. return (exp(x) * w * (1.0 + w * f));
  1028. }
  1029. else if (x < 32.0)
  1030. {
  1031. w = 1.0/x;
  1032. f = polevl(w,A4,7) / p1evl(w,B4,8);
  1033. return (exp(x) * w * (1.0 + w * f));
  1034. }
  1035. else if (x < 64.0)
  1036. {
  1037. w = 1.0/x;
  1038. f = polevl(w,A7,5) / p1evl(w,B7,5);
  1039. return (exp(x) * w * (1.0 + w * f));
  1040. }
  1041. else
  1042. {
  1043. w = 1.0/x;
  1044. f = polevl(w,A3,8) / p1evl(w,B3,9);
  1045. return (exp(x) * w * (1.0 + w * f));
  1046. }
  1047. }