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