erf.hpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. // (C) Copyright John Maddock 2006.
  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_SPECIAL_ERF_HPP
  6. #define BOOST_MATH_SPECIAL_ERF_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/tools/config.hpp>
  12. #include <boost/math/special_functions/gamma.hpp>
  13. #include <boost/math/tools/roots.hpp>
  14. #include <boost/math/policies/error_handling.hpp>
  15. #include <boost/math/tools/big_constant.hpp>
  16. #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
  17. //
  18. // This is the only way we can avoid
  19. // warning: non-standard suffix on floating constant [-Wpedantic]
  20. // when building with -Wall -pedantic. Neither __extension__
  21. // nor #pragma diagnostic ignored work :(
  22. //
  23. #pragma GCC system_header
  24. #endif
  25. namespace boost{ namespace math{
  26. namespace detail
  27. {
  28. //
  29. // Asymptotic series for large z:
  30. //
  31. template <class T>
  32. struct erf_asympt_series_t
  33. {
  34. erf_asympt_series_t(T z) : xx(2 * -z * z), tk(1)
  35. {
  36. BOOST_MATH_STD_USING
  37. result = -exp(-z * z) / sqrt(boost::math::constants::pi<T>());
  38. result /= z;
  39. }
  40. typedef T result_type;
  41. T operator()()
  42. {
  43. BOOST_MATH_STD_USING
  44. T r = result;
  45. result *= tk / xx;
  46. tk += 2;
  47. if( fabs(r) < fabs(result))
  48. result = 0;
  49. return r;
  50. }
  51. private:
  52. T result;
  53. T xx;
  54. int tk;
  55. };
  56. //
  57. // How large z has to be in order to ensure that the series converges:
  58. //
  59. template <class T>
  60. inline float erf_asymptotic_limit_N(const T&)
  61. {
  62. return (std::numeric_limits<float>::max)();
  63. }
  64. inline float erf_asymptotic_limit_N(const std::integral_constant<int, 24>&)
  65. {
  66. return 2.8F;
  67. }
  68. inline float erf_asymptotic_limit_N(const std::integral_constant<int, 53>&)
  69. {
  70. return 4.3F;
  71. }
  72. inline float erf_asymptotic_limit_N(const std::integral_constant<int, 64>&)
  73. {
  74. return 4.8F;
  75. }
  76. inline float erf_asymptotic_limit_N(const std::integral_constant<int, 106>&)
  77. {
  78. return 6.5F;
  79. }
  80. inline float erf_asymptotic_limit_N(const std::integral_constant<int, 113>&)
  81. {
  82. return 6.8F;
  83. }
  84. template <class T, class Policy>
  85. inline T erf_asymptotic_limit()
  86. {
  87. typedef typename policies::precision<T, Policy>::type precision_type;
  88. typedef std::integral_constant<int,
  89. precision_type::value <= 0 ? 0 :
  90. precision_type::value <= 24 ? 24 :
  91. precision_type::value <= 53 ? 53 :
  92. precision_type::value <= 64 ? 64 :
  93. precision_type::value <= 113 ? 113 : 0
  94. > tag_type;
  95. return erf_asymptotic_limit_N(tag_type());
  96. }
  97. template <class T>
  98. struct erf_series_near_zero
  99. {
  100. typedef T result_type;
  101. T term;
  102. T zz;
  103. int k;
  104. erf_series_near_zero(const T& z) : term(z), zz(-z * z), k(0) {}
  105. T operator()()
  106. {
  107. T result = term / (2 * k + 1);
  108. term *= zz / ++k;
  109. return result;
  110. }
  111. };
  112. template <class T, class Policy>
  113. T erf_series_near_zero_sum(const T& x, const Policy& pol)
  114. {
  115. //
  116. // We need Kahan summation here, otherwise the errors grow fairly quickly.
  117. // This method is *much* faster than the alternatives even so.
  118. //
  119. erf_series_near_zero<T> sum(x);
  120. boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  121. T result = constants::two_div_root_pi<T>() * tools::kahan_sum_series(sum, tools::digits<T>(), max_iter);
  122. policies::check_series_iterations<T>("boost::math::erf<%1%>(%1%, %1%)", max_iter, pol);
  123. return result;
  124. }
  125. template <class T, class Policy, class Tag>
  126. T erf_imp(T z, bool invert, const Policy& pol, const Tag& t)
  127. {
  128. BOOST_MATH_STD_USING
  129. BOOST_MATH_INSTRUMENT_CODE("Generic erf_imp called");
  130. if(z < 0)
  131. {
  132. if(!invert)
  133. return -erf_imp(T(-z), invert, pol, t);
  134. else
  135. return 1 + erf_imp(T(-z), false, pol, t);
  136. }
  137. T result;
  138. if(!invert && (z > detail::erf_asymptotic_limit<T, Policy>()))
  139. {
  140. detail::erf_asympt_series_t<T> s(z);
  141. boost::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  142. result = boost::math::tools::sum_series(s, policies::get_epsilon<T, Policy>(), max_iter, 1);
  143. policies::check_series_iterations<T>("boost::math::erf<%1%>(%1%, %1%)", max_iter, pol);
  144. }
  145. else
  146. {
  147. T x = z * z;
  148. if(z < 1.3f)
  149. {
  150. // Compute P:
  151. // This is actually good for z p to 2 or so, but the cutoff given seems
  152. // to be the best compromise. Performance wise, this is way quicker than anything else...
  153. result = erf_series_near_zero_sum(z, pol);
  154. }
  155. else if(x > 1 / tools::epsilon<T>())
  156. {
  157. // http://functions.wolfram.com/06.27.06.0006.02
  158. invert = !invert;
  159. result = exp(-x) / (constants::root_pi<T>() * z);
  160. }
  161. else
  162. {
  163. // Compute Q:
  164. invert = !invert;
  165. result = z * exp(-x);
  166. result /= boost::math::constants::root_pi<T>();
  167. result *= upper_gamma_fraction(T(0.5f), x, policies::get_epsilon<T, Policy>());
  168. }
  169. }
  170. if(invert)
  171. result = 1 - result;
  172. return result;
  173. }
  174. template <class T, class Policy>
  175. T erf_imp(T z, bool invert, const Policy& pol, const std::integral_constant<int, 53>& t)
  176. {
  177. BOOST_MATH_STD_USING
  178. BOOST_MATH_INSTRUMENT_CODE("53-bit precision erf_imp called");
  179. if ((boost::math::isnan)(z))
  180. return policies::raise_denorm_error("boost::math::erf<%1%>(%1%)", "Expected a finite argument but got %1%", z, pol);
  181. if(z < 0)
  182. {
  183. if(!invert)
  184. return -erf_imp(T(-z), invert, pol, t);
  185. else if(z < -0.5)
  186. return 2 - erf_imp(T(-z), invert, pol, t);
  187. else
  188. return 1 + erf_imp(T(-z), false, pol, t);
  189. }
  190. T result;
  191. //
  192. // Big bunch of selection statements now to pick
  193. // which implementation to use,
  194. // try to put most likely options first:
  195. //
  196. if(z < 0.5)
  197. {
  198. //
  199. // We're going to calculate erf:
  200. //
  201. if(z < 1e-10)
  202. {
  203. if(z == 0)
  204. {
  205. result = T(0);
  206. }
  207. else
  208. {
  209. static const T c = BOOST_MATH_BIG_CONSTANT(T, 53, 0.003379167095512573896158903121545171688);
  210. result = static_cast<T>(z * 1.125f + z * c);
  211. }
  212. }
  213. else
  214. {
  215. // Maximum Deviation Found: 1.561e-17
  216. // Expected Error Term: 1.561e-17
  217. // Maximum Relative Change in Control Points: 1.155e-04
  218. // Max Error found at double precision = 2.961182e-17
  219. static const T Y = 1.044948577880859375f;
  220. static const T P[] = {
  221. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0834305892146531832907),
  222. BOOST_MATH_BIG_CONSTANT(T, 53, -0.338165134459360935041),
  223. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0509990735146777432841),
  224. BOOST_MATH_BIG_CONSTANT(T, 53, -0.00772758345802133288487),
  225. BOOST_MATH_BIG_CONSTANT(T, 53, -0.000322780120964605683831),
  226. };
  227. static const T Q[] = {
  228. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  229. BOOST_MATH_BIG_CONSTANT(T, 53, 0.455004033050794024546),
  230. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0875222600142252549554),
  231. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00858571925074406212772),
  232. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000370900071787748000569),
  233. };
  234. T zz = z * z;
  235. result = z * (Y + tools::evaluate_polynomial(P, zz) / tools::evaluate_polynomial(Q, zz));
  236. }
  237. }
  238. else if(invert ? (z < 28) : (z < 5.8f))
  239. {
  240. //
  241. // We'll be calculating erfc:
  242. //
  243. invert = !invert;
  244. if(z < 1.5f)
  245. {
  246. // Maximum Deviation Found: 3.702e-17
  247. // Expected Error Term: 3.702e-17
  248. // Maximum Relative Change in Control Points: 2.845e-04
  249. // Max Error found at double precision = 4.841816e-17
  250. static const T Y = 0.405935764312744140625f;
  251. static const T P[] = {
  252. BOOST_MATH_BIG_CONSTANT(T, 53, -0.098090592216281240205),
  253. BOOST_MATH_BIG_CONSTANT(T, 53, 0.178114665841120341155),
  254. BOOST_MATH_BIG_CONSTANT(T, 53, 0.191003695796775433986),
  255. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0888900368967884466578),
  256. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0195049001251218801359),
  257. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00180424538297014223957),
  258. };
  259. static const T Q[] = {
  260. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  261. BOOST_MATH_BIG_CONSTANT(T, 53, 1.84759070983002217845),
  262. BOOST_MATH_BIG_CONSTANT(T, 53, 1.42628004845511324508),
  263. BOOST_MATH_BIG_CONSTANT(T, 53, 0.578052804889902404909),
  264. BOOST_MATH_BIG_CONSTANT(T, 53, 0.12385097467900864233),
  265. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0113385233577001411017),
  266. BOOST_MATH_BIG_CONSTANT(T, 53, 0.337511472483094676155e-5),
  267. };
  268. BOOST_MATH_INSTRUMENT_VARIABLE(Y);
  269. BOOST_MATH_INSTRUMENT_VARIABLE(P[0]);
  270. BOOST_MATH_INSTRUMENT_VARIABLE(Q[0]);
  271. BOOST_MATH_INSTRUMENT_VARIABLE(z);
  272. result = Y + tools::evaluate_polynomial(P, T(z - 0.5)) / tools::evaluate_polynomial(Q, T(z - 0.5));
  273. BOOST_MATH_INSTRUMENT_VARIABLE(result);
  274. result *= exp(-z * z) / z;
  275. BOOST_MATH_INSTRUMENT_VARIABLE(result);
  276. }
  277. else if(z < 2.5f)
  278. {
  279. // Max Error found at double precision = 6.599585e-18
  280. // Maximum Deviation Found: 3.909e-18
  281. // Expected Error Term: 3.909e-18
  282. // Maximum Relative Change in Control Points: 9.886e-05
  283. static const T Y = 0.50672817230224609375f;
  284. static const T P[] = {
  285. BOOST_MATH_BIG_CONSTANT(T, 53, -0.0243500476207698441272),
  286. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0386540375035707201728),
  287. BOOST_MATH_BIG_CONSTANT(T, 53, 0.04394818964209516296),
  288. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0175679436311802092299),
  289. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00323962406290842133584),
  290. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000235839115596880717416),
  291. };
  292. static const T Q[] = {
  293. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  294. BOOST_MATH_BIG_CONSTANT(T, 53, 1.53991494948552447182),
  295. BOOST_MATH_BIG_CONSTANT(T, 53, 0.982403709157920235114),
  296. BOOST_MATH_BIG_CONSTANT(T, 53, 0.325732924782444448493),
  297. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0563921837420478160373),
  298. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00410369723978904575884),
  299. };
  300. result = Y + tools::evaluate_polynomial(P, T(z - 1.5)) / tools::evaluate_polynomial(Q, T(z - 1.5));
  301. T hi, lo;
  302. int expon;
  303. hi = floor(ldexp(frexp(z, &expon), 26));
  304. hi = ldexp(hi, expon - 26);
  305. lo = z - hi;
  306. T sq = z * z;
  307. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  308. result *= exp(-sq) * exp(-err_sqr) / z;
  309. }
  310. else if(z < 4.5f)
  311. {
  312. // Maximum Deviation Found: 1.512e-17
  313. // Expected Error Term: 1.512e-17
  314. // Maximum Relative Change in Control Points: 2.222e-04
  315. // Max Error found at double precision = 2.062515e-17
  316. static const T Y = 0.5405750274658203125f;
  317. static const T P[] = {
  318. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00295276716530971662634),
  319. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0137384425896355332126),
  320. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00840807615555585383007),
  321. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00212825620914618649141),
  322. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000250269961544794627958),
  323. BOOST_MATH_BIG_CONSTANT(T, 53, 0.113212406648847561139e-4),
  324. };
  325. static const T Q[] = {
  326. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  327. BOOST_MATH_BIG_CONSTANT(T, 53, 1.04217814166938418171),
  328. BOOST_MATH_BIG_CONSTANT(T, 53, 0.442597659481563127003),
  329. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0958492726301061423444),
  330. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0105982906484876531489),
  331. BOOST_MATH_BIG_CONSTANT(T, 53, 0.000479411269521714493907),
  332. };
  333. result = Y + tools::evaluate_polynomial(P, T(z - 3.5)) / tools::evaluate_polynomial(Q, T(z - 3.5));
  334. T hi, lo;
  335. int expon;
  336. hi = floor(ldexp(frexp(z, &expon), 26));
  337. hi = ldexp(hi, expon - 26);
  338. lo = z - hi;
  339. T sq = z * z;
  340. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  341. result *= exp(-sq) * exp(-err_sqr) / z;
  342. }
  343. else
  344. {
  345. // Max Error found at double precision = 2.997958e-17
  346. // Maximum Deviation Found: 2.860e-17
  347. // Expected Error Term: 2.859e-17
  348. // Maximum Relative Change in Control Points: 1.357e-05
  349. static const T Y = 0.5579090118408203125f;
  350. static const T P[] = {
  351. BOOST_MATH_BIG_CONSTANT(T, 53, 0.00628057170626964891937),
  352. BOOST_MATH_BIG_CONSTANT(T, 53, 0.0175389834052493308818),
  353. BOOST_MATH_BIG_CONSTANT(T, 53, -0.212652252872804219852),
  354. BOOST_MATH_BIG_CONSTANT(T, 53, -0.687717681153649930619),
  355. BOOST_MATH_BIG_CONSTANT(T, 53, -2.5518551727311523996),
  356. BOOST_MATH_BIG_CONSTANT(T, 53, -3.22729451764143718517),
  357. BOOST_MATH_BIG_CONSTANT(T, 53, -2.8175401114513378771),
  358. };
  359. static const T Q[] = {
  360. BOOST_MATH_BIG_CONSTANT(T, 53, 1.0),
  361. BOOST_MATH_BIG_CONSTANT(T, 53, 2.79257750980575282228),
  362. BOOST_MATH_BIG_CONSTANT(T, 53, 11.0567237927800161565),
  363. BOOST_MATH_BIG_CONSTANT(T, 53, 15.930646027911794143),
  364. BOOST_MATH_BIG_CONSTANT(T, 53, 22.9367376522880577224),
  365. BOOST_MATH_BIG_CONSTANT(T, 53, 13.5064170191802889145),
  366. BOOST_MATH_BIG_CONSTANT(T, 53, 5.48409182238641741584),
  367. };
  368. result = Y + tools::evaluate_polynomial(P, T(1 / z)) / tools::evaluate_polynomial(Q, T(1 / z));
  369. T hi, lo;
  370. int expon;
  371. hi = floor(ldexp(frexp(z, &expon), 26));
  372. hi = ldexp(hi, expon - 26);
  373. lo = z - hi;
  374. T sq = z * z;
  375. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  376. result *= exp(-sq) * exp(-err_sqr) / z;
  377. }
  378. }
  379. else
  380. {
  381. //
  382. // Any value of z larger than 28 will underflow to zero:
  383. //
  384. result = 0;
  385. invert = !invert;
  386. }
  387. if(invert)
  388. {
  389. result = 1 - result;
  390. }
  391. return result;
  392. } // template <class T, class Lanczos>T erf_imp(T z, bool invert, const Lanczos& l, const std::integral_constant<int, 53>& t)
  393. template <class T, class Policy>
  394. T erf_imp(T z, bool invert, const Policy& pol, const std::integral_constant<int, 64>& t)
  395. {
  396. BOOST_MATH_STD_USING
  397. BOOST_MATH_INSTRUMENT_CODE("64-bit precision erf_imp called");
  398. if(z < 0)
  399. {
  400. if(!invert)
  401. return -erf_imp(T(-z), invert, pol, t);
  402. else if(z < -0.5)
  403. return 2 - erf_imp(T(-z), invert, pol, t);
  404. else
  405. return 1 + erf_imp(T(-z), false, pol, t);
  406. }
  407. T result;
  408. //
  409. // Big bunch of selection statements now to pick which
  410. // implementation to use, try to put most likely options
  411. // first:
  412. //
  413. if(z < 0.5)
  414. {
  415. //
  416. // We're going to calculate erf:
  417. //
  418. if(z == 0)
  419. {
  420. result = 0;
  421. }
  422. else if(z < 1e-10)
  423. {
  424. static const T c = BOOST_MATH_BIG_CONSTANT(T, 64, 0.003379167095512573896158903121545171688);
  425. result = z * 1.125 + z * c;
  426. }
  427. else
  428. {
  429. // Max Error found at long double precision = 1.623299e-20
  430. // Maximum Deviation Found: 4.326e-22
  431. // Expected Error Term: -4.326e-22
  432. // Maximum Relative Change in Control Points: 1.474e-04
  433. static const T Y = 1.044948577880859375f;
  434. static const T P[] = {
  435. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0834305892146531988966),
  436. BOOST_MATH_BIG_CONSTANT(T, 64, -0.338097283075565413695),
  437. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0509602734406067204596),
  438. BOOST_MATH_BIG_CONSTANT(T, 64, -0.00904906346158537794396),
  439. BOOST_MATH_BIG_CONSTANT(T, 64, -0.000489468651464798669181),
  440. BOOST_MATH_BIG_CONSTANT(T, 64, -0.200305626366151877759e-4),
  441. };
  442. static const T Q[] = {
  443. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  444. BOOST_MATH_BIG_CONSTANT(T, 64, 0.455817300515875172439),
  445. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0916537354356241792007),
  446. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0102722652675910031202),
  447. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000650511752687851548735),
  448. BOOST_MATH_BIG_CONSTANT(T, 64, 0.189532519105655496778e-4),
  449. };
  450. result = z * (Y + tools::evaluate_polynomial(P, T(z * z)) / tools::evaluate_polynomial(Q, T(z * z)));
  451. }
  452. }
  453. else if(invert ? (z < 110) : (z < 6.4f))
  454. {
  455. //
  456. // We'll be calculating erfc:
  457. //
  458. invert = !invert;
  459. if(z < 1.5)
  460. {
  461. // Max Error found at long double precision = 3.239590e-20
  462. // Maximum Deviation Found: 2.241e-20
  463. // Expected Error Term: -2.241e-20
  464. // Maximum Relative Change in Control Points: 5.110e-03
  465. static const T Y = 0.405935764312744140625f;
  466. static const T P[] = {
  467. BOOST_MATH_BIG_CONSTANT(T, 64, -0.0980905922162812031672),
  468. BOOST_MATH_BIG_CONSTANT(T, 64, 0.159989089922969141329),
  469. BOOST_MATH_BIG_CONSTANT(T, 64, 0.222359821619935712378),
  470. BOOST_MATH_BIG_CONSTANT(T, 64, 0.127303921703577362312),
  471. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0384057530342762400273),
  472. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00628431160851156719325),
  473. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000441266654514391746428),
  474. BOOST_MATH_BIG_CONSTANT(T, 64, 0.266689068336295642561e-7),
  475. };
  476. static const T Q[] = {
  477. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  478. BOOST_MATH_BIG_CONSTANT(T, 64, 2.03237474985469469291),
  479. BOOST_MATH_BIG_CONSTANT(T, 64, 1.78355454954969405222),
  480. BOOST_MATH_BIG_CONSTANT(T, 64, 0.867940326293760578231),
  481. BOOST_MATH_BIG_CONSTANT(T, 64, 0.248025606990021698392),
  482. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0396649631833002269861),
  483. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00279220237309449026796),
  484. };
  485. result = Y + tools::evaluate_polynomial(P, T(z - 0.5f)) / tools::evaluate_polynomial(Q, T(z - 0.5f));
  486. T hi, lo;
  487. int expon;
  488. hi = floor(ldexp(frexp(z, &expon), 32));
  489. hi = ldexp(hi, expon - 32);
  490. lo = z - hi;
  491. T sq = z * z;
  492. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  493. result *= exp(-sq) * exp(-err_sqr) / z;
  494. }
  495. else if(z < 2.5)
  496. {
  497. // Max Error found at long double precision = 3.686211e-21
  498. // Maximum Deviation Found: 1.495e-21
  499. // Expected Error Term: -1.494e-21
  500. // Maximum Relative Change in Control Points: 1.793e-04
  501. static const T Y = 0.50672817230224609375f;
  502. static const T P[] = {
  503. BOOST_MATH_BIG_CONSTANT(T, 64, -0.024350047620769840217),
  504. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0343522687935671451309),
  505. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0505420824305544949541),
  506. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0257479325917757388209),
  507. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00669349844190354356118),
  508. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00090807914416099524444),
  509. BOOST_MATH_BIG_CONSTANT(T, 64, 0.515917266698050027934e-4),
  510. };
  511. static const T Q[] = {
  512. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  513. BOOST_MATH_BIG_CONSTANT(T, 64, 1.71657861671930336344),
  514. BOOST_MATH_BIG_CONSTANT(T, 64, 1.26409634824280366218),
  515. BOOST_MATH_BIG_CONSTANT(T, 64, 0.512371437838969015941),
  516. BOOST_MATH_BIG_CONSTANT(T, 64, 0.120902623051120950935),
  517. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0158027197831887485261),
  518. BOOST_MATH_BIG_CONSTANT(T, 64, 0.000897871370778031611439),
  519. };
  520. result = Y + tools::evaluate_polynomial(P, T(z - 1.5f)) / tools::evaluate_polynomial(Q, T(z - 1.5f));
  521. T hi, lo;
  522. int expon;
  523. hi = floor(ldexp(frexp(z, &expon), 32));
  524. hi = ldexp(hi, expon - 32);
  525. lo = z - hi;
  526. T sq = z * z;
  527. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  528. result *= exp(-sq) * exp(-err_sqr) / z;
  529. }
  530. else if(z < 4.5)
  531. {
  532. // Maximum Deviation Found: 1.107e-20
  533. // Expected Error Term: -1.106e-20
  534. // Maximum Relative Change in Control Points: 1.709e-04
  535. // Max Error found at long double precision = 1.446908e-20
  536. static const T Y = 0.5405750274658203125f;
  537. static const T P[] = {
  538. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0029527671653097284033),
  539. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0141853245895495604051),
  540. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0104959584626432293901),
  541. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00343963795976100077626),
  542. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00059065441194877637899),
  543. BOOST_MATH_BIG_CONSTANT(T, 64, 0.523435380636174008685e-4),
  544. BOOST_MATH_BIG_CONSTANT(T, 64, 0.189896043050331257262e-5),
  545. };
  546. static const T Q[] = {
  547. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  548. BOOST_MATH_BIG_CONSTANT(T, 64, 1.19352160185285642574),
  549. BOOST_MATH_BIG_CONSTANT(T, 64, 0.603256964363454392857),
  550. BOOST_MATH_BIG_CONSTANT(T, 64, 0.165411142458540585835),
  551. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0259729870946203166468),
  552. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00221657568292893699158),
  553. BOOST_MATH_BIG_CONSTANT(T, 64, 0.804149464190309799804e-4),
  554. };
  555. result = Y + tools::evaluate_polynomial(P, T(z - 3.5f)) / tools::evaluate_polynomial(Q, T(z - 3.5f));
  556. T hi, lo;
  557. int expon;
  558. hi = floor(ldexp(frexp(z, &expon), 32));
  559. hi = ldexp(hi, expon - 32);
  560. lo = z - hi;
  561. T sq = z * z;
  562. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  563. result *= exp(-sq) * exp(-err_sqr) / z;
  564. }
  565. else
  566. {
  567. // Max Error found at long double precision = 7.961166e-21
  568. // Maximum Deviation Found: 6.677e-21
  569. // Expected Error Term: 6.676e-21
  570. // Maximum Relative Change in Control Points: 2.319e-05
  571. static const T Y = 0.55825519561767578125f;
  572. static const T P[] = {
  573. BOOST_MATH_BIG_CONSTANT(T, 64, 0.00593438793008050214106),
  574. BOOST_MATH_BIG_CONSTANT(T, 64, 0.0280666231009089713937),
  575. BOOST_MATH_BIG_CONSTANT(T, 64, -0.141597835204583050043),
  576. BOOST_MATH_BIG_CONSTANT(T, 64, -0.978088201154300548842),
  577. BOOST_MATH_BIG_CONSTANT(T, 64, -5.47351527796012049443),
  578. BOOST_MATH_BIG_CONSTANT(T, 64, -13.8677304660245326627),
  579. BOOST_MATH_BIG_CONSTANT(T, 64, -27.1274948720539821722),
  580. BOOST_MATH_BIG_CONSTANT(T, 64, -29.2545152747009461519),
  581. BOOST_MATH_BIG_CONSTANT(T, 64, -16.8865774499799676937),
  582. };
  583. static const T Q[] = {
  584. BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
  585. BOOST_MATH_BIG_CONSTANT(T, 64, 4.72948911186645394541),
  586. BOOST_MATH_BIG_CONSTANT(T, 64, 23.6750543147695749212),
  587. BOOST_MATH_BIG_CONSTANT(T, 64, 60.0021517335693186785),
  588. BOOST_MATH_BIG_CONSTANT(T, 64, 131.766251645149522868),
  589. BOOST_MATH_BIG_CONSTANT(T, 64, 178.167924971283482513),
  590. BOOST_MATH_BIG_CONSTANT(T, 64, 182.499390505915222699),
  591. BOOST_MATH_BIG_CONSTANT(T, 64, 104.365251479578577989),
  592. BOOST_MATH_BIG_CONSTANT(T, 64, 30.8365511891224291717),
  593. };
  594. result = Y + tools::evaluate_polynomial(P, T(1 / z)) / tools::evaluate_polynomial(Q, T(1 / z));
  595. T hi, lo;
  596. int expon;
  597. hi = floor(ldexp(frexp(z, &expon), 32));
  598. hi = ldexp(hi, expon - 32);
  599. lo = z - hi;
  600. T sq = z * z;
  601. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  602. result *= exp(-sq) * exp(-err_sqr) / z;
  603. }
  604. }
  605. else
  606. {
  607. //
  608. // Any value of z larger than 110 will underflow to zero:
  609. //
  610. result = 0;
  611. invert = !invert;
  612. }
  613. if(invert)
  614. {
  615. result = 1 - result;
  616. }
  617. return result;
  618. } // template <class T, class Lanczos>T erf_imp(T z, bool invert, const Lanczos& l, const std::integral_constant<int, 64>& t)
  619. template <class T, class Policy>
  620. T erf_imp(T z, bool invert, const Policy& pol, const std::integral_constant<int, 113>& t)
  621. {
  622. BOOST_MATH_STD_USING
  623. BOOST_MATH_INSTRUMENT_CODE("113-bit precision erf_imp called");
  624. if(z < 0)
  625. {
  626. if(!invert)
  627. return -erf_imp(T(-z), invert, pol, t);
  628. else if(z < -0.5)
  629. return 2 - erf_imp(T(-z), invert, pol, t);
  630. else
  631. return 1 + erf_imp(T(-z), false, pol, t);
  632. }
  633. T result;
  634. //
  635. // Big bunch of selection statements now to pick which
  636. // implementation to use, try to put most likely options
  637. // first:
  638. //
  639. if(z < 0.5)
  640. {
  641. //
  642. // We're going to calculate erf:
  643. //
  644. if(z == 0)
  645. {
  646. result = 0;
  647. }
  648. else if(z < 1e-20)
  649. {
  650. static const T c = BOOST_MATH_BIG_CONSTANT(T, 113, 0.003379167095512573896158903121545171688);
  651. result = z * 1.125 + z * c;
  652. }
  653. else
  654. {
  655. // Max Error found at long double precision = 2.342380e-35
  656. // Maximum Deviation Found: 6.124e-36
  657. // Expected Error Term: -6.124e-36
  658. // Maximum Relative Change in Control Points: 3.492e-10
  659. static const T Y = 1.0841522216796875f;
  660. static const T P[] = {
  661. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0442269454158250738961589031215451778),
  662. BOOST_MATH_BIG_CONSTANT(T, 113, -0.35549265736002144875335323556961233),
  663. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0582179564566667896225454670863270393),
  664. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0112694696904802304229950538453123925),
  665. BOOST_MATH_BIG_CONSTANT(T, 113, -0.000805730648981801146251825329609079099),
  666. BOOST_MATH_BIG_CONSTANT(T, 113, -0.566304966591936566229702842075966273e-4),
  667. BOOST_MATH_BIG_CONSTANT(T, 113, -0.169655010425186987820201021510002265e-5),
  668. BOOST_MATH_BIG_CONSTANT(T, 113, -0.344448249920445916714548295433198544e-7),
  669. };
  670. static const T Q[] = {
  671. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  672. BOOST_MATH_BIG_CONSTANT(T, 113, 0.466542092785657604666906909196052522),
  673. BOOST_MATH_BIG_CONSTANT(T, 113, 0.100005087012526447295176964142107611),
  674. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0128341535890117646540050072234142603),
  675. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00107150448466867929159660677016658186),
  676. BOOST_MATH_BIG_CONSTANT(T, 113, 0.586168368028999183607733369248338474e-4),
  677. BOOST_MATH_BIG_CONSTANT(T, 113, 0.196230608502104324965623171516808796e-5),
  678. BOOST_MATH_BIG_CONSTANT(T, 113, 0.313388521582925207734229967907890146e-7),
  679. };
  680. result = z * (Y + tools::evaluate_polynomial(P, T(z * z)) / tools::evaluate_polynomial(Q, T(z * z)));
  681. }
  682. }
  683. else if(invert ? (z < 110) : (z < 8.65f))
  684. {
  685. //
  686. // We'll be calculating erfc:
  687. //
  688. invert = !invert;
  689. if(z < 1)
  690. {
  691. // Max Error found at long double precision = 3.246278e-35
  692. // Maximum Deviation Found: 1.388e-35
  693. // Expected Error Term: 1.387e-35
  694. // Maximum Relative Change in Control Points: 6.127e-05
  695. static const T Y = 0.371877193450927734375f;
  696. static const T P[] = {
  697. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0640320213544647969396032886581290455),
  698. BOOST_MATH_BIG_CONSTANT(T, 113, 0.200769874440155895637857443946706731),
  699. BOOST_MATH_BIG_CONSTANT(T, 113, 0.378447199873537170666487408805779826),
  700. BOOST_MATH_BIG_CONSTANT(T, 113, 0.30521399466465939450398642044975127),
  701. BOOST_MATH_BIG_CONSTANT(T, 113, 0.146890026406815277906781824723458196),
  702. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0464837937749539978247589252732769567),
  703. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00987895759019540115099100165904822903),
  704. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00137507575429025512038051025154301132),
  705. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0001144764551085935580772512359680516),
  706. BOOST_MATH_BIG_CONSTANT(T, 113, 0.436544865032836914773944382339900079e-5),
  707. };
  708. static const T Q[] = {
  709. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  710. BOOST_MATH_BIG_CONSTANT(T, 113, 2.47651182872457465043733800302427977),
  711. BOOST_MATH_BIG_CONSTANT(T, 113, 2.78706486002517996428836400245547955),
  712. BOOST_MATH_BIG_CONSTANT(T, 113, 1.87295924621659627926365005293130693),
  713. BOOST_MATH_BIG_CONSTANT(T, 113, 0.829375825174365625428280908787261065),
  714. BOOST_MATH_BIG_CONSTANT(T, 113, 0.251334771307848291593780143950311514),
  715. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0522110268876176186719436765734722473),
  716. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00718332151250963182233267040106902368),
  717. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000595279058621482041084986219276392459),
  718. BOOST_MATH_BIG_CONSTANT(T, 113, 0.226988669466501655990637599399326874e-4),
  719. BOOST_MATH_BIG_CONSTANT(T, 113, 0.270666232259029102353426738909226413e-10),
  720. };
  721. result = Y + tools::evaluate_polynomial(P, T(z - 0.5f)) / tools::evaluate_polynomial(Q, T(z - 0.5f));
  722. T hi, lo;
  723. int expon;
  724. hi = floor(ldexp(frexp(z, &expon), 56));
  725. hi = ldexp(hi, expon - 56);
  726. lo = z - hi;
  727. T sq = z * z;
  728. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  729. result *= exp(-sq) * exp(-err_sqr) / z;
  730. }
  731. else if(z < 1.5)
  732. {
  733. // Max Error found at long double precision = 2.215785e-35
  734. // Maximum Deviation Found: 1.539e-35
  735. // Expected Error Term: 1.538e-35
  736. // Maximum Relative Change in Control Points: 6.104e-05
  737. static const T Y = 0.45658016204833984375f;
  738. static const T P[] = {
  739. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0289965858925328393392496555094848345),
  740. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0868181194868601184627743162571779226),
  741. BOOST_MATH_BIG_CONSTANT(T, 113, 0.169373435121178901746317404936356745),
  742. BOOST_MATH_BIG_CONSTANT(T, 113, 0.13350446515949251201104889028133486),
  743. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0617447837290183627136837688446313313),
  744. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0185618495228251406703152962489700468),
  745. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00371949406491883508764162050169531013),
  746. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000485121708792921297742105775823900772),
  747. BOOST_MATH_BIG_CONSTANT(T, 113, 0.376494706741453489892108068231400061e-4),
  748. BOOST_MATH_BIG_CONSTANT(T, 113, 0.133166058052466262415271732172490045e-5),
  749. };
  750. static const T Q[] = {
  751. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  752. BOOST_MATH_BIG_CONSTANT(T, 113, 2.32970330146503867261275580968135126),
  753. BOOST_MATH_BIG_CONSTANT(T, 113, 2.46325715420422771961250513514928746),
  754. BOOST_MATH_BIG_CONSTANT(T, 113, 1.55307882560757679068505047390857842),
  755. BOOST_MATH_BIG_CONSTANT(T, 113, 0.644274289865972449441174485441409076),
  756. BOOST_MATH_BIG_CONSTANT(T, 113, 0.182609091063258208068606847453955649),
  757. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0354171651271241474946129665801606795),
  758. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00454060370165285246451879969534083997),
  759. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000349871943711566546821198612518656486),
  760. BOOST_MATH_BIG_CONSTANT(T, 113, 0.123749319840299552925421880481085392e-4),
  761. };
  762. result = Y + tools::evaluate_polynomial(P, T(z - 1.0f)) / tools::evaluate_polynomial(Q, T(z - 1.0f));
  763. T hi, lo;
  764. int expon;
  765. hi = floor(ldexp(frexp(z, &expon), 56));
  766. hi = ldexp(hi, expon - 56);
  767. lo = z - hi;
  768. T sq = z * z;
  769. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  770. result *= exp(-sq) * exp(-err_sqr) / z;
  771. }
  772. else if(z < 2.25)
  773. {
  774. // Maximum Deviation Found: 1.418e-35
  775. // Expected Error Term: 1.418e-35
  776. // Maximum Relative Change in Control Points: 1.316e-04
  777. // Max Error found at long double precision = 1.998462e-35
  778. static const T Y = 0.50250148773193359375f;
  779. static const T P[] = {
  780. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0201233630504573402185161184151016606),
  781. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0331864357574860196516686996302305002),
  782. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0716562720864787193337475444413405461),
  783. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0545835322082103985114927569724880658),
  784. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0236692635189696678976549720784989593),
  785. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00656970902163248872837262539337601845),
  786. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00120282643299089441390490459256235021),
  787. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000142123229065182650020762792081622986),
  788. BOOST_MATH_BIG_CONSTANT(T, 113, 0.991531438367015135346716277792989347e-5),
  789. BOOST_MATH_BIG_CONSTANT(T, 113, 0.312857043762117596999398067153076051e-6),
  790. };
  791. static const T Q[] = {
  792. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  793. BOOST_MATH_BIG_CONSTANT(T, 113, 2.13506082409097783827103424943508554),
  794. BOOST_MATH_BIG_CONSTANT(T, 113, 2.06399257267556230937723190496806215),
  795. BOOST_MATH_BIG_CONSTANT(T, 113, 1.18678481279932541314830499880691109),
  796. BOOST_MATH_BIG_CONSTANT(T, 113, 0.447733186643051752513538142316799562),
  797. BOOST_MATH_BIG_CONSTANT(T, 113, 0.11505680005657879437196953047542148),
  798. BOOST_MATH_BIG_CONSTANT(T, 113, 0.020163993632192726170219663831914034),
  799. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00232708971840141388847728782209730585),
  800. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000160733201627963528519726484608224112),
  801. BOOST_MATH_BIG_CONSTANT(T, 113, 0.507158721790721802724402992033269266e-5),
  802. BOOST_MATH_BIG_CONSTANT(T, 113, 0.18647774409821470950544212696270639e-12),
  803. };
  804. result = Y + tools::evaluate_polynomial(P, T(z - 1.5f)) / tools::evaluate_polynomial(Q, T(z - 1.5f));
  805. T hi, lo;
  806. int expon;
  807. hi = floor(ldexp(frexp(z, &expon), 56));
  808. hi = ldexp(hi, expon - 56);
  809. lo = z - hi;
  810. T sq = z * z;
  811. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  812. result *= exp(-sq) * exp(-err_sqr) / z;
  813. }
  814. else if (z < 3)
  815. {
  816. // Maximum Deviation Found: 3.575e-36
  817. // Expected Error Term: 3.575e-36
  818. // Maximum Relative Change in Control Points: 7.103e-05
  819. // Max Error found at long double precision = 5.794737e-36
  820. static const T Y = 0.52896785736083984375f;
  821. static const T P[] = {
  822. BOOST_MATH_BIG_CONSTANT(T, 113, -0.00902152521745813634562524098263360074),
  823. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0145207142776691539346923710537580927),
  824. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0301681239582193983824211995978678571),
  825. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0215548540823305814379020678660434461),
  826. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00864683476267958365678294164340749949),
  827. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00219693096885585491739823283511049902),
  828. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000364961639163319762492184502159894371),
  829. BOOST_MATH_BIG_CONSTANT(T, 113, 0.388174251026723752769264051548703059e-4),
  830. BOOST_MATH_BIG_CONSTANT(T, 113, 0.241918026931789436000532513553594321e-5),
  831. BOOST_MATH_BIG_CONSTANT(T, 113, 0.676586625472423508158937481943649258e-7),
  832. };
  833. static const T Q[] = {
  834. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  835. BOOST_MATH_BIG_CONSTANT(T, 113, 1.93669171363907292305550231764920001),
  836. BOOST_MATH_BIG_CONSTANT(T, 113, 1.69468476144051356810672506101377494),
  837. BOOST_MATH_BIG_CONSTANT(T, 113, 0.880023580986436640372794392579985511),
  838. BOOST_MATH_BIG_CONSTANT(T, 113, 0.299099106711315090710836273697708402),
  839. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0690593962363545715997445583603382337),
  840. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0108427016361318921960863149875360222),
  841. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00111747247208044534520499324234317695),
  842. BOOST_MATH_BIG_CONSTANT(T, 113, 0.686843205749767250666787987163701209e-4),
  843. BOOST_MATH_BIG_CONSTANT(T, 113, 0.192093541425429248675532015101904262e-5),
  844. };
  845. result = Y + tools::evaluate_polynomial(P, T(z - 2.25f)) / tools::evaluate_polynomial(Q, T(z - 2.25f));
  846. T hi, lo;
  847. int expon;
  848. hi = floor(ldexp(frexp(z, &expon), 56));
  849. hi = ldexp(hi, expon - 56);
  850. lo = z - hi;
  851. T sq = z * z;
  852. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  853. result *= exp(-sq) * exp(-err_sqr) / z;
  854. }
  855. else if(z < 3.5)
  856. {
  857. // Maximum Deviation Found: 8.126e-37
  858. // Expected Error Term: -8.126e-37
  859. // Maximum Relative Change in Control Points: 1.363e-04
  860. // Max Error found at long double precision = 1.747062e-36
  861. static const T Y = 0.54037380218505859375f;
  862. static const T P[] = {
  863. BOOST_MATH_BIG_CONSTANT(T, 113, -0.0033703486408887424921155540591370375),
  864. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0104948043110005245215286678898115811),
  865. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0148530118504000311502310457390417795),
  866. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00816693029245443090102738825536188916),
  867. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00249716579989140882491939681805594585),
  868. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0004655591010047353023978045800916647),
  869. BOOST_MATH_BIG_CONSTANT(T, 113, 0.531129557920045295895085236636025323e-4),
  870. BOOST_MATH_BIG_CONSTANT(T, 113, 0.343526765122727069515775194111741049e-5),
  871. BOOST_MATH_BIG_CONSTANT(T, 113, 0.971120407556888763695313774578711839e-7),
  872. };
  873. static const T Q[] = {
  874. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  875. BOOST_MATH_BIG_CONSTANT(T, 113, 1.59911256167540354915906501335919317),
  876. BOOST_MATH_BIG_CONSTANT(T, 113, 1.136006830764025173864831382946934),
  877. BOOST_MATH_BIG_CONSTANT(T, 113, 0.468565867990030871678574840738423023),
  878. BOOST_MATH_BIG_CONSTANT(T, 113, 0.122821824954470343413956476900662236),
  879. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0209670914950115943338996513330141633),
  880. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00227845718243186165620199012883547257),
  881. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000144243326443913171313947613547085553),
  882. BOOST_MATH_BIG_CONSTANT(T, 113, 0.407763415954267700941230249989140046e-5),
  883. };
  884. result = Y + tools::evaluate_polynomial(P, T(z - 3.0f)) / tools::evaluate_polynomial(Q, T(z - 3.0f));
  885. T hi, lo;
  886. int expon;
  887. hi = floor(ldexp(frexp(z, &expon), 56));
  888. hi = ldexp(hi, expon - 56);
  889. lo = z - hi;
  890. T sq = z * z;
  891. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  892. result *= exp(-sq) * exp(-err_sqr) / z;
  893. }
  894. else if(z < 5.5)
  895. {
  896. // Maximum Deviation Found: 5.804e-36
  897. // Expected Error Term: -5.803e-36
  898. // Maximum Relative Change in Control Points: 2.475e-05
  899. // Max Error found at long double precision = 1.349545e-35
  900. static const T Y = 0.55000019073486328125f;
  901. static const T P[] = {
  902. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00118142849742309772151454518093813615),
  903. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0072201822885703318172366893469382745),
  904. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0078782276276860110721875733778481505),
  905. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00418229166204362376187593976656261146),
  906. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00134198400587769200074194304298642705),
  907. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000283210387078004063264777611497435572),
  908. BOOST_MATH_BIG_CONSTANT(T, 113, 0.405687064094911866569295610914844928e-4),
  909. BOOST_MATH_BIG_CONSTANT(T, 113, 0.39348283801568113807887364414008292e-5),
  910. BOOST_MATH_BIG_CONSTANT(T, 113, 0.248798540917787001526976889284624449e-6),
  911. BOOST_MATH_BIG_CONSTANT(T, 113, 0.929502490223452372919607105387474751e-8),
  912. BOOST_MATH_BIG_CONSTANT(T, 113, 0.156161469668275442569286723236274457e-9),
  913. };
  914. static const T Q[] = {
  915. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  916. BOOST_MATH_BIG_CONSTANT(T, 113, 1.52955245103668419479878456656709381),
  917. BOOST_MATH_BIG_CONSTANT(T, 113, 1.06263944820093830054635017117417064),
  918. BOOST_MATH_BIG_CONSTANT(T, 113, 0.441684612681607364321013134378316463),
  919. BOOST_MATH_BIG_CONSTANT(T, 113, 0.121665258426166960049773715928906382),
  920. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0232134512374747691424978642874321434),
  921. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00310778180686296328582860464875562636),
  922. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000288361770756174705123674838640161693),
  923. BOOST_MATH_BIG_CONSTANT(T, 113, 0.177529187194133944622193191942300132e-4),
  924. BOOST_MATH_BIG_CONSTANT(T, 113, 0.655068544833064069223029299070876623e-6),
  925. BOOST_MATH_BIG_CONSTANT(T, 113, 0.11005507545746069573608988651927452e-7),
  926. };
  927. result = Y + tools::evaluate_polynomial(P, T(z - 4.5f)) / tools::evaluate_polynomial(Q, T(z - 4.5f));
  928. T hi, lo;
  929. int expon;
  930. hi = floor(ldexp(frexp(z, &expon), 56));
  931. hi = ldexp(hi, expon - 56);
  932. lo = z - hi;
  933. T sq = z * z;
  934. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  935. result *= exp(-sq) * exp(-err_sqr) / z;
  936. }
  937. else if(z < 7.5)
  938. {
  939. // Maximum Deviation Found: 1.007e-36
  940. // Expected Error Term: 1.007e-36
  941. // Maximum Relative Change in Control Points: 1.027e-03
  942. // Max Error found at long double precision = 2.646420e-36
  943. static const T Y = 0.5574436187744140625f;
  944. static const T P[] = {
  945. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000293236907400849056269309713064107674),
  946. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00225110719535060642692275221961480162),
  947. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00190984458121502831421717207849429799),
  948. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000747757733460111743833929141001680706),
  949. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000170663175280949889583158597373928096),
  950. BOOST_MATH_BIG_CONSTANT(T, 113, 0.246441188958013822253071608197514058e-4),
  951. BOOST_MATH_BIG_CONSTANT(T, 113, 0.229818000860544644974205957895688106e-5),
  952. BOOST_MATH_BIG_CONSTANT(T, 113, 0.134886977703388748488480980637704864e-6),
  953. BOOST_MATH_BIG_CONSTANT(T, 113, 0.454764611880548962757125070106650958e-8),
  954. BOOST_MATH_BIG_CONSTANT(T, 113, 0.673002744115866600294723141176820155e-10),
  955. };
  956. static const T Q[] = {
  957. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  958. BOOST_MATH_BIG_CONSTANT(T, 113, 1.12843690320861239631195353379313367),
  959. BOOST_MATH_BIG_CONSTANT(T, 113, 0.569900657061622955362493442186537259),
  960. BOOST_MATH_BIG_CONSTANT(T, 113, 0.169094404206844928112348730277514273),
  961. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0324887449084220415058158657252147063),
  962. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00419252877436825753042680842608219552),
  963. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00036344133176118603523976748563178578),
  964. BOOST_MATH_BIG_CONSTANT(T, 113, 0.204123895931375107397698245752850347e-4),
  965. BOOST_MATH_BIG_CONSTANT(T, 113, 0.674128352521481412232785122943508729e-6),
  966. BOOST_MATH_BIG_CONSTANT(T, 113, 0.997637501418963696542159244436245077e-8),
  967. };
  968. result = Y + tools::evaluate_polynomial(P, T(z - 6.5f)) / tools::evaluate_polynomial(Q, T(z - 6.5f));
  969. T hi, lo;
  970. int expon;
  971. hi = floor(ldexp(frexp(z, &expon), 56));
  972. hi = ldexp(hi, expon - 56);
  973. lo = z - hi;
  974. T sq = z * z;
  975. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  976. result *= exp(-sq) * exp(-err_sqr) / z;
  977. }
  978. else if(z < 11.5)
  979. {
  980. // Maximum Deviation Found: 8.380e-36
  981. // Expected Error Term: 8.380e-36
  982. // Maximum Relative Change in Control Points: 2.632e-06
  983. // Max Error found at long double precision = 9.849522e-36
  984. static const T Y = 0.56083202362060546875f;
  985. static const T P[] = {
  986. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000282420728751494363613829834891390121),
  987. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00175387065018002823433704079355125161),
  988. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0021344978564889819420775336322920375),
  989. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00124151356560137532655039683963075661),
  990. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000423600733566948018555157026862139644),
  991. BOOST_MATH_BIG_CONSTANT(T, 113, 0.914030340865175237133613697319509698e-4),
  992. BOOST_MATH_BIG_CONSTANT(T, 113, 0.126999927156823363353809747017945494e-4),
  993. BOOST_MATH_BIG_CONSTANT(T, 113, 0.110610959842869849776179749369376402e-5),
  994. BOOST_MATH_BIG_CONSTANT(T, 113, 0.55075079477173482096725348704634529e-7),
  995. BOOST_MATH_BIG_CONSTANT(T, 113, 0.119735694018906705225870691331543806e-8),
  996. };
  997. static const T Q[] = {
  998. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  999. BOOST_MATH_BIG_CONSTANT(T, 113, 1.69889613396167354566098060039549882),
  1000. BOOST_MATH_BIG_CONSTANT(T, 113, 1.28824647372749624464956031163282674),
  1001. BOOST_MATH_BIG_CONSTANT(T, 113, 0.572297795434934493541628008224078717),
  1002. BOOST_MATH_BIG_CONSTANT(T, 113, 0.164157697425571712377043857240773164),
  1003. BOOST_MATH_BIG_CONSTANT(T, 113, 0.0315311145224594430281219516531649562),
  1004. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00405588922155632380812945849777127458),
  1005. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000336929033691445666232029762868642417),
  1006. BOOST_MATH_BIG_CONSTANT(T, 113, 0.164033049810404773469413526427932109e-4),
  1007. BOOST_MATH_BIG_CONSTANT(T, 113, 0.356615210500531410114914617294694857e-6),
  1008. };
  1009. result = Y + tools::evaluate_polynomial(P, T(z / 2 - 4.75f)) / tools::evaluate_polynomial(Q, T(z / 2 - 4.75f));
  1010. T hi, lo;
  1011. int expon;
  1012. hi = floor(ldexp(frexp(z, &expon), 56));
  1013. hi = ldexp(hi, expon - 56);
  1014. lo = z - hi;
  1015. T sq = z * z;
  1016. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  1017. result *= exp(-sq) * exp(-err_sqr) / z;
  1018. }
  1019. else
  1020. {
  1021. // Maximum Deviation Found: 1.132e-35
  1022. // Expected Error Term: -1.132e-35
  1023. // Maximum Relative Change in Control Points: 4.674e-04
  1024. // Max Error found at long double precision = 1.162590e-35
  1025. static const T Y = 0.5632686614990234375f;
  1026. static const T P[] = {
  1027. BOOST_MATH_BIG_CONSTANT(T, 113, 0.000920922048732849448079451574171836943),
  1028. BOOST_MATH_BIG_CONSTANT(T, 113, 0.00321439044532288750501700028748922439),
  1029. BOOST_MATH_BIG_CONSTANT(T, 113, -0.250455263029390118657884864261823431),
  1030. BOOST_MATH_BIG_CONSTANT(T, 113, -0.906807635364090342031792404764598142),
  1031. BOOST_MATH_BIG_CONSTANT(T, 113, -8.92233572835991735876688745989985565),
  1032. BOOST_MATH_BIG_CONSTANT(T, 113, -21.7797433494422564811782116907878495),
  1033. BOOST_MATH_BIG_CONSTANT(T, 113, -91.1451915251976354349734589601171659),
  1034. BOOST_MATH_BIG_CONSTANT(T, 113, -144.1279109655993927069052125017673),
  1035. BOOST_MATH_BIG_CONSTANT(T, 113, -313.845076581796338665519022313775589),
  1036. BOOST_MATH_BIG_CONSTANT(T, 113, -273.11378811923343424081101235736475),
  1037. BOOST_MATH_BIG_CONSTANT(T, 113, -271.651566205951067025696102600443452),
  1038. BOOST_MATH_BIG_CONSTANT(T, 113, -60.0530577077238079968843307523245547),
  1039. };
  1040. static const T Q[] = {
  1041. BOOST_MATH_BIG_CONSTANT(T, 113, 1.0),
  1042. BOOST_MATH_BIG_CONSTANT(T, 113, 3.49040448075464744191022350947892036),
  1043. BOOST_MATH_BIG_CONSTANT(T, 113, 34.3563592467165971295915749548313227),
  1044. BOOST_MATH_BIG_CONSTANT(T, 113, 84.4993232033879023178285731843850461),
  1045. BOOST_MATH_BIG_CONSTANT(T, 113, 376.005865281206894120659401340373818),
  1046. BOOST_MATH_BIG_CONSTANT(T, 113, 629.95369438888946233003926191755125),
  1047. BOOST_MATH_BIG_CONSTANT(T, 113, 1568.35771983533158591604513304269098),
  1048. BOOST_MATH_BIG_CONSTANT(T, 113, 1646.02452040831961063640827116581021),
  1049. BOOST_MATH_BIG_CONSTANT(T, 113, 2299.96860633240298708910425594484895),
  1050. BOOST_MATH_BIG_CONSTANT(T, 113, 1222.73204392037452750381340219906374),
  1051. BOOST_MATH_BIG_CONSTANT(T, 113, 799.359797306084372350264298361110448),
  1052. BOOST_MATH_BIG_CONSTANT(T, 113, 72.7415265778588087243442792401576737),
  1053. };
  1054. result = Y + tools::evaluate_polynomial(P, T(1 / z)) / tools::evaluate_polynomial(Q, T(1 / z));
  1055. T hi, lo;
  1056. int expon;
  1057. hi = floor(ldexp(frexp(z, &expon), 56));
  1058. hi = ldexp(hi, expon - 56);
  1059. lo = z - hi;
  1060. T sq = z * z;
  1061. T err_sqr = ((hi * hi - sq) + 2 * hi * lo) + lo * lo;
  1062. result *= exp(-sq) * exp(-err_sqr) / z;
  1063. }
  1064. }
  1065. else
  1066. {
  1067. //
  1068. // Any value of z larger than 110 will underflow to zero:
  1069. //
  1070. result = 0;
  1071. invert = !invert;
  1072. }
  1073. if(invert)
  1074. {
  1075. result = 1 - result;
  1076. }
  1077. return result;
  1078. } // template <class T, class Lanczos>T erf_imp(T z, bool invert, const Lanczos& l, const std::integral_constant<int, 113>& t)
  1079. template <class T, class Policy, class tag>
  1080. struct erf_initializer
  1081. {
  1082. struct init
  1083. {
  1084. init()
  1085. {
  1086. do_init(tag());
  1087. }
  1088. static void do_init(const std::integral_constant<int, 0>&){}
  1089. static void do_init(const std::integral_constant<int, 53>&)
  1090. {
  1091. boost::math::erf(static_cast<T>(1e-12), Policy());
  1092. boost::math::erf(static_cast<T>(0.25), Policy());
  1093. boost::math::erf(static_cast<T>(1.25), Policy());
  1094. boost::math::erf(static_cast<T>(2.25), Policy());
  1095. boost::math::erf(static_cast<T>(4.25), Policy());
  1096. boost::math::erf(static_cast<T>(5.25), Policy());
  1097. }
  1098. static void do_init(const std::integral_constant<int, 64>&)
  1099. {
  1100. boost::math::erf(static_cast<T>(1e-12), Policy());
  1101. boost::math::erf(static_cast<T>(0.25), Policy());
  1102. boost::math::erf(static_cast<T>(1.25), Policy());
  1103. boost::math::erf(static_cast<T>(2.25), Policy());
  1104. boost::math::erf(static_cast<T>(4.25), Policy());
  1105. boost::math::erf(static_cast<T>(5.25), Policy());
  1106. }
  1107. static void do_init(const std::integral_constant<int, 113>&)
  1108. {
  1109. boost::math::erf(static_cast<T>(1e-22), Policy());
  1110. boost::math::erf(static_cast<T>(0.25), Policy());
  1111. boost::math::erf(static_cast<T>(1.25), Policy());
  1112. boost::math::erf(static_cast<T>(2.125), Policy());
  1113. boost::math::erf(static_cast<T>(2.75), Policy());
  1114. boost::math::erf(static_cast<T>(3.25), Policy());
  1115. boost::math::erf(static_cast<T>(5.25), Policy());
  1116. boost::math::erf(static_cast<T>(7.25), Policy());
  1117. boost::math::erf(static_cast<T>(11.25), Policy());
  1118. boost::math::erf(static_cast<T>(12.5), Policy());
  1119. }
  1120. void force_instantiate()const{}
  1121. };
  1122. static const init initializer;
  1123. static void force_instantiate()
  1124. {
  1125. initializer.force_instantiate();
  1126. }
  1127. };
  1128. template <class T, class Policy, class tag>
  1129. const typename erf_initializer<T, Policy, tag>::init erf_initializer<T, Policy, tag>::initializer;
  1130. } // namespace detail
  1131. template <class T, class Policy>
  1132. inline typename tools::promote_args<T>::type erf(T z, const Policy& /* pol */)
  1133. {
  1134. typedef typename tools::promote_args<T>::type result_type;
  1135. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  1136. typedef typename policies::precision<result_type, Policy>::type precision_type;
  1137. typedef typename policies::normalise<
  1138. Policy,
  1139. policies::promote_float<false>,
  1140. policies::promote_double<false>,
  1141. policies::discrete_quantile<>,
  1142. policies::assert_undefined<> >::type forwarding_policy;
  1143. BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name());
  1144. BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name());
  1145. BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name());
  1146. typedef std::integral_constant<int,
  1147. precision_type::value <= 0 ? 0 :
  1148. precision_type::value <= 53 ? 53 :
  1149. precision_type::value <= 64 ? 64 :
  1150. precision_type::value <= 113 ? 113 : 0
  1151. > tag_type;
  1152. BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name());
  1153. detail::erf_initializer<value_type, forwarding_policy, tag_type>::force_instantiate(); // Force constants to be initialized before main
  1154. return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp(
  1155. static_cast<value_type>(z),
  1156. false,
  1157. forwarding_policy(),
  1158. tag_type()), "boost::math::erf<%1%>(%1%, %1%)");
  1159. }
  1160. template <class T, class Policy>
  1161. inline typename tools::promote_args<T>::type erfc(T z, const Policy& /* pol */)
  1162. {
  1163. typedef typename tools::promote_args<T>::type result_type;
  1164. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  1165. typedef typename policies::precision<result_type, Policy>::type precision_type;
  1166. typedef typename policies::normalise<
  1167. Policy,
  1168. policies::promote_float<false>,
  1169. policies::promote_double<false>,
  1170. policies::discrete_quantile<>,
  1171. policies::assert_undefined<> >::type forwarding_policy;
  1172. BOOST_MATH_INSTRUMENT_CODE("result_type = " << typeid(result_type).name());
  1173. BOOST_MATH_INSTRUMENT_CODE("value_type = " << typeid(value_type).name());
  1174. BOOST_MATH_INSTRUMENT_CODE("precision_type = " << typeid(precision_type).name());
  1175. typedef std::integral_constant<int,
  1176. precision_type::value <= 0 ? 0 :
  1177. precision_type::value <= 53 ? 53 :
  1178. precision_type::value <= 64 ? 64 :
  1179. precision_type::value <= 113 ? 113 : 0
  1180. > tag_type;
  1181. BOOST_MATH_INSTRUMENT_CODE("tag_type = " << typeid(tag_type).name());
  1182. detail::erf_initializer<value_type, forwarding_policy, tag_type>::force_instantiate(); // Force constants to be initialized before main
  1183. return policies::checked_narrowing_cast<result_type, forwarding_policy>(detail::erf_imp(
  1184. static_cast<value_type>(z),
  1185. true,
  1186. forwarding_policy(),
  1187. tag_type()), "boost::math::erfc<%1%>(%1%, %1%)");
  1188. }
  1189. template <class T>
  1190. inline typename tools::promote_args<T>::type erf(T z)
  1191. {
  1192. return boost::math::erf(z, policies::policy<>());
  1193. }
  1194. template <class T>
  1195. inline typename tools::promote_args<T>::type erfc(T z)
  1196. {
  1197. return boost::math::erfc(z, policies::policy<>());
  1198. }
  1199. } // namespace math
  1200. } // namespace boost
  1201. #include <boost/math/special_functions/detail/erf_inv.hpp>
  1202. #endif // BOOST_MATH_SPECIAL_ERF_HPP