expint.hpp 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  1. // Copyright John Maddock 2007.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_EXPINT_HPP
  6. #define BOOST_MATH_EXPINT_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #pragma warning(push)
  10. #pragma warning(disable:4702) // Unreachable code (release mode only warning)
  11. #endif
  12. #include <boost/math/tools/precision.hpp>
  13. #include <boost/math/tools/promotion.hpp>
  14. #include <boost/math/tools/fraction.hpp>
  15. #include <boost/math/tools/series.hpp>
  16. #include <boost/math/policies/error_handling.hpp>
  17. #include <boost/math/special_functions/math_fwd.hpp>
  18. #include <boost/math/special_functions/digamma.hpp>
  19. #include <boost/math/special_functions/log1p.hpp>
  20. #include <boost/math/special_functions/pow.hpp>
  21. #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
  22. //
  23. // This is the only way we can avoid
  24. // warning: non-standard suffix on floating constant [-Wpedantic]
  25. // when building with -Wall -pedantic. Neither __extension__
  26. // nor #pragma diagnostic ignored work :(
  27. //
  28. #pragma GCC system_header
  29. #endif
  30. namespace boost{ namespace math{
  31. template <class T, class Policy>
  32. inline typename tools::promote_args<T>::type
  33. expint(unsigned n, T z, const Policy& /*pol*/);
  34. namespace detail{
  35. template <class T>
  36. inline T expint_1_rational(const T& z, const std::integral_constant<int, 0>&)
  37. {
  38. // this function is never actually called
  39. BOOST_ASSERT(0);
  40. return z;
  41. }
  42. template <class T>
  43. T expint_1_rational(const T& z, const std::integral_constant<int, 53>&)
  44. {
  45. BOOST_MATH_STD_USING
  46. T result;
  47. if(z <= 1)
  48. {
  49. // Maximum Deviation Found: 2.006e-18
  50. // Expected Error Term: 2.006e-18
  51. // Max error found at double precision: 2.760e-17
  52. static const T Y = 0.66373538970947265625F;
  53. static const T P[6] = {
  54. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0865197248079397976498),
  55. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0320913665303559189999),
  56. BOOST_MATH_BIG_CONSTANT(T, 53, -0.245088216639761496153),
  57. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0368031736257943745142),
  58. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00399167106081113256961),
  59. BOOST_MATH_BIG_CONSTANT(T, 53, -0.000111507792921197858394)
  60. };
  61. static const T Q[6] = {
  62. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  63. BOOST_MATH_BIG_CONSTANT(T, 53, 0.37091387659397013215),
  64. BOOST_MATH_BIG_CONSTANT(T, 53, 0.056770677104207528384),
  65. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00427347600017103698101),
  66. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000131049900798434683324),
  67. BOOST_MATH_BIG_CONSTANT(T, 53, -0.528611029520217142048e-6)
  68. };
  69. result = tools::evaluate_polynomial(P, z)
  70. / tools::evaluate_polynomial(Q, z);
  71. result += z - log(z) - Y;
  72. }
  73. else if(z < -boost::math::tools::log_min_value<T>())
  74. {
  75. // Maximum Deviation Found (interpolated): 1.444e-17
  76. // Max error found at double precision: 3.119e-17
  77. static const T P[11] = {
  78. BOOST_MATH_BIG_CONSTANT(T, 53, -0.121013190657725568138e-18),
  79. BOOST_MATH_BIG_CONSTANT(T, 53, -0.999999999999998811143),
  80. BOOST_MATH_BIG_CONSTANT(T, 53, -43.3058660811817946037),
  81. BOOST_MATH_BIG_CONSTANT(T, 53, -724.581482791462469795),
  82. BOOST_MATH_BIG_CONSTANT(T, 53, -6046.8250112711035463),
  83. BOOST_MATH_BIG_CONSTANT(T, 53, -27182.6254466733970467),
  84. BOOST_MATH_BIG_CONSTANT(T, 53, -66598.2652345418633509),
  85. BOOST_MATH_BIG_CONSTANT(T, 53, -86273.1567711649528784),
  86. BOOST_MATH_BIG_CONSTANT(T, 53, -54844.4587226402067411),
  87. BOOST_MATH_BIG_CONSTANT(T, 53, -14751.4895786128450662),
  88. BOOST_MATH_BIG_CONSTANT(T, 53, -1185.45720315201027667)
  89. };
  90. static const T Q[12] = {
  91. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  92. BOOST_MATH_BIG_CONSTANT(T, 53, 45.3058660811801465927),
  93. BOOST_MATH_BIG_CONSTANT(T, 53, 809.193214954550328455),
  94. BOOST_MATH_BIG_CONSTANT(T, 53, 7417.37624454689546708),
  95. BOOST_MATH_BIG_CONSTANT(T, 53, 38129.5594484818471461),
  96. BOOST_MATH_BIG_CONSTANT(T, 53, 113057.05869159631492),
  97. BOOST_MATH_BIG_CONSTANT(T, 53, 192104.047790227984431),
  98. BOOST_MATH_BIG_CONSTANT(T, 53, 180329.498380501819718),
  99. BOOST_MATH_BIG_CONSTANT(T, 53, 86722.3403467334749201),
  100. BOOST_MATH_BIG_CONSTANT(T, 53, 18455.4124737722049515),
  101. BOOST_MATH_BIG_CONSTANT(T, 53, 1229.20784182403048905),
  102. BOOST_MATH_BIG_CONSTANT(T, 53, -0.776491285282330997549)
  103. };
  104. T recip = 1 / z;
  105. result = 1 + tools::evaluate_polynomial(P, recip)
  106. / tools::evaluate_polynomial(Q, recip);
  107. result *= exp(-z) * recip;
  108. }
  109. else
  110. {
  111. result = 0;
  112. }
  113. return result;
  114. }
  115. template <class T>
  116. T expint_1_rational(const T& z, const std::integral_constant<int, 64>&)
  117. {
  118. BOOST_MATH_STD_USING
  119. T result;
  120. if(z <= 1)
  121. {
  122. // Maximum Deviation Found: 3.807e-20
  123. // Expected Error Term: 3.807e-20
  124. // Max error found at long double precision: 6.249e-20
  125. static const T Y = 0.66373538970947265625F;
  126. static const T P[6] = {
  127. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0865197248079397956816),
  128. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0275114007037026844633),
  129. BOOST_MATH_BIG_CONSTANT(T, 64, -0.246594388074877139824),
  130. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0237624819878732642231),
  131. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00259113319641673986276),
  132. BOOST_MATH_BIG_CONSTANT(T, 64, 0.30853660894346057053e-4)
  133. };
  134. static const T Q[7] = {
  135. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  136. BOOST_MATH_BIG_CONSTANT(T, 64, 0.317978365797784100273),
  137. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0393622602554758722511),
  138. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00204062029115966323229),
  139. BOOST_MATH_BIG_CONSTANT(T, 64, 0.732512107100088047854e-5),
  140. BOOST_MATH_BIG_CONSTANT(T, 64, -0.202872781770207871975e-5),
  141. BOOST_MATH_BIG_CONSTANT(T, 64, 0.52779248094603709945e-7)
  142. };
  143. result = tools::evaluate_polynomial(P, z)
  144. / tools::evaluate_polynomial(Q, z);
  145. result += z - log(z) - Y;
  146. }
  147. else if(z < -boost::math::tools::log_min_value<T>())
  148. {
  149. // Maximum Deviation Found (interpolated): 2.220e-20
  150. // Max error found at long double precision: 1.346e-19
  151. static const T P[14] = {
  152. BOOST_MATH_BIG_CONSTANT(T, 64, -0.534401189080684443046e-23),
  153. BOOST_MATH_BIG_CONSTANT(T, 64, -0.999999999999999999905),
  154. BOOST_MATH_BIG_CONSTANT(T, 64, -62.1517806091379402505),
  155. BOOST_MATH_BIG_CONSTANT(T, 64, -1568.45688271895145277),
  156. BOOST_MATH_BIG_CONSTANT(T, 64, -21015.3431990874009619),
  157. BOOST_MATH_BIG_CONSTANT(T, 64, -164333.011755931661949),
  158. BOOST_MATH_BIG_CONSTANT(T, 64, -777917.270775426696103),
  159. BOOST_MATH_BIG_CONSTANT(T, 64, -2244188.56195255112937),
  160. BOOST_MATH_BIG_CONSTANT(T, 64, -3888702.98145335643429),
  161. BOOST_MATH_BIG_CONSTANT(T, 64, -3909822.65621952648353),
  162. BOOST_MATH_BIG_CONSTANT(T, 64, -2149033.9538897398457),
  163. BOOST_MATH_BIG_CONSTANT(T, 64, -584705.537139793925189),
  164. BOOST_MATH_BIG_CONSTANT(T, 64, -65815.2605361889477244),
  165. BOOST_MATH_BIG_CONSTANT(T, 64, -2038.82870680427258038)
  166. };
  167. static const T Q[14] = {
  168. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  169. BOOST_MATH_BIG_CONSTANT(T, 64, 64.1517806091379399478),
  170. BOOST_MATH_BIG_CONSTANT(T, 64, 1690.76044393722763785),
  171. BOOST_MATH_BIG_CONSTANT(T, 64, 24035.9534033068949426),
  172. BOOST_MATH_BIG_CONSTANT(T, 64, 203679.998633572361706),
  173. BOOST_MATH_BIG_CONSTANT(T, 64, 1074661.58459976978285),
  174. BOOST_MATH_BIG_CONSTANT(T, 64, 3586552.65020899358773),
  175. BOOST_MATH_BIG_CONSTANT(T, 64, 7552186.84989547621411),
  176. BOOST_MATH_BIG_CONSTANT(T, 64, 9853333.79353054111434),
  177. BOOST_MATH_BIG_CONSTANT(T, 64, 7689642.74550683631258),
  178. BOOST_MATH_BIG_CONSTANT(T, 64, 3385553.35146759180739),
  179. BOOST_MATH_BIG_CONSTANT(T, 64, 763218.072732396428725),
  180. BOOST_MATH_BIG_CONSTANT(T, 64, 73930.2995984054930821),
  181. BOOST_MATH_BIG_CONSTANT(T, 64, 2063.86994219629165937)
  182. };
  183. T recip = 1 / z;
  184. result = 1 + tools::evaluate_polynomial(P, recip)
  185. / tools::evaluate_polynomial(Q, recip);
  186. result *= exp(-z) * recip;
  187. }
  188. else
  189. {
  190. result = 0;
  191. }
  192. return result;
  193. }
  194. template <class T>
  195. T expint_1_rational(const T& z, const std::integral_constant<int, 113>&)
  196. {
  197. BOOST_MATH_STD_USING
  198. T result;
  199. if(z <= 1)
  200. {
  201. // Maximum Deviation Found: 2.477e-35
  202. // Expected Error Term: 2.477e-35
  203. // Max error found at long double precision: 6.810e-35
  204. static const T Y = 0.66373538970947265625F;
  205. static const T P[10] = {
  206. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0865197248079397956434879099175975937),
  207. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0369066175910795772830865304506087759),
  208. BOOST_MATH_BIG_CONSTANT(T, 113, -0.24272036838415474665971599314725545),
  209. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0502166331248948515282379137550178307),
  210. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00768384138547489410285101483730424919),
  211. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000612574337702109683505224915484717162),
  212. BOOST_MATH_BIG_CONSTANT(T, 113, -0.380207107950635046971492617061708534e-4),
  213. BOOST_MATH_BIG_CONSTANT(T, 113, -0.136528159460768830763009294683628406e-5),
  214. BOOST_MATH_BIG_CONSTANT(T, 113, -0.346839106212658259681029388908658618e-7),
  215. BOOST_MATH_BIG_CONSTANT(T, 113, -0.340500302777838063940402160594523429e-9)
  216. };
  217. static const T Q[10] = {
  218. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  219. BOOST_MATH_BIG_CONSTANT(T, 113, 0.426568827778942588160423015589537302),
  220. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0841384046470893490592450881447510148),
  221. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0100557215850668029618957359471132995),
  222. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000799334870474627021737357294799839363),
  223. BOOST_MATH_BIG_CONSTANT(T, 113, 0.434452090903862735242423068552687688e-4),
  224. BOOST_MATH_BIG_CONSTANT(T, 113, 0.15829674748799079874182885081231252e-5),
  225. BOOST_MATH_BIG_CONSTANT(T, 113, 0.354406206738023762100882270033082198e-7),
  226. BOOST_MATH_BIG_CONSTANT(T, 113, 0.369373328141051577845488477377890236e-9),
  227. BOOST_MATH_BIG_CONSTANT(T, 113, -0.274149801370933606409282434677600112e-12)
  228. };
  229. result = tools::evaluate_polynomial(P, z)
  230. / tools::evaluate_polynomial(Q, z);
  231. result += z - log(z) - Y;
  232. }
  233. else if(z <= 4)
  234. {
  235. // Max error in interpolated form: 5.614e-35
  236. // Max error found at long double precision: 7.979e-35
  237. static const T Y = 0.70190334320068359375F;
  238. static const T P[16] = {
  239. BOOST_MATH_BIG_CONSTANT(T, 113, 0.298096656795020369955077350585959794),
  240. BOOST_MATH_BIG_CONSTANT(T, 113, 12.9314045995266142913135497455971247),
  241. BOOST_MATH_BIG_CONSTANT(T, 113, 226.144334921582637462526628217345501),
  242. BOOST_MATH_BIG_CONSTANT(T, 113, 2070.83670924261732722117682067381405),
  243. BOOST_MATH_BIG_CONSTANT(T, 113, 10715.1115684330959908244769731347186),
  244. BOOST_MATH_BIG_CONSTANT(T, 113, 30728.7876355542048019664777316053311),
  245. BOOST_MATH_BIG_CONSTANT(T, 113, 38520.6078609349855436936232610875297),
  246. BOOST_MATH_BIG_CONSTANT(T, 113, -27606.0780981527583168728339620565165),
  247. BOOST_MATH_BIG_CONSTANT(T, 113, -169026.485055785605958655247592604835),
  248. BOOST_MATH_BIG_CONSTANT(T, 113, -254361.919204983608659069868035092282),
  249. BOOST_MATH_BIG_CONSTANT(T, 113, -195765.706874132267953259272028679935),
  250. BOOST_MATH_BIG_CONSTANT(T, 113, -83352.6826013533205474990119962408675),
  251. BOOST_MATH_BIG_CONSTANT(T, 113, -19251.6828496869586415162597993050194),
  252. BOOST_MATH_BIG_CONSTANT(T, 113, -2226.64251774578542836725386936102339),
  253. BOOST_MATH_BIG_CONSTANT(T, 113, -109.009437301400845902228611986479816),
  254. BOOST_MATH_BIG_CONSTANT(T, 113, -1.51492042209561411434644938098833499)
  255. };
  256. static const T Q[16] = {
  257. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  258. BOOST_MATH_BIG_CONSTANT(T, 113, 46.734521442032505570517810766704587),
  259. BOOST_MATH_BIG_CONSTANT(T, 113, 908.694714348462269000247450058595655),
  260. BOOST_MATH_BIG_CONSTANT(T, 113, 9701.76053033673927362784882748513195),
  261. BOOST_MATH_BIG_CONSTANT(T, 113, 63254.2815292641314236625196594947774),
  262. BOOST_MATH_BIG_CONSTANT(T, 113, 265115.641285880437335106541757711092),
  263. BOOST_MATH_BIG_CONSTANT(T, 113, 732707.841188071900498536533086567735),
  264. BOOST_MATH_BIG_CONSTANT(T, 113, 1348514.02492635723327306628712057794),
  265. BOOST_MATH_BIG_CONSTANT(T, 113, 1649986.81455283047769673308781585991),
  266. BOOST_MATH_BIG_CONSTANT(T, 113, 1326000.828522976970116271208812099),
  267. BOOST_MATH_BIG_CONSTANT(T, 113, 683643.09490612171772350481773951341),
  268. BOOST_MATH_BIG_CONSTANT(T, 113, 217640.505137263607952365685653352229),
  269. BOOST_MATH_BIG_CONSTANT(T, 113, 40288.3467237411710881822569476155485),
  270. BOOST_MATH_BIG_CONSTANT(T, 113, 3932.89353979531632559232883283175754),
  271. BOOST_MATH_BIG_CONSTANT(T, 113, 169.845369689596739824177412096477219),
  272. BOOST_MATH_BIG_CONSTANT(T, 113, 2.17607292280092201170768401876895354)
  273. };
  274. T recip = 1 / z;
  275. result = Y + tools::evaluate_polynomial(P, recip)
  276. / tools::evaluate_polynomial(Q, recip);
  277. result *= exp(-z) * recip;
  278. }
  279. else if(z < -boost::math::tools::log_min_value<T>())
  280. {
  281. // Max error in interpolated form: 4.413e-35
  282. // Max error found at long double precision: 8.928e-35
  283. static const T P[19] = {
  284. BOOST_MATH_BIG_CONSTANT(T, 113, -0.559148411832951463689610809550083986e-40),
  285. BOOST_MATH_BIG_CONSTANT(T, 113, -0.999999999999999999999999999999999997),
  286. BOOST_MATH_BIG_CONSTANT(T, 113, -166.542326331163836642960118190147367),
  287. BOOST_MATH_BIG_CONSTANT(T, 113, -12204.639128796330005065904675153652),
  288. BOOST_MATH_BIG_CONSTANT(T, 113, -520807.069767086071806275022036146855),
  289. BOOST_MATH_BIG_CONSTANT(T, 113, -14435981.5242137970691490903863125326),
  290. BOOST_MATH_BIG_CONSTANT(T, 113, -274574945.737064301247496460758654196),
  291. BOOST_MATH_BIG_CONSTANT(T, 113, -3691611582.99810039356254671781473079),
  292. BOOST_MATH_BIG_CONSTANT(T, 113, -35622515944.8255047299363690814678763),
  293. BOOST_MATH_BIG_CONSTANT(T, 113, -248040014774.502043161750715548451142),
  294. BOOST_MATH_BIG_CONSTANT(T, 113, -1243190389769.53458416330946622607913),
  295. BOOST_MATH_BIG_CONSTANT(T, 113, -4441730126135.54739052731990368425339),
  296. BOOST_MATH_BIG_CONSTANT(T, 113, -11117043181899.7388524310281751971366),
  297. BOOST_MATH_BIG_CONSTANT(T, 113, -18976497615396.9717776601813519498961),
  298. BOOST_MATH_BIG_CONSTANT(T, 113, -21237496819711.1011661104761906067131),
  299. BOOST_MATH_BIG_CONSTANT(T, 113, -14695899122092.5161620333466757812848),
  300. BOOST_MATH_BIG_CONSTANT(T, 113, -5737221535080.30569711574295785864903),
  301. BOOST_MATH_BIG_CONSTANT(T, 113, -1077042281708.42654526404581272546244),
  302. BOOST_MATH_BIG_CONSTANT(T, 113, -68028222642.1941480871395695677675137)
  303. };
  304. static const T Q[20] = {
  305. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  306. BOOST_MATH_BIG_CONSTANT(T, 113, 168.542326331163836642960118190147311),
  307. BOOST_MATH_BIG_CONSTANT(T, 113, 12535.7237814586576783518249115343619),
  308. BOOST_MATH_BIG_CONSTANT(T, 113, 544891.263372016404143120911148640627),
  309. BOOST_MATH_BIG_CONSTANT(T, 113, 15454474.7241010258634446523045237762),
  310. BOOST_MATH_BIG_CONSTANT(T, 113, 302495899.896629522673410325891717381),
  311. BOOST_MATH_BIG_CONSTANT(T, 113, 4215565948.38886507646911672693270307),
  312. BOOST_MATH_BIG_CONSTANT(T, 113, 42552409471.7951815668506556705733344),
  313. BOOST_MATH_BIG_CONSTANT(T, 113, 313592377066.753173979584098301610186),
  314. BOOST_MATH_BIG_CONSTANT(T, 113, 1688763640223.4541980740597514904542),
  315. BOOST_MATH_BIG_CONSTANT(T, 113, 6610992294901.59589748057620192145704),
  316. BOOST_MATH_BIG_CONSTANT(T, 113, 18601637235659.6059890851321772682606),
  317. BOOST_MATH_BIG_CONSTANT(T, 113, 36944278231087.2571020964163402941583),
  318. BOOST_MATH_BIG_CONSTANT(T, 113, 50425858518481.7497071917028793820058),
  319. BOOST_MATH_BIG_CONSTANT(T, 113, 45508060902865.0899967797848815980644),
  320. BOOST_MATH_BIG_CONSTANT(T, 113, 25649955002765.3817331501988304758142),
  321. BOOST_MATH_BIG_CONSTANT(T, 113, 8259575619094.6518520988612711292331),
  322. BOOST_MATH_BIG_CONSTANT(T, 113, 1299981487496.12607474362723586264515),
  323. BOOST_MATH_BIG_CONSTANT(T, 113, 70242279152.8241187845178443118302693),
  324. BOOST_MATH_BIG_CONSTANT(T, 113, -37633302.9409263839042721539363416685)
  325. };
  326. T recip = 1 / z;
  327. result = 1 + tools::evaluate_polynomial(P, recip)
  328. / tools::evaluate_polynomial(Q, recip);
  329. result *= exp(-z) * recip;
  330. }
  331. else
  332. {
  333. result = 0;
  334. }
  335. return result;
  336. }
  337. template <class T>
  338. struct expint_fraction
  339. {
  340. typedef std::pair<T,T> result_type;
  341. expint_fraction(unsigned n_, T z_) : b(n_ + z_), i(-1), n(n_){}
  342. std::pair<T,T> operator()()
  343. {
  344. std::pair<T,T> result = std::make_pair(-static_cast<T>((i+1) * (n+i)), b);
  345. b += 2;
  346. ++i;
  347. return result;
  348. }
  349. private:
  350. T b;
  351. int i;
  352. unsigned n;
  353. };
  354. template <class T, class Policy>
  355. inline T expint_as_fraction(unsigned n, T z, const Policy& pol)
  356. {
  357. BOOST_MATH_STD_USING
  358. BOOST_MATH_INSTRUMENT_VARIABLE(z)
  359. boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  360. expint_fraction<T> f(n, z);
  361. T result = tools::continued_fraction_b(
  362. f,
  363. boost::math::policies::get_epsilon<T, Policy>(),
  364. max_iter);
  365. policies::check_series_iterations<T>("boost::math::expint_continued_fraction<%1%>(unsigned,%1%)", max_iter, pol);
  366. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  367. BOOST_MATH_INSTRUMENT_VARIABLE(max_iter)
  368. result = exp(-z) / result;
  369. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  370. return result;
  371. }
  372. template <class T>
  373. struct expint_series
  374. {
  375. typedef T result_type;
  376. expint_series(unsigned k_, T z_, T x_k_, T denom_, T fact_)
  377. : k(k_), z(z_), x_k(x_k_), denom(denom_), fact(fact_){}
  378. T operator()()
  379. {
  380. x_k *= -z;
  381. denom += 1;
  382. fact *= ++k;
  383. return x_k / (denom * fact);
  384. }
  385. private:
  386. unsigned k;
  387. T z;
  388. T x_k;
  389. T denom;
  390. T fact;
  391. };
  392. template <class T, class Policy>
  393. inline T expint_as_series(unsigned n, T z, const Policy& pol)
  394. {
  395. BOOST_MATH_STD_USING
  396. boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  397. BOOST_MATH_INSTRUMENT_VARIABLE(z)
  398. T result = 0;
  399. T x_k = -1;
  400. T denom = T(1) - n;
  401. T fact = 1;
  402. unsigned k = 0;
  403. for(; k < n - 1;)
  404. {
  405. result += x_k / (denom * fact);
  406. denom += 1;
  407. x_k *= -z;
  408. fact *= ++k;
  409. }
  410. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  411. result += pow(-z, static_cast<T>(n - 1))
  412. * (boost::math::digamma(static_cast<T>(n), pol) - log(z)) / fact;
  413. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  414. expint_series<T> s(k, z, x_k, denom, fact);
  415. result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, result);
  416. policies::check_series_iterations<T>("boost::math::expint_series<%1%>(unsigned,%1%)", max_iter, pol);
  417. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  418. BOOST_MATH_INSTRUMENT_VARIABLE(max_iter)
  419. return result;
  420. }
  421. template <class T, class Policy, class Tag>
  422. T expint_imp(unsigned n, T z, const Policy& pol, const Tag& tag)
  423. {
  424. BOOST_MATH_STD_USING
  425. static const char* function = "boost::math::expint<%1%>(unsigned, %1%)";
  426. if(z < 0)
  427. return policies::raise_domain_error<T>(function, "Function requires z >= 0 but got %1%.", z, pol);
  428. if(z == 0)
  429. return n == 1 ? policies::raise_overflow_error<T>(function, 0, pol) : T(1 / (static_cast<T>(n - 1)));
  430. T result;
  431. bool f;
  432. if(n < 3)
  433. {
  434. f = z < 0.5;
  435. }
  436. else
  437. {
  438. f = z < (static_cast<T>(n - 2) / static_cast<T>(n - 1));
  439. }
  440. #ifdef BOOST_MSVC
  441. # pragma warning(push)
  442. # pragma warning(disable:4127) // conditional expression is constant
  443. #endif
  444. if(n == 0)
  445. result = exp(-z) / z;
  446. else if((n == 1) && (Tag::value))
  447. {
  448. result = expint_1_rational(z, tag);
  449. }
  450. else if(f)
  451. result = expint_as_series(n, z, pol);
  452. else
  453. result = expint_as_fraction(n, z, pol);
  454. #ifdef BOOST_MSVC
  455. # pragma warning(pop)
  456. #endif
  457. return result;
  458. }
  459. template <class T>
  460. struct expint_i_series
  461. {
  462. typedef T result_type;
  463. expint_i_series(T z_) : k(0), z_k(1), z(z_){}
  464. T operator()()
  465. {
  466. z_k *= z / ++k;
  467. return z_k / k;
  468. }
  469. private:
  470. unsigned k;
  471. T z_k;
  472. T z;
  473. };
  474. template <class T, class Policy>
  475. T expint_i_as_series(T z, const Policy& pol)
  476. {
  477. BOOST_MATH_STD_USING
  478. T result = log(z); // (log(z) - log(1 / z)) / 2;
  479. result += constants::euler<T>();
  480. expint_i_series<T> s(z);
  481. boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  482. result = tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, result);
  483. policies::check_series_iterations<T>("boost::math::expint_i_series<%1%>(%1%)", max_iter, pol);
  484. return result;
  485. }
  486. template <class T, class Policy, class Tag>
  487. T expint_i_imp(T z, const Policy& pol, const Tag& tag)
  488. {
  489. static const char* function = "boost::math::expint<%1%>(%1%)";
  490. if(z < 0)
  491. return -expint_imp(1, T(-z), pol, tag);
  492. if(z == 0)
  493. return -policies::raise_overflow_error<T>(function, 0, pol);
  494. return expint_i_as_series(z, pol);
  495. }
  496. template <class T, class Policy>
  497. T expint_i_imp(T z, const Policy& pol, const std::integral_constant<int, 53>& tag)
  498. {
  499. BOOST_MATH_STD_USING
  500. static const char* function = "boost::math::expint<%1%>(%1%)";
  501. if(z < 0)
  502. return -expint_imp(1, T(-z), pol, tag);
  503. if(z == 0)
  504. return -policies::raise_overflow_error<T>(function, 0, pol);
  505. T result;
  506. if(z <= 6)
  507. {
  508. // Maximum Deviation Found: 2.852e-18
  509. // Expected Error Term: 2.852e-18
  510. // Max Error found at double precision = Poly: 2.636335e-16 Cheb: 4.187027e-16
  511. static const T P[10] = {
  512. BOOST_MATH_BIG_CONSTANT(T, 53, 2.98677224343598593013),
  513. BOOST_MATH_BIG_CONSTANT(T, 53, 0.356343618769377415068),
  514. BOOST_MATH_BIG_CONSTANT(T, 53, 0.780836076283730801839),
  515. BOOST_MATH_BIG_CONSTANT(T, 53, 0.114670926327032002811),
  516. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0499434773576515260534),
  517. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00726224593341228159561),
  518. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00115478237227804306827),
  519. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000116419523609765200999),
  520. BOOST_MATH_BIG_CONSTANT(T, 53, 0.798296365679269702435e-5),
  521. BOOST_MATH_BIG_CONSTANT(T, 53, 0.2777056254402008721e-6)
  522. };
  523. static const T Q[8] = {
  524. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  525. BOOST_MATH_BIG_CONSTANT(T, 53, -1.17090412365413911947),
  526. BOOST_MATH_BIG_CONSTANT(T, 53, 0.62215109846016746276),
  527. BOOST_MATH_BIG_CONSTANT(T, 53, -0.195114782069495403315),
  528. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0391523431392967238166),
  529. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00504800158663705747345),
  530. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000389034007436065401822),
  531. BOOST_MATH_BIG_CONSTANT(T, 53, -0.138972589601781706598e-4)
  532. };
  533. static const T c1 = BOOST_MATH_BIG_CONSTANT(T, 53, 1677624236387711.0);
  534. static const T c2 = BOOST_MATH_BIG_CONSTANT(T, 53, 4503599627370496.0);
  535. static const T r1 = static_cast<T>(c1 / c2);
  536. static const T r2 = BOOST_MATH_BIG_CONSTANT(T, 53, 0.131401834143860282009280387409357165515556574352422001206362e-16);
  537. static const T r = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 53, 0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392));
  538. T t = (z / 3) - 1;
  539. result = tools::evaluate_polynomial(P, t)
  540. / tools::evaluate_polynomial(Q, t);
  541. t = (z - r1) - r2;
  542. result *= t;
  543. if(fabs(t) < 0.1)
  544. {
  545. result += boost::math::log1p(t / r, pol);
  546. }
  547. else
  548. {
  549. result += log(z / r);
  550. }
  551. }
  552. else if (z <= 10)
  553. {
  554. // Maximum Deviation Found: 6.546e-17
  555. // Expected Error Term: 6.546e-17
  556. // Max Error found at double precision = Poly: 6.890169e-17 Cheb: 6.772128e-17
  557. static const T Y = 1.158985137939453125F;
  558. static const T P[8] = {
  559. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00139324086199402804173),
  560. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0349921221823888744966),
  561. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0264095520754134848538),
  562. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00761224003005476438412),
  563. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00247496209592143627977),
  564. BOOST_MATH_BIG_CONSTANT(T, 53, -0.000374885917942100256775),
  565. BOOST_MATH_BIG_CONSTANT(T, 53, -0.554086272024881826253e-4),
  566. BOOST_MATH_BIG_CONSTANT(T, 53, -0.396487648924804510056e-5)
  567. };
  568. static const T Q[8] = {
  569. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  570. BOOST_MATH_BIG_CONSTANT(T, 53, 0.744625566823272107711),
  571. BOOST_MATH_BIG_CONSTANT(T, 53, 0.329061095011767059236),
  572. BOOST_MATH_BIG_CONSTANT(T, 53, 0.100128624977313872323),
  573. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0223851099128506347278),
  574. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00365334190742316650106),
  575. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000402453408512476836472),
  576. BOOST_MATH_BIG_CONSTANT(T, 53, 0.263649630720255691787e-4)
  577. };
  578. T t = z / 2 - 4;
  579. result = Y + tools::evaluate_polynomial(P, t)
  580. / tools::evaluate_polynomial(Q, t);
  581. result *= exp(z) / z;
  582. result += z;
  583. }
  584. else if(z <= 20)
  585. {
  586. // Maximum Deviation Found: 1.843e-17
  587. // Expected Error Term: -1.842e-17
  588. // Max Error found at double precision = Poly: 4.375868e-17 Cheb: 5.860967e-17
  589. static const T Y = 1.0869731903076171875F;
  590. static const T P[9] = {
  591. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00893891094356945667451),
  592. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0484607730127134045806),
  593. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0652810444222236895772),
  594. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0478447572647309671455),
  595. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0226059218923777094596),
  596. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00720603636917482065907),
  597. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00155941947035972031334),
  598. BOOST_MATH_BIG_CONSTANT(T, 53, -0.000209750022660200888349),
  599. BOOST_MATH_BIG_CONSTANT(T, 53, -0.138652200349182596186e-4)
  600. };
  601. static const T Q[9] = {
  602. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  603. BOOST_MATH_BIG_CONSTANT(T, 53, 1.97017214039061194971),
  604. BOOST_MATH_BIG_CONSTANT(T, 53, 1.86232465043073157508),
  605. BOOST_MATH_BIG_CONSTANT(T, 53, 1.09601437090337519977),
  606. BOOST_MATH_BIG_CONSTANT(T, 53, 0.438873285773088870812),
  607. BOOST_MATH_BIG_CONSTANT(T, 53, 0.122537731979686102756),
  608. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0233458478275769288159),
  609. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00278170769163303669021),
  610. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000159150281166108755531)
  611. };
  612. T t = z / 5 - 3;
  613. result = Y + tools::evaluate_polynomial(P, t)
  614. / tools::evaluate_polynomial(Q, t);
  615. result *= exp(z) / z;
  616. result += z;
  617. }
  618. else if(z <= 40)
  619. {
  620. // Maximum Deviation Found: 5.102e-18
  621. // Expected Error Term: 5.101e-18
  622. // Max Error found at double precision = Poly: 1.441088e-16 Cheb: 1.864792e-16
  623. static const T Y = 1.03937530517578125F;
  624. static const T P[9] = {
  625. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00356165148914447597995),
  626. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0229930320357982333406),
  627. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0449814350482277917716),
  628. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0453759383048193402336),
  629. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0272050837209380717069),
  630. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00994403059883350813295),
  631. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00207592267812291726961),
  632. BOOST_MATH_BIG_CONSTANT(T, 53, -0.000192178045857733706044),
  633. BOOST_MATH_BIG_CONSTANT(T, 53, -0.113161784705911400295e-9)
  634. };
  635. static const T Q[9] = {
  636. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  637. BOOST_MATH_BIG_CONSTANT(T, 53, 2.84354408840148561131),
  638. BOOST_MATH_BIG_CONSTANT(T, 53, 3.6599610090072393012),
  639. BOOST_MATH_BIG_CONSTANT(T, 53, 2.75088464344293083595),
  640. BOOST_MATH_BIG_CONSTANT(T, 53, 1.2985244073998398643),
  641. BOOST_MATH_BIG_CONSTANT(T, 53, 0.383213198510794507409),
  642. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0651165455496281337831),
  643. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00488071077519227853585)
  644. };
  645. T t = z / 10 - 3;
  646. result = Y + tools::evaluate_polynomial(P, t)
  647. / tools::evaluate_polynomial(Q, t);
  648. result *= exp(z) / z;
  649. result += z;
  650. }
  651. else
  652. {
  653. // Max Error found at double precision = 3.381886e-17
  654. static const T exp40 = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 53, 2.35385266837019985407899910749034804508871617254555467236651e17));
  655. static const T Y= 1.013065338134765625F;
  656. static const T P[6] = {
  657. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0130653381347656243849),
  658. BOOST_MATH_BIG_CONSTANT(T, 53, 0.19029710559486576682),
  659. BOOST_MATH_BIG_CONSTANT(T, 53, 94.7365094537197236011),
  660. BOOST_MATH_BIG_CONSTANT(T, 53, -2516.35323679844256203),
  661. BOOST_MATH_BIG_CONSTANT(T, 53, 18932.0850014925993025),
  662. BOOST_MATH_BIG_CONSTANT(T, 53, -38703.1431362056714134)
  663. };
  664. static const T Q[7] = {
  665. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  666. BOOST_MATH_BIG_CONSTANT(T, 53, 61.9733592849439884145),
  667. BOOST_MATH_BIG_CONSTANT(T, 53, -2354.56211323420194283),
  668. BOOST_MATH_BIG_CONSTANT(T, 53, 22329.1459489893079041),
  669. BOOST_MATH_BIG_CONSTANT(T, 53, -70126.245140396567133),
  670. BOOST_MATH_BIG_CONSTANT(T, 53, 54738.2833147775537106),
  671. BOOST_MATH_BIG_CONSTANT(T, 53, 8297.16296356518409347)
  672. };
  673. T t = 1 / z;
  674. result = Y + tools::evaluate_polynomial(P, t)
  675. / tools::evaluate_polynomial(Q, t);
  676. if(z < 41)
  677. result *= exp(z) / z;
  678. else
  679. {
  680. // Avoid premature overflow if we can:
  681. t = z - 40;
  682. if(t > tools::log_max_value<T>())
  683. {
  684. result = policies::raise_overflow_error<T>(function, 0, pol);
  685. }
  686. else
  687. {
  688. result *= exp(z - 40) / z;
  689. if(result > tools::max_value<T>() / exp40)
  690. {
  691. result = policies::raise_overflow_error<T>(function, 0, pol);
  692. }
  693. else
  694. {
  695. result *= exp40;
  696. }
  697. }
  698. }
  699. result += z;
  700. }
  701. return result;
  702. }
  703. template <class T, class Policy>
  704. T expint_i_imp(T z, const Policy& pol, const std::integral_constant<int, 64>& tag)
  705. {
  706. BOOST_MATH_STD_USING
  707. static const char* function = "boost::math::expint<%1%>(%1%)";
  708. if(z < 0)
  709. return -expint_imp(1, T(-z), pol, tag);
  710. if(z == 0)
  711. return -policies::raise_overflow_error<T>(function, 0, pol);
  712. T result;
  713. if(z <= 6)
  714. {
  715. // Maximum Deviation Found: 3.883e-21
  716. // Expected Error Term: 3.883e-21
  717. // Max Error found at long double precision = Poly: 3.344801e-19 Cheb: 4.989937e-19
  718. static const T P[11] = {
  719. BOOST_MATH_BIG_CONSTANT(T, 64, 2.98677224343598593764),
  720. BOOST_MATH_BIG_CONSTANT(T, 64, 0.25891613550886736592),
  721. BOOST_MATH_BIG_CONSTANT(T, 64, 0.789323584998672832285),
  722. BOOST_MATH_BIG_CONSTANT(T, 64, 0.092432587824602399339),
  723. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0514236978728625906656),
  724. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00658477469745132977921),
  725. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00124914538197086254233),
  726. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000131429679565472408551),
  727. BOOST_MATH_BIG_CONSTANT(T, 64, 0.11293331317982763165e-4),
  728. BOOST_MATH_BIG_CONSTANT(T, 64, 0.629499283139417444244e-6),
  729. BOOST_MATH_BIG_CONSTANT(T, 64, 0.177833045143692498221e-7)
  730. };
  731. static const T Q[9] = {
  732. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  733. BOOST_MATH_BIG_CONSTANT(T, 64, -1.20352377969742325748),
  734. BOOST_MATH_BIG_CONSTANT(T, 64, 0.66707904942606479811),
  735. BOOST_MATH_BIG_CONSTANT(T, 64, -0.223014531629140771914),
  736. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0493340022262908008636),
  737. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00741934273050807310677),
  738. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00074353567782087939294),
  739. BOOST_MATH_BIG_CONSTANT(T, 64, -0.455861727069603367656e-4),
  740. BOOST_MATH_BIG_CONSTANT(T, 64, 0.131515429329812837701e-5)
  741. };
  742. static const T c1 = BOOST_MATH_BIG_CONSTANT(T, 64, 1677624236387711.0);
  743. static const T c2 = BOOST_MATH_BIG_CONSTANT(T, 64, 4503599627370496.0);
  744. static const T r1 = c1 / c2;
  745. static const T r2 = BOOST_MATH_BIG_CONSTANT(T, 64, 0.131401834143860282009280387409357165515556574352422001206362e-16);
  746. static const T r = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392));
  747. T t = (z / 3) - 1;
  748. result = tools::evaluate_polynomial(P, t)
  749. / tools::evaluate_polynomial(Q, t);
  750. t = (z - r1) - r2;
  751. result *= t;
  752. if(fabs(t) < 0.1)
  753. {
  754. result += boost::math::log1p(t / r, pol);
  755. }
  756. else
  757. {
  758. result += log(z / r);
  759. }
  760. }
  761. else if (z <= 10)
  762. {
  763. // Maximum Deviation Found: 2.622e-21
  764. // Expected Error Term: -2.622e-21
  765. // Max Error found at long double precision = Poly: 1.208328e-20 Cheb: 1.073723e-20
  766. static const T Y = 1.158985137939453125F;
  767. static const T P[9] = {
  768. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00139324086199409049399),
  769. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0345238388952337563247),
  770. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0382065278072592940767),
  771. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0156117003070560727392),
  772. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00383276012430495387102),
  773. BOOST_MATH_BIG_CONSTANT(T, 64, -0.000697070540945496497992),
  774. BOOST_MATH_BIG_CONSTANT(T, 64, -0.877310384591205930343e-4),
  775. BOOST_MATH_BIG_CONSTANT(T, 64, -0.623067256376494930067e-5),
  776. BOOST_MATH_BIG_CONSTANT(T, 64, -0.377246883283337141444e-6)
  777. };
  778. static const T Q[10] = {
  779. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  780. BOOST_MATH_BIG_CONSTANT(T, 64, 1.08073635708902053767),
  781. BOOST_MATH_BIG_CONSTANT(T, 64, 0.553681133533942532909),
  782. BOOST_MATH_BIG_CONSTANT(T, 64, 0.176763647137553797451),
  783. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0387891748253869928121),
  784. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0060603004848394727017),
  785. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000670519492939992806051),
  786. BOOST_MATH_BIG_CONSTANT(T, 64, 0.4947357050100855646e-4),
  787. BOOST_MATH_BIG_CONSTANT(T, 64, 0.204339282037446434827e-5),
  788. BOOST_MATH_BIG_CONSTANT(T, 64, 0.146951181174930425744e-7)
  789. };
  790. T t = z / 2 - 4;
  791. result = Y + tools::evaluate_polynomial(P, t)
  792. / tools::evaluate_polynomial(Q, t);
  793. result *= exp(z) / z;
  794. result += z;
  795. }
  796. else if(z <= 20)
  797. {
  798. // Maximum Deviation Found: 3.220e-20
  799. // Expected Error Term: 3.220e-20
  800. // Max Error found at long double precision = Poly: 7.696841e-20 Cheb: 6.205163e-20
  801. static const T Y = 1.0869731903076171875F;
  802. static const T P[10] = {
  803. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00893891094356946995368),
  804. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0487562980088748775943),
  805. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0670568657950041926085),
  806. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0509577352851442932713),
  807. BOOST_MATH_BIG_CONSTANT(T, 64, -0.02551800927409034206),
  808. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00892913759760086687083),
  809. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00224469630207344379888),
  810. BOOST_MATH_BIG_CONSTANT(T, 64, -0.000392477245911296982776),
  811. BOOST_MATH_BIG_CONSTANT(T, 64, -0.44424044184395578775e-4),
  812. BOOST_MATH_BIG_CONSTANT(T, 64, -0.252788029251437017959e-5)
  813. };
  814. static const T Q[10] = {
  815. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  816. BOOST_MATH_BIG_CONSTANT(T, 64, 2.00323265503572414261),
  817. BOOST_MATH_BIG_CONSTANT(T, 64, 1.94688958187256383178),
  818. BOOST_MATH_BIG_CONSTANT(T, 64, 1.19733638134417472296),
  819. BOOST_MATH_BIG_CONSTANT(T, 64, 0.513137726038353385661),
  820. BOOST_MATH_BIG_CONSTANT(T, 64, 0.159135395578007264547),
  821. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0358233587351620919881),
  822. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0056716655597009417875),
  823. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000577048986213535829925),
  824. BOOST_MATH_BIG_CONSTANT(T, 64, 0.290976943033493216793e-4)
  825. };
  826. T t = z / 5 - 3;
  827. result = Y + tools::evaluate_polynomial(P, t)
  828. / tools::evaluate_polynomial(Q, t);
  829. result *= exp(z) / z;
  830. result += z;
  831. }
  832. else if(z <= 40)
  833. {
  834. // Maximum Deviation Found: 2.940e-21
  835. // Expected Error Term: -2.938e-21
  836. // Max Error found at long double precision = Poly: 3.419893e-19 Cheb: 3.359874e-19
  837. static const T Y = 1.03937530517578125F;
  838. static const T P[12] = {
  839. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00356165148914447278177),
  840. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0240235006148610849678),
  841. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0516699967278057976119),
  842. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0586603078706856245674),
  843. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0409960120868776180825),
  844. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0185485073689590665153),
  845. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00537842101034123222417),
  846. BOOST_MATH_BIG_CONSTANT(T, 64, -0.000920988084778273760609),
  847. BOOST_MATH_BIG_CONSTANT(T, 64, -0.716742618812210980263e-4),
  848. BOOST_MATH_BIG_CONSTANT(T, 64, -0.504623302166487346677e-9),
  849. BOOST_MATH_BIG_CONSTANT(T, 64, 0.712662196671896837736e-10),
  850. BOOST_MATH_BIG_CONSTANT(T, 64, -0.533769629702262072175e-11)
  851. };
  852. static const T Q[9] = {
  853. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  854. BOOST_MATH_BIG_CONSTANT(T, 64, 3.13286733695729715455),
  855. BOOST_MATH_BIG_CONSTANT(T, 64, 4.49281223045653491929),
  856. BOOST_MATH_BIG_CONSTANT(T, 64, 3.84900294427622911374),
  857. BOOST_MATH_BIG_CONSTANT(T, 64, 2.15205199043580378211),
  858. BOOST_MATH_BIG_CONSTANT(T, 64, 0.802912186540269232424),
  859. BOOST_MATH_BIG_CONSTANT(T, 64, 0.194793170017818925388),
  860. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0280128013584653182994),
  861. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00182034930799902922549)
  862. };
  863. T t = z / 10 - 3;
  864. result = Y + tools::evaluate_polynomial(P, t)
  865. / tools::evaluate_polynomial(Q, t);
  866. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  867. result *= exp(z) / z;
  868. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  869. result += z;
  870. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  871. }
  872. else
  873. {
  874. // Maximum Deviation Found: 3.536e-20
  875. // Max Error found at long double precision = Poly: 1.310671e-19 Cheb: 8.630943e-11
  876. static const T exp40 = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 64, 2.35385266837019985407899910749034804508871617254555467236651e17));
  877. static const T Y= 1.013065338134765625F;
  878. static const T P[9] = {
  879. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0130653381347656250004),
  880. BOOST_MATH_BIG_CONSTANT(T, 64, 0.644487780349757303739),
  881. BOOST_MATH_BIG_CONSTANT(T, 64, 143.995670348227433964),
  882. BOOST_MATH_BIG_CONSTANT(T, 64, -13918.9322758014173709),
  883. BOOST_MATH_BIG_CONSTANT(T, 64, 476260.975133624194484),
  884. BOOST_MATH_BIG_CONSTANT(T, 64, -7437102.15135982802122),
  885. BOOST_MATH_BIG_CONSTANT(T, 64, 53732298.8764767916542),
  886. BOOST_MATH_BIG_CONSTANT(T, 64, -160695051.957997452509),
  887. BOOST_MATH_BIG_CONSTANT(T, 64, 137839271.592778020028)
  888. };
  889. static const T Q[9] = {
  890. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  891. BOOST_MATH_BIG_CONSTANT(T, 64, 27.2103343964943718802),
  892. BOOST_MATH_BIG_CONSTANT(T, 64, -8785.48528692879413676),
  893. BOOST_MATH_BIG_CONSTANT(T, 64, 397530.290000322626766),
  894. BOOST_MATH_BIG_CONSTANT(T, 64, -7356441.34957799368252),
  895. BOOST_MATH_BIG_CONSTANT(T, 64, 63050914.5343400957524),
  896. BOOST_MATH_BIG_CONSTANT(T, 64, -246143779.638307701369),
  897. BOOST_MATH_BIG_CONSTANT(T, 64, 384647824.678554961174),
  898. BOOST_MATH_BIG_CONSTANT(T, 64, -166288297.874583961493)
  899. };
  900. T t = 1 / z;
  901. result = Y + tools::evaluate_polynomial(P, t)
  902. / tools::evaluate_polynomial(Q, t);
  903. if(z < 41)
  904. result *= exp(z) / z;
  905. else
  906. {
  907. // Avoid premature overflow if we can:
  908. t = z - 40;
  909. if(t > tools::log_max_value<T>())
  910. {
  911. result = policies::raise_overflow_error<T>(function, 0, pol);
  912. }
  913. else
  914. {
  915. result *= exp(z - 40) / z;
  916. if(result > tools::max_value<T>() / exp40)
  917. {
  918. result = policies::raise_overflow_error<T>(function, 0, pol);
  919. }
  920. else
  921. {
  922. result *= exp40;
  923. }
  924. }
  925. }
  926. result += z;
  927. }
  928. return result;
  929. }
  930. template <class T, class Policy>
  931. void expint_i_imp_113a(T& result, const T& z, const Policy& pol)
  932. {
  933. BOOST_MATH_STD_USING
  934. // Maximum Deviation Found: 1.230e-36
  935. // Expected Error Term: -1.230e-36
  936. // Max Error found at long double precision = Poly: 4.355299e-34 Cheb: 7.512581e-34
  937. static const T P[15] = {
  938. BOOST_MATH_BIG_CONSTANT(T, 113, 2.98677224343598593765287235997328555),
  939. BOOST_MATH_BIG_CONSTANT(T, 113, -0.333256034674702967028780537349334037),
  940. BOOST_MATH_BIG_CONSTANT(T, 113, 0.851831522798101228384971644036708463),
  941. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0657854833494646206186773614110374948),
  942. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0630065662557284456000060708977935073),
  943. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00311759191425309373327784154659649232),
  944. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00176213568201493949664478471656026771),
  945. BOOST_MATH_BIG_CONSTANT(T, 113, -0.491548660404172089488535218163952295e-4),
  946. BOOST_MATH_BIG_CONSTANT(T, 113, 0.207764227621061706075562107748176592e-4),
  947. BOOST_MATH_BIG_CONSTANT(T, 113, -0.225445398156913584846374273379402765e-6),
  948. BOOST_MATH_BIG_CONSTANT(T, 113, 0.996939977231410319761273881672601592e-7),
  949. BOOST_MATH_BIG_CONSTANT(T, 113, 0.212546902052178643330520878928100847e-9),
  950. BOOST_MATH_BIG_CONSTANT(T, 113, 0.154646053060262871360159325115980023e-9),
  951. BOOST_MATH_BIG_CONSTANT(T, 113, 0.143971277122049197323415503594302307e-11),
  952. BOOST_MATH_BIG_CONSTANT(T, 113, 0.306243138978114692252817805327426657e-13)
  953. };
  954. static const T Q[15] = {
  955. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  956. BOOST_MATH_BIG_CONSTANT(T, 113, -1.40178870313943798705491944989231793),
  957. BOOST_MATH_BIG_CONSTANT(T, 113, 0.943810968269701047641218856758605284),
  958. BOOST_MATH_BIG_CONSTANT(T, 113, -0.405026631534345064600850391026113165),
  959. BOOST_MATH_BIG_CONSTANT(T, 113, 0.123924153524614086482627660399122762),
  960. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0286364505373369439591132549624317707),
  961. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00516148845910606985396596845494015963),
  962. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000738330799456364820380739850924783649),
  963. BOOST_MATH_BIG_CONSTANT(T, 113, 0.843737760991856114061953265870882637e-4),
  964. BOOST_MATH_BIG_CONSTANT(T, 113, -0.767957673431982543213661388914587589e-5),
  965. BOOST_MATH_BIG_CONSTANT(T, 113, 0.549136847313854595809952100614840031e-6),
  966. BOOST_MATH_BIG_CONSTANT(T, 113, -0.299801381513743676764008325949325404e-7),
  967. BOOST_MATH_BIG_CONSTANT(T, 113, 0.118419479055346106118129130945423483e-8),
  968. BOOST_MATH_BIG_CONSTANT(T, 113, -0.30372295663095470359211949045344607e-10),
  969. BOOST_MATH_BIG_CONSTANT(T, 113, 0.382742953753485333207877784720070523e-12)
  970. };
  971. static const T c1 = BOOST_MATH_BIG_CONSTANT(T, 113, 1677624236387711.0);
  972. static const T c2 = BOOST_MATH_BIG_CONSTANT(T, 113, 4503599627370496.0);
  973. static const T c3 = BOOST_MATH_BIG_CONSTANT(T, 113, 266514582277687.0);
  974. static const T c4 = BOOST_MATH_BIG_CONSTANT(T, 113, 4503599627370496.0);
  975. static const T c5 = BOOST_MATH_BIG_CONSTANT(T, 113, 4503599627370496.0);
  976. static const T r1 = c1 / c2;
  977. static const T r2 = c3 / c4 / c5;
  978. static const T r3 = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 113, 0.283806480836357377069325311780969887585024578164571984232357e-31));
  979. static const T r = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 113, 0.372507410781366634461991866580119133535689497771654051555657435242200120636201854384926049951548942392));
  980. T t = (z / 3) - 1;
  981. result = tools::evaluate_polynomial(P, t)
  982. / tools::evaluate_polynomial(Q, t);
  983. t = ((z - r1) - r2) - r3;
  984. result *= t;
  985. if(fabs(t) < 0.1)
  986. {
  987. result += boost::math::log1p(t / r, pol);
  988. }
  989. else
  990. {
  991. result += log(z / r);
  992. }
  993. }
  994. template <class T>
  995. void expint_i_113b(T& result, const T& z)
  996. {
  997. BOOST_MATH_STD_USING
  998. // Maximum Deviation Found: 7.779e-36
  999. // Expected Error Term: -7.779e-36
  1000. // Max Error found at long double precision = Poly: 2.576723e-35 Cheb: 1.236001e-34
  1001. static const T Y = 1.158985137939453125F;
  1002. static const T P[15] = {
  1003. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00139324086199409049282472239613554817),
  1004. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0338173111691991289178779840307998955),
  1005. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0555972290794371306259684845277620556),
  1006. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0378677976003456171563136909186202177),
  1007. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0152221583517528358782902783914356667),
  1008. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00428283334203873035104248217403126905),
  1009. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000922782631491644846511553601323435286),
  1010. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000155513428088853161562660696055496696),
  1011. BOOST_MATH_BIG_CONSTANT(T, 113, -0.205756580255359882813545261519317096e-4),
  1012. BOOST_MATH_BIG_CONSTANT(T, 113, -0.220327406578552089820753181821115181e-5),
  1013. BOOST_MATH_BIG_CONSTANT(T, 113, -0.189483157545587592043421445645377439e-6),
  1014. BOOST_MATH_BIG_CONSTANT(T, 113, -0.122426571518570587750898968123803867e-7),
  1015. BOOST_MATH_BIG_CONSTANT(T, 113, -0.635187358949437991465353268374523944e-9),
  1016. BOOST_MATH_BIG_CONSTANT(T, 113, -0.203015132965870311935118337194860863e-10),
  1017. BOOST_MATH_BIG_CONSTANT(T, 113, -0.384276705503357655108096065452950822e-12)
  1018. };
  1019. static const T Q[15] = {
  1020. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1021. BOOST_MATH_BIG_CONSTANT(T, 113, 1.58784732785354597996617046880946257),
  1022. BOOST_MATH_BIG_CONSTANT(T, 113, 1.18550755302279446339364262338114098),
  1023. BOOST_MATH_BIG_CONSTANT(T, 113, 0.55598993549661368604527040349702836),
  1024. BOOST_MATH_BIG_CONSTANT(T, 113, 0.184290888380564236919107835030984453),
  1025. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0459658051803613282360464632326866113),
  1026. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0089505064268613225167835599456014705),
  1027. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00139042673882987693424772855926289077),
  1028. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000174210708041584097450805790176479012),
  1029. BOOST_MATH_BIG_CONSTANT(T, 113, 0.176324034009707558089086875136647376e-4),
  1030. BOOST_MATH_BIG_CONSTANT(T, 113, 0.142935845999505649273084545313710581e-5),
  1031. BOOST_MATH_BIG_CONSTANT(T, 113, 0.907502324487057260675816233312747784e-7),
  1032. BOOST_MATH_BIG_CONSTANT(T, 113, 0.431044337808893270797934621235918418e-8),
  1033. BOOST_MATH_BIG_CONSTANT(T, 113, 0.139007266881450521776529705677086902e-9),
  1034. BOOST_MATH_BIG_CONSTANT(T, 113, 0.234715286125516430792452741830364672e-11)
  1035. };
  1036. T t = z / 2 - 4;
  1037. result = Y + tools::evaluate_polynomial(P, t)
  1038. / tools::evaluate_polynomial(Q, t);
  1039. result *= exp(z) / z;
  1040. result += z;
  1041. }
  1042. template <class T>
  1043. void expint_i_113c(T& result, const T& z)
  1044. {
  1045. BOOST_MATH_STD_USING
  1046. // Maximum Deviation Found: 1.082e-34
  1047. // Expected Error Term: 1.080e-34
  1048. // Max Error found at long double precision = Poly: 1.958294e-34 Cheb: 2.472261e-34
  1049. static const T Y = 1.091579437255859375F;
  1050. static const T P[17] = {
  1051. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00685089599550151282724924894258520532),
  1052. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0443313550253580053324487059748497467),
  1053. BOOST_MATH_BIG_CONSTANT(T, 113, -0.071538561252424027443296958795814874),
  1054. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0622923153354102682285444067843300583),
  1055. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0361631270264607478205393775461208794),
  1056. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0153192826839624850298106509601033261),
  1057. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00496967904961260031539602977748408242),
  1058. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00126989079663425780800919171538920589),
  1059. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000258933143097125199914724875206326698),
  1060. BOOST_MATH_BIG_CONSTANT(T, 113, -0.422110326689204794443002330541441956e-4),
  1061. BOOST_MATH_BIG_CONSTANT(T, 113, -0.546004547590412661451073996127115221e-5),
  1062. BOOST_MATH_BIG_CONSTANT(T, 113, -0.546775260262202177131068692199272241e-6),
  1063. BOOST_MATH_BIG_CONSTANT(T, 113, -0.404157632825805803833379568956559215e-7),
  1064. BOOST_MATH_BIG_CONSTANT(T, 113, -0.200612596196561323832327013027419284e-8),
  1065. BOOST_MATH_BIG_CONSTANT(T, 113, -0.502538501472133913417609379765434153e-10),
  1066. BOOST_MATH_BIG_CONSTANT(T, 113, -0.326283053716799774936661568391296584e-13),
  1067. BOOST_MATH_BIG_CONSTANT(T, 113, 0.869226483473172853557775877908693647e-15)
  1068. };
  1069. static const T Q[15] = {
  1070. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1071. BOOST_MATH_BIG_CONSTANT(T, 113, 2.23227220874479061894038229141871087),
  1072. BOOST_MATH_BIG_CONSTANT(T, 113, 2.40221000361027971895657505660959863),
  1073. BOOST_MATH_BIG_CONSTANT(T, 113, 1.65476320985936174728238416007084214),
  1074. BOOST_MATH_BIG_CONSTANT(T, 113, 0.816828602963895720369875535001248227),
  1075. BOOST_MATH_BIG_CONSTANT(T, 113, 0.306337922909446903672123418670921066),
  1076. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0902400121654409267774593230720600752),
  1077. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0212708882169429206498765100993228086),
  1078. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00404442626252467471957713495828165491),
  1079. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0006195601618842253612635241404054589),
  1080. BOOST_MATH_BIG_CONSTANT(T, 113, 0.755930932686543009521454653994321843e-4),
  1081. BOOST_MATH_BIG_CONSTANT(T, 113, 0.716004532773778954193609582677482803e-5),
  1082. BOOST_MATH_BIG_CONSTANT(T, 113, 0.500881663076471627699290821742924233e-6),
  1083. BOOST_MATH_BIG_CONSTANT(T, 113, 0.233593219218823384508105943657387644e-7),
  1084. BOOST_MATH_BIG_CONSTANT(T, 113, 0.554900353169148897444104962034267682e-9)
  1085. };
  1086. T t = z / 4 - 3.5;
  1087. result = Y + tools::evaluate_polynomial(P, t)
  1088. / tools::evaluate_polynomial(Q, t);
  1089. result *= exp(z) / z;
  1090. result += z;
  1091. }
  1092. template <class T>
  1093. void expint_i_113d(T& result, const T& z)
  1094. {
  1095. BOOST_MATH_STD_USING
  1096. // Maximum Deviation Found: 3.163e-35
  1097. // Expected Error Term: 3.163e-35
  1098. // Max Error found at long double precision = Poly: 4.158110e-35 Cheb: 5.385532e-35
  1099. static const T Y = 1.051731109619140625F;
  1100. static const T P[14] = {
  1101. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00144552494420652573815404828020593565),
  1102. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0126747451594545338365684731262912741),
  1103. BOOST_MATH_BIG_CONSTANT(T, 113, -0.01757394877502366717526779263438073),
  1104. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0126838952395506921945756139424722588),
  1105. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0060045057928894974954756789352443522),
  1106. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00205349237147226126653803455793107903),
  1107. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000532606040579654887676082220195624207),
  1108. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000107344687098019891474772069139014662),
  1109. BOOST_MATH_BIG_CONSTANT(T, 113, -0.169536802705805811859089949943435152e-4),
  1110. BOOST_MATH_BIG_CONSTANT(T, 113, -0.20863311729206543881826553010120078e-5),
  1111. BOOST_MATH_BIG_CONSTANT(T, 113, -0.195670358542116256713560296776654385e-6),
  1112. BOOST_MATH_BIG_CONSTANT(T, 113, -0.133291168587253145439184028259772437e-7),
  1113. BOOST_MATH_BIG_CONSTANT(T, 113, -0.595500337089495614285777067722823397e-9),
  1114. BOOST_MATH_BIG_CONSTANT(T, 113, -0.133141358866324100955927979606981328e-10)
  1115. };
  1116. static const T Q[14] = {
  1117. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1118. BOOST_MATH_BIG_CONSTANT(T, 113, 1.72490783907582654629537013560044682),
  1119. BOOST_MATH_BIG_CONSTANT(T, 113, 1.44524329516800613088375685659759765),
  1120. BOOST_MATH_BIG_CONSTANT(T, 113, 0.778241785539308257585068744978050181),
  1121. BOOST_MATH_BIG_CONSTANT(T, 113, 0.300520486589206605184097270225725584),
  1122. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0879346899691339661394537806057953957),
  1123. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0200802415843802892793583043470125006),
  1124. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00362842049172586254520256100538273214),
  1125. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000519731362862955132062751246769469957),
  1126. BOOST_MATH_BIG_CONSTANT(T, 113, 0.584092147914050999895178697392282665e-4),
  1127. BOOST_MATH_BIG_CONSTANT(T, 113, 0.501851497707855358002773398333542337e-5),
  1128. BOOST_MATH_BIG_CONSTANT(T, 113, 0.313085677467921096644895738538865537e-6),
  1129. BOOST_MATH_BIG_CONSTANT(T, 113, 0.127552010539733113371132321521204458e-7),
  1130. BOOST_MATH_BIG_CONSTANT(T, 113, 0.25737310826983451144405899970774587e-9)
  1131. };
  1132. T t = z / 4 - 5.5;
  1133. result = Y + tools::evaluate_polynomial(P, t)
  1134. / tools::evaluate_polynomial(Q, t);
  1135. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1136. result *= exp(z) / z;
  1137. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1138. result += z;
  1139. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1140. }
  1141. template <class T>
  1142. void expint_i_113e(T& result, const T& z)
  1143. {
  1144. BOOST_MATH_STD_USING
  1145. // Maximum Deviation Found: 7.972e-36
  1146. // Expected Error Term: 7.962e-36
  1147. // Max Error found at long double precision = Poly: 1.711721e-34 Cheb: 3.100018e-34
  1148. static const T Y = 1.032726287841796875F;
  1149. static const T P[15] = {
  1150. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00141056919297307534690895009969373233),
  1151. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0123384175302540291339020257071411437),
  1152. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0298127270706864057791526083667396115),
  1153. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0390686759471630584626293670260768098),
  1154. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0338226792912607409822059922949035589),
  1155. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0211659736179834946452561197559654582),
  1156. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0100428887460879377373158821400070313),
  1157. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00370717396015165148484022792801682932),
  1158. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0010768667551001624764329000496561659),
  1159. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000246127328761027039347584096573123531),
  1160. BOOST_MATH_BIG_CONSTANT(T, 113, -0.437318110527818613580613051861991198e-4),
  1161. BOOST_MATH_BIG_CONSTANT(T, 113, -0.587532682329299591501065482317771497e-5),
  1162. BOOST_MATH_BIG_CONSTANT(T, 113, -0.565697065670893984610852937110819467e-6),
  1163. BOOST_MATH_BIG_CONSTANT(T, 113, -0.350233957364028523971768887437839573e-7),
  1164. BOOST_MATH_BIG_CONSTANT(T, 113, -0.105428907085424234504608142258423505e-8)
  1165. };
  1166. static const T Q[16] = {
  1167. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1168. BOOST_MATH_BIG_CONSTANT(T, 113, 3.17261315255467581204685605414005525),
  1169. BOOST_MATH_BIG_CONSTANT(T, 113, 4.85267952971640525245338392887217426),
  1170. BOOST_MATH_BIG_CONSTANT(T, 113, 4.74341914912439861451492872946725151),
  1171. BOOST_MATH_BIG_CONSTANT(T, 113, 3.31108463283559911602405970817931801),
  1172. BOOST_MATH_BIG_CONSTANT(T, 113, 1.74657006336994649386607925179848899),
  1173. BOOST_MATH_BIG_CONSTANT(T, 113, 0.718255607416072737965933040353653244),
  1174. BOOST_MATH_BIG_CONSTANT(T, 113, 0.234037553177354542791975767960643864),
  1175. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0607470145906491602476833515412605389),
  1176. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0125048143774226921434854172947548724),
  1177. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00201034366420433762935768458656609163),
  1178. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000244823338417452367656368849303165721),
  1179. BOOST_MATH_BIG_CONSTANT(T, 113, 0.213511655166983177960471085462540807e-4),
  1180. BOOST_MATH_BIG_CONSTANT(T, 113, 0.119323998465870686327170541547982932e-5),
  1181. BOOST_MATH_BIG_CONSTANT(T, 113, 0.322153582559488797803027773591727565e-7),
  1182. BOOST_MATH_BIG_CONSTANT(T, 113, -0.161635525318683508633792845159942312e-16)
  1183. };
  1184. T t = z / 8 - 4.25;
  1185. result = Y + tools::evaluate_polynomial(P, t)
  1186. / tools::evaluate_polynomial(Q, t);
  1187. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1188. result *= exp(z) / z;
  1189. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1190. result += z;
  1191. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1192. }
  1193. template <class T>
  1194. void expint_i_113f(T& result, const T& z)
  1195. {
  1196. BOOST_MATH_STD_USING
  1197. // Maximum Deviation Found: 4.469e-36
  1198. // Expected Error Term: 4.468e-36
  1199. // Max Error found at long double precision = Poly: 1.288958e-35 Cheb: 2.304586e-35
  1200. static const T Y = 1.0216197967529296875F;
  1201. static const T P[12] = {
  1202. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000322999116096627043476023926572650045),
  1203. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00385606067447365187909164609294113346),
  1204. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00686514524727568176735949971985244415),
  1205. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00606260649593050194602676772589601799),
  1206. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00334382362017147544335054575436194357),
  1207. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00126108534260253075708625583630318043),
  1208. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000337881489347846058951220431209276776),
  1209. BOOST_MATH_BIG_CONSTANT(T, 113, -0.648480902304640018785370650254018022e-4),
  1210. BOOST_MATH_BIG_CONSTANT(T, 113, -0.87652644082970492211455290209092766e-5),
  1211. BOOST_MATH_BIG_CONSTANT(T, 113, -0.794712243338068631557849449519994144e-6),
  1212. BOOST_MATH_BIG_CONSTANT(T, 113, -0.434084023639508143975983454830954835e-7),
  1213. BOOST_MATH_BIG_CONSTANT(T, 113, -0.107839681938752337160494412638656696e-8)
  1214. };
  1215. static const T Q[12] = {
  1216. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1217. BOOST_MATH_BIG_CONSTANT(T, 113, 2.09913805456661084097134805151524958),
  1218. BOOST_MATH_BIG_CONSTANT(T, 113, 2.07041755535439919593503171320431849),
  1219. BOOST_MATH_BIG_CONSTANT(T, 113, 1.26406517226052371320416108604874734),
  1220. BOOST_MATH_BIG_CONSTANT(T, 113, 0.529689923703770353961553223973435569),
  1221. BOOST_MATH_BIG_CONSTANT(T, 113, 0.159578150879536711042269658656115746),
  1222. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0351720877642000691155202082629857131),
  1223. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00565313621289648752407123620997063122),
  1224. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000646920278540515480093843570291218295),
  1225. BOOST_MATH_BIG_CONSTANT(T, 113, 0.499904084850091676776993523323213591e-4),
  1226. BOOST_MATH_BIG_CONSTANT(T, 113, 0.233740058688179614344680531486267142e-5),
  1227. BOOST_MATH_BIG_CONSTANT(T, 113, 0.498800627828842754845418576305379469e-7)
  1228. };
  1229. T t = z / 7 - 7;
  1230. result = Y + tools::evaluate_polynomial(P, t)
  1231. / tools::evaluate_polynomial(Q, t);
  1232. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1233. result *= exp(z) / z;
  1234. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1235. result += z;
  1236. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1237. }
  1238. template <class T>
  1239. void expint_i_113g(T& result, const T& z)
  1240. {
  1241. BOOST_MATH_STD_USING
  1242. // Maximum Deviation Found: 5.588e-35
  1243. // Expected Error Term: -5.566e-35
  1244. // Max Error found at long double precision = Poly: 9.976345e-35 Cheb: 8.358865e-35
  1245. static const T Y = 1.015148162841796875F;
  1246. static const T P[11] = {
  1247. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000435714784725086961464589957142615216),
  1248. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00432114324353830636009453048419094314),
  1249. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0100740363285526177522819204820582424),
  1250. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0116744115827059174392383504427640362),
  1251. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00816145387784261141360062395898644652),
  1252. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00371380272673500791322744465394211508),
  1253. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00112958263488611536502153195005736563),
  1254. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000228316462389404645183269923754256664),
  1255. BOOST_MATH_BIG_CONSTANT(T, 113, -0.29462181955852860250359064291292577e-4),
  1256. BOOST_MATH_BIG_CONSTANT(T, 113, -0.21972450610957417963227028788460299e-5),
  1257. BOOST_MATH_BIG_CONSTANT(T, 113, -0.720558173805289167524715527536874694e-7)
  1258. };
  1259. static const T Q[11] = {
  1260. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1261. BOOST_MATH_BIG_CONSTANT(T, 113, 2.95918362458402597039366979529287095),
  1262. BOOST_MATH_BIG_CONSTANT(T, 113, 3.96472247520659077944638411856748924),
  1263. BOOST_MATH_BIG_CONSTANT(T, 113, 3.15563251550528513747923714884142131),
  1264. BOOST_MATH_BIG_CONSTANT(T, 113, 1.64674612007093983894215359287448334),
  1265. BOOST_MATH_BIG_CONSTANT(T, 113, 0.58695020129846594405856226787156424),
  1266. BOOST_MATH_BIG_CONSTANT(T, 113, 0.144358385319329396231755457772362793),
  1267. BOOST_MATH_BIG_CONSTANT(T, 113, 0.024146911506411684815134916238348063),
  1268. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0026257132337460784266874572001650153),
  1269. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000167479843750859222348869769094711093),
  1270. BOOST_MATH_BIG_CONSTANT(T, 113, 0.475673638665358075556452220192497036e-5)
  1271. };
  1272. T t = z / 14 - 5;
  1273. result = Y + tools::evaluate_polynomial(P, t)
  1274. / tools::evaluate_polynomial(Q, t);
  1275. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1276. result *= exp(z) / z;
  1277. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1278. result += z;
  1279. BOOST_MATH_INSTRUMENT_VARIABLE(result)
  1280. }
  1281. template <class T>
  1282. void expint_i_113h(T& result, const T& z)
  1283. {
  1284. BOOST_MATH_STD_USING
  1285. // Maximum Deviation Found: 4.448e-36
  1286. // Expected Error Term: 4.445e-36
  1287. // Max Error found at long double precision = Poly: 2.058532e-35 Cheb: 2.165465e-27
  1288. static const T Y= 1.00849151611328125F;
  1289. static const T P[9] = {
  1290. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0084915161132812500000001440233607358),
  1291. BOOST_MATH_BIG_CONSTANT(T, 113, 1.84479378737716028341394223076147872),
  1292. BOOST_MATH_BIG_CONSTANT(T, 113, -130.431146923726715674081563022115568),
  1293. BOOST_MATH_BIG_CONSTANT(T, 113, 4336.26945491571504885214176203512015),
  1294. BOOST_MATH_BIG_CONSTANT(T, 113, -76279.0031974974730095170437591004177),
  1295. BOOST_MATH_BIG_CONSTANT(T, 113, 729577.956271997673695191455111727774),
  1296. BOOST_MATH_BIG_CONSTANT(T, 113, -3661928.69330208734947103004900349266),
  1297. BOOST_MATH_BIG_CONSTANT(T, 113, 8570600.041606912735872059184527855),
  1298. BOOST_MATH_BIG_CONSTANT(T, 113, -6758379.93672362080947905580906028645)
  1299. };
  1300. static const T Q[10] = {
  1301. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1302. BOOST_MATH_BIG_CONSTANT(T, 113, -99.4868026047611434569541483506091713),
  1303. BOOST_MATH_BIG_CONSTANT(T, 113, 3879.67753690517114249705089803055473),
  1304. BOOST_MATH_BIG_CONSTANT(T, 113, -76495.82413252517165830203774900806),
  1305. BOOST_MATH_BIG_CONSTANT(T, 113, 820773.726408311894342553758526282667),
  1306. BOOST_MATH_BIG_CONSTANT(T, 113, -4803087.64956923577571031564909646579),
  1307. BOOST_MATH_BIG_CONSTANT(T, 113, 14521246.227703545012713173740895477),
  1308. BOOST_MATH_BIG_CONSTANT(T, 113, -19762752.0196769712258527849159393044),
  1309. BOOST_MATH_BIG_CONSTANT(T, 113, 8354144.67882768405803322344185185517),
  1310. BOOST_MATH_BIG_CONSTANT(T, 113, 355076.853106511136734454134915432571)
  1311. };
  1312. T t = 1 / z;
  1313. result = Y + tools::evaluate_polynomial(P, t)
  1314. / tools::evaluate_polynomial(Q, t);
  1315. result *= exp(z) / z;
  1316. result += z;
  1317. }
  1318. template <class T, class Policy>
  1319. T expint_i_imp(T z, const Policy& pol, const std::integral_constant<int, 113>& tag)
  1320. {
  1321. BOOST_MATH_STD_USING
  1322. static const char* function = "boost::math::expint<%1%>(%1%)";
  1323. if(z < 0)
  1324. return -expint_imp(1, T(-z), pol, tag);
  1325. if(z == 0)
  1326. return -policies::raise_overflow_error<T>(function, 0, pol);
  1327. T result;
  1328. if(z <= 6)
  1329. {
  1330. expint_i_imp_113a(result, z, pol);
  1331. }
  1332. else if (z <= 10)
  1333. {
  1334. expint_i_113b(result, z);
  1335. }
  1336. else if(z <= 18)
  1337. {
  1338. expint_i_113c(result, z);
  1339. }
  1340. else if(z <= 26)
  1341. {
  1342. expint_i_113d(result, z);
  1343. }
  1344. else if(z <= 42)
  1345. {
  1346. expint_i_113e(result, z);
  1347. }
  1348. else if(z <= 56)
  1349. {
  1350. expint_i_113f(result, z);
  1351. }
  1352. else if(z <= 84)
  1353. {
  1354. expint_i_113g(result, z);
  1355. }
  1356. else if(z <= 210)
  1357. {
  1358. expint_i_113h(result, z);
  1359. }
  1360. else // z > 210
  1361. {
  1362. // Maximum Deviation Found: 3.963e-37
  1363. // Expected Error Term: 3.963e-37
  1364. // Max Error found at long double precision = Poly: 1.248049e-36 Cheb: 2.843486e-29
  1365. static const T exp40 = static_cast<T>(BOOST_MATH_BIG_CONSTANT(T, 113, 2.35385266837019985407899910749034804508871617254555467236651e17));
  1366. static const T Y= 1.00252532958984375F;
  1367. static const T P[8] = {
  1368. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00252532958984375000000000000000000085),
  1369. BOOST_MATH_BIG_CONSTANT(T, 113, 1.16591386866059087390621952073890359),
  1370. BOOST_MATH_BIG_CONSTANT(T, 113, -67.8483431314018462417456828499277579),
  1371. BOOST_MATH_BIG_CONSTANT(T, 113, 1567.68688154683822956359536287575892),
  1372. BOOST_MATH_BIG_CONSTANT(T, 113, -17335.4683325819116482498725687644986),
  1373. BOOST_MATH_BIG_CONSTANT(T, 113, 93632.6567462673524739954389166550069),
  1374. BOOST_MATH_BIG_CONSTANT(T, 113, -225025.189335919133214440347510936787),
  1375. BOOST_MATH_BIG_CONSTANT(T, 113, 175864.614717440010942804684741336853)
  1376. };
  1377. static const T Q[9] = {
  1378. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1379. BOOST_MATH_BIG_CONSTANT(T, 113, -65.6998869881600212224652719706425129),
  1380. BOOST_MATH_BIG_CONSTANT(T, 113, 1642.73850032324014781607859416890077),
  1381. BOOST_MATH_BIG_CONSTANT(T, 113, -19937.2610222467322481947237312818575),
  1382. BOOST_MATH_BIG_CONSTANT(T, 113, 124136.267326632742667972126625064538),
  1383. BOOST_MATH_BIG_CONSTANT(T, 113, -384614.251466704550678760562965502293),
  1384. BOOST_MATH_BIG_CONSTANT(T, 113, 523355.035910385688578278384032026998),
  1385. BOOST_MATH_BIG_CONSTANT(T, 113, -217809.552260834025885677791936351294),
  1386. BOOST_MATH_BIG_CONSTANT(T, 113, -8555.81719551123640677261226549550872)
  1387. };
  1388. T t = 1 / z;
  1389. result = Y + tools::evaluate_polynomial(P, t)
  1390. / tools::evaluate_polynomial(Q, t);
  1391. if(z < 41)
  1392. result *= exp(z) / z;
  1393. else
  1394. {
  1395. // Avoid premature overflow if we can:
  1396. t = z - 40;
  1397. if(t > tools::log_max_value<T>())
  1398. {
  1399. result = policies::raise_overflow_error<T>(function, 0, pol);
  1400. }
  1401. else
  1402. {
  1403. result *= exp(z - 40) / z;
  1404. if(result > tools::max_value<T>() / exp40)
  1405. {
  1406. result = policies::raise_overflow_error<T>(function, 0, pol);
  1407. }
  1408. else
  1409. {
  1410. result *= exp40;
  1411. }
  1412. }
  1413. }
  1414. result += z;
  1415. }
  1416. return result;
  1417. }
  1418. template <class T, class Policy, class tag>
  1419. struct expint_i_initializer
  1420. {
  1421. struct init
  1422. {
  1423. init()
  1424. {
  1425. do_init(tag());
  1426. }
  1427. static void do_init(const std::integral_constant<int, 0>&){}
  1428. static void do_init(const std::integral_constant<int, 53>&)
  1429. {
  1430. boost::math::expint(T(5), Policy());
  1431. boost::math::expint(T(7), Policy());
  1432. boost::math::expint(T(18), Policy());
  1433. boost::math::expint(T(38), Policy());
  1434. boost::math::expint(T(45), Policy());
  1435. }
  1436. static void do_init(const std::integral_constant<int, 64>&)
  1437. {
  1438. boost::math::expint(T(5), Policy());
  1439. boost::math::expint(T(7), Policy());
  1440. boost::math::expint(T(18), Policy());
  1441. boost::math::expint(T(38), Policy());
  1442. boost::math::expint(T(45), Policy());
  1443. }
  1444. static void do_init(const std::integral_constant<int, 113>&)
  1445. {
  1446. boost::math::expint(T(5), Policy());
  1447. boost::math::expint(T(7), Policy());
  1448. boost::math::expint(T(17), Policy());
  1449. boost::math::expint(T(25), Policy());
  1450. boost::math::expint(T(40), Policy());
  1451. boost::math::expint(T(50), Policy());
  1452. boost::math::expint(T(80), Policy());
  1453. boost::math::expint(T(200), Policy());
  1454. boost::math::expint(T(220), Policy());
  1455. }
  1456. void force_instantiate()const{}
  1457. };
  1458. static const init initializer;
  1459. static void force_instantiate()
  1460. {
  1461. initializer.force_instantiate();
  1462. }
  1463. };
  1464. template <class T, class Policy, class tag>
  1465. const typename expint_i_initializer<T, Policy, tag>::init expint_i_initializer<T, Policy, tag>::initializer;
  1466. template <class T, class Policy, class tag>
  1467. struct expint_1_initializer
  1468. {
  1469. struct init
  1470. {
  1471. init()
  1472. {
  1473. do_init(tag());
  1474. }
  1475. static void do_init(const std::integral_constant<int, 0>&){}
  1476. static void do_init(const std::integral_constant<int, 53>&)
  1477. {
  1478. boost::math::expint(1, T(0.5), Policy());
  1479. boost::math::expint(1, T(2), Policy());
  1480. }
  1481. static void do_init(const std::integral_constant<int, 64>&)
  1482. {
  1483. boost::math::expint(1, T(0.5), Policy());
  1484. boost::math::expint(1, T(2), Policy());
  1485. }
  1486. static void do_init(const std::integral_constant<int, 113>&)
  1487. {
  1488. boost::math::expint(1, T(0.5), Policy());
  1489. boost::math::expint(1, T(2), Policy());
  1490. boost::math::expint(1, T(6), Policy());
  1491. }
  1492. void force_instantiate()const{}
  1493. };
  1494. static const init initializer;
  1495. static void force_instantiate()
  1496. {
  1497. initializer.force_instantiate();
  1498. }
  1499. };
  1500. template <class T, class Policy, class tag>
  1501. const typename expint_1_initializer<T, Policy, tag>::init expint_1_initializer<T, Policy, tag>::initializer;
  1502. template <class T, class Policy>
  1503. inline typename tools::promote_args<T>::type
  1504. expint_forwarder(T z, const Policy& /*pol*/, std::true_type const&)
  1505. {
  1506. typedef typename tools::promote_args<T>::type result_type;
  1507. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  1508. typedef typename policies::precision<result_type, Policy>::type precision_type;
  1509. typedef typename policies::normalise<
  1510. Policy,
  1511. policies::promote_float<false>,
  1512. policies::promote_double<false>,
  1513. policies::discrete_quantile<>,
  1514. policies::assert_undefined<> >::type forwarding_policy;
  1515. typedef std::integral_constant<int,
  1516. precision_type::value <= 0 ? 0 :
  1517. precision_type::value <= 53 ? 53 :
  1518. precision_type::value <= 64 ? 64 :
  1519. precision_type::value <= 113 ? 113 : 0
  1520. > tag_type;
  1521. expint_i_initializer<value_type, forwarding_policy, tag_type>::force_instantiate();
  1522. return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::expint_i_imp(
  1523. static_cast<value_type>(z),
  1524. forwarding_policy(),
  1525. tag_type()), "boost::math::expint<%1%>(%1%)");
  1526. }
  1527. template <class T>
  1528. inline typename tools::promote_args<T>::type
  1529. expint_forwarder(unsigned n, T z, const std::false_type&)
  1530. {
  1531. return boost::math::expint(n, z, policies::policy<>());
  1532. }
  1533. } // namespace detail
  1534. template <class T, class Policy>
  1535. inline typename tools::promote_args<T>::type
  1536. expint(unsigned n, T z, const Policy& /*pol*/)
  1537. {
  1538. typedef typename tools::promote_args<T>::type result_type;
  1539. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  1540. typedef typename policies::precision<result_type, Policy>::type precision_type;
  1541. typedef typename policies::normalise<
  1542. Policy,
  1543. policies::promote_float<false>,
  1544. policies::promote_double<false>,
  1545. policies::discrete_quantile<>,
  1546. policies::assert_undefined<> >::type forwarding_policy;
  1547. typedef std::integral_constant<int,
  1548. precision_type::value <= 0 ? 0 :
  1549. precision_type::value <= 53 ? 53 :
  1550. precision_type::value <= 64 ? 64 :
  1551. precision_type::value <= 113 ? 113 : 0
  1552. > tag_type;
  1553. detail::expint_1_initializer<value_type, forwarding_policy, tag_type>::force_instantiate();
  1554. return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::expint_imp(
  1555. n,
  1556. static_cast<value_type>(z),
  1557. forwarding_policy(),
  1558. tag_type()), "boost::math::expint<%1%>(unsigned, %1%)");
  1559. }
  1560. template <class T, class U>
  1561. inline typename detail::expint_result<T, U>::type
  1562. expint(T const z, U const u)
  1563. {
  1564. typedef typename policies::is_policy<U>::type tag_type;
  1565. return detail::expint_forwarder(z, u, tag_type());
  1566. }
  1567. template <class T>
  1568. inline typename tools::promote_args<T>::type
  1569. expint(T z)
  1570. {
  1571. return expint(z, policies::policy<>());
  1572. }
  1573. }} // namespaces
  1574. #ifdef _MSC_VER
  1575. #pragma warning(pop)
  1576. #endif
  1577. #endif // BOOST_MATH_EXPINT_HPP