]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright John Maddock 2008. |
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 | // Wrapper that works with mpfr_class defined in gmpfrxx.h | |
7 | // See http://math.berkeley.edu/~wilken/code/gmpfrxx/ | |
8 | // Also requires the gmp and mpfr libraries. | |
9 | // | |
10 | ||
11 | #ifndef BOOST_MATH_E_FLOAT_BINDINGS_HPP | |
12 | #define BOOST_MATH_E_FLOAT_BINDINGS_HPP | |
13 | ||
14 | #include <boost/config.hpp> | |
15 | ||
16 | ||
17 | #include <e_float/e_float.h> | |
18 | #include <functions/functions.h> | |
19 | ||
20 | #include <boost/math/tools/precision.hpp> | |
21 | #include <boost/math/tools/real_cast.hpp> | |
22 | #include <boost/math/policies/policy.hpp> | |
23 | #include <boost/math/distributions/fwd.hpp> | |
24 | #include <boost/math/special_functions/math_fwd.hpp> | |
25 | #include <boost/math/special_functions/fpclassify.hpp> | |
26 | #include <boost/math/bindings/detail/big_digamma.hpp> | |
27 | #include <boost/math/bindings/detail/big_lanczos.hpp> | |
28 | #include <boost/lexical_cast.hpp> | |
29 | ||
30 | ||
31 | namespace boost{ namespace math{ namespace ef{ | |
32 | ||
33 | class e_float | |
34 | { | |
35 | public: | |
36 | // Constructors: | |
37 | e_float() {} | |
38 | e_float(const ::e_float& c) : m_value(c){} | |
39 | e_float(char c) | |
40 | { | |
41 | m_value = ::e_float(c); | |
42 | } | |
43 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T | |
44 | e_float(wchar_t c) | |
45 | { | |
46 | m_value = ::e_float(c); | |
47 | } | |
48 | #endif | |
49 | e_float(unsigned char c) | |
50 | { | |
51 | m_value = ::e_float(c); | |
52 | } | |
53 | e_float(signed char c) | |
54 | { | |
55 | m_value = ::e_float(c); | |
56 | } | |
57 | e_float(unsigned short c) | |
58 | { | |
59 | m_value = ::e_float(c); | |
60 | } | |
61 | e_float(short c) | |
62 | { | |
63 | m_value = ::e_float(c); | |
64 | } | |
65 | e_float(unsigned int c) | |
66 | { | |
67 | m_value = ::e_float(c); | |
68 | } | |
69 | e_float(int c) | |
70 | { | |
71 | m_value = ::e_float(c); | |
72 | } | |
73 | e_float(unsigned long c) | |
74 | { | |
75 | m_value = ::e_float((UINT64)c); | |
76 | } | |
77 | e_float(long c) | |
78 | { | |
79 | m_value = ::e_float((INT64)c); | |
80 | } | |
81 | #ifdef BOOST_HAS_LONG_LONG | |
82 | e_float(boost::ulong_long_type c) | |
83 | { | |
84 | m_value = ::e_float(c); | |
85 | } | |
86 | e_float(boost::long_long_type c) | |
87 | { | |
88 | m_value = ::e_float(c); | |
89 | } | |
90 | #endif | |
91 | e_float(float c) | |
92 | { | |
93 | assign_large_real(c); | |
94 | } | |
95 | e_float(double c) | |
96 | { | |
97 | assign_large_real(c); | |
98 | } | |
99 | e_float(long double c) | |
100 | { | |
101 | assign_large_real(c); | |
102 | } | |
103 | ||
104 | // Assignment: | |
105 | e_float& operator=(char c) { m_value = ::e_float(c); return *this; } | |
106 | e_float& operator=(unsigned char c) { m_value = ::e_float(c); return *this; } | |
107 | e_float& operator=(signed char c) { m_value = ::e_float(c); return *this; } | |
108 | #ifndef BOOST_NO_INTRINSIC_WCHAR_T | |
109 | e_float& operator=(wchar_t c) { m_value = ::e_float(c); return *this; } | |
110 | #endif | |
111 | e_float& operator=(short c) { m_value = ::e_float(c); return *this; } | |
112 | e_float& operator=(unsigned short c) { m_value = ::e_float(c); return *this; } | |
113 | e_float& operator=(int c) { m_value = ::e_float(c); return *this; } | |
114 | e_float& operator=(unsigned int c) { m_value = ::e_float(c); return *this; } | |
115 | e_float& operator=(long c) { m_value = ::e_float((INT64)c); return *this; } | |
116 | e_float& operator=(unsigned long c) { m_value = ::e_float((UINT64)c); return *this; } | |
117 | #ifdef BOOST_HAS_LONG_LONG | |
118 | e_float& operator=(boost::long_long_type c) { m_value = ::e_float(c); return *this; } | |
119 | e_float& operator=(boost::ulong_long_type c) { m_value = ::e_float(c); return *this; } | |
120 | #endif | |
121 | e_float& operator=(float c) { assign_large_real(c); return *this; } | |
122 | e_float& operator=(double c) { assign_large_real(c); return *this; } | |
123 | e_float& operator=(long double c) { assign_large_real(c); return *this; } | |
124 | ||
125 | // Access: | |
126 | ::e_float& value(){ return m_value; } | |
127 | ::e_float const& value()const{ return m_value; } | |
128 | ||
129 | // Member arithmetic: | |
130 | e_float& operator+=(const e_float& other) | |
131 | { m_value += other.value(); return *this; } | |
132 | e_float& operator-=(const e_float& other) | |
133 | { m_value -= other.value(); return *this; } | |
134 | e_float& operator*=(const e_float& other) | |
135 | { m_value *= other.value(); return *this; } | |
136 | e_float& operator/=(const e_float& other) | |
137 | { m_value /= other.value(); return *this; } | |
138 | e_float operator-()const | |
139 | { return -m_value; } | |
140 | e_float const& operator+()const | |
141 | { return *this; } | |
142 | ||
143 | private: | |
144 | ::e_float m_value; | |
145 | ||
146 | template <class V> | |
147 | void assign_large_real(const V& a) | |
148 | { | |
149 | using std::frexp; | |
150 | using std::ldexp; | |
151 | using std::floor; | |
152 | if (a == 0) { | |
153 | m_value = ::ef::zero(); | |
154 | return; | |
155 | } | |
156 | ||
157 | if (a == 1) { | |
158 | m_value = ::ef::one(); | |
159 | return; | |
160 | } | |
161 | ||
162 | if ((boost::math::isinf)(a)) | |
163 | { | |
164 | m_value = a > 0 ? m_value.my_value_inf() : -m_value.my_value_inf(); | |
165 | return; | |
166 | } | |
167 | if((boost::math::isnan)(a)) | |
168 | { | |
169 | m_value = m_value.my_value_nan(); | |
170 | return; | |
171 | } | |
172 | ||
173 | int e; | |
174 | long double f, term; | |
175 | ::e_float t; | |
176 | m_value = ::ef::zero(); | |
177 | ||
178 | f = frexp(a, &e); | |
179 | ||
180 | ::e_float shift = ::ef::pow2(30); | |
181 | ||
182 | while(f) | |
183 | { | |
184 | // extract 30 bits from f: | |
185 | f = ldexp(f, 30); | |
186 | term = floor(f); | |
187 | e -= 30; | |
188 | m_value *= shift; | |
189 | m_value += ::e_float(static_cast<INT64>(term)); | |
190 | f -= term; | |
191 | } | |
192 | m_value *= ::ef::pow2(e); | |
193 | } | |
194 | }; | |
195 | ||
196 | ||
197 | // Non-member arithmetic: | |
198 | inline e_float operator+(const e_float& a, const e_float& b) | |
199 | { | |
200 | e_float result(a); | |
201 | result += b; | |
202 | return result; | |
203 | } | |
204 | inline e_float operator-(const e_float& a, const e_float& b) | |
205 | { | |
206 | e_float result(a); | |
207 | result -= b; | |
208 | return result; | |
209 | } | |
210 | inline e_float operator*(const e_float& a, const e_float& b) | |
211 | { | |
212 | e_float result(a); | |
213 | result *= b; | |
214 | return result; | |
215 | } | |
216 | inline e_float operator/(const e_float& a, const e_float& b) | |
217 | { | |
218 | e_float result(a); | |
219 | result /= b; | |
220 | return result; | |
221 | } | |
222 | ||
223 | // Comparison: | |
224 | inline bool operator == (const e_float& a, const e_float& b) | |
225 | { return a.value() == b.value() ? true : false; } | |
226 | inline bool operator != (const e_float& a, const e_float& b) | |
227 | { return a.value() != b.value() ? true : false;} | |
228 | inline bool operator < (const e_float& a, const e_float& b) | |
229 | { return a.value() < b.value() ? true : false; } | |
230 | inline bool operator <= (const e_float& a, const e_float& b) | |
231 | { return a.value() <= b.value() ? true : false; } | |
232 | inline bool operator > (const e_float& a, const e_float& b) | |
233 | { return a.value() > b.value() ? true : false; } | |
234 | inline bool operator >= (const e_float& a, const e_float& b) | |
235 | { return a.value() >= b.value() ? true : false; } | |
236 | ||
237 | std::istream& operator >> (std::istream& is, e_float& f) | |
238 | { | |
239 | return is >> f.value(); | |
240 | } | |
241 | ||
242 | std::ostream& operator << (std::ostream& os, const e_float& f) | |
243 | { | |
244 | return os << f.value(); | |
245 | } | |
246 | ||
247 | inline e_float fabs(const e_float& v) | |
248 | { | |
249 | return ::ef::fabs(v.value()); | |
250 | } | |
251 | ||
252 | inline e_float abs(const e_float& v) | |
253 | { | |
254 | return ::ef::fabs(v.value()); | |
255 | } | |
256 | ||
257 | inline e_float floor(const e_float& v) | |
258 | { | |
259 | return ::ef::floor(v.value()); | |
260 | } | |
261 | ||
262 | inline e_float ceil(const e_float& v) | |
263 | { | |
264 | return ::ef::ceil(v.value()); | |
265 | } | |
266 | ||
267 | inline e_float pow(const e_float& v, const e_float& w) | |
268 | { | |
269 | return ::ef::pow(v.value(), w.value()); | |
270 | } | |
271 | ||
272 | inline e_float pow(const e_float& v, int i) | |
273 | { | |
274 | return ::ef::pow(v.value(), ::e_float(i)); | |
275 | } | |
276 | ||
277 | inline e_float exp(const e_float& v) | |
278 | { | |
279 | return ::ef::exp(v.value()); | |
280 | } | |
281 | ||
282 | inline e_float log(const e_float& v) | |
283 | { | |
284 | return ::ef::log(v.value()); | |
285 | } | |
286 | ||
287 | inline e_float sqrt(const e_float& v) | |
288 | { | |
289 | return ::ef::sqrt(v.value()); | |
290 | } | |
291 | ||
292 | inline e_float sin(const e_float& v) | |
293 | { | |
294 | return ::ef::sin(v.value()); | |
295 | } | |
296 | ||
297 | inline e_float cos(const e_float& v) | |
298 | { | |
299 | return ::ef::cos(v.value()); | |
300 | } | |
301 | ||
302 | inline e_float tan(const e_float& v) | |
303 | { | |
304 | return ::ef::tan(v.value()); | |
305 | } | |
306 | ||
307 | inline e_float acos(const e_float& v) | |
308 | { | |
309 | return ::ef::acos(v.value()); | |
310 | } | |
311 | ||
312 | inline e_float asin(const e_float& v) | |
313 | { | |
314 | return ::ef::asin(v.value()); | |
315 | } | |
316 | ||
317 | inline e_float atan(const e_float& v) | |
318 | { | |
319 | return ::ef::atan(v.value()); | |
320 | } | |
321 | ||
322 | inline e_float atan2(const e_float& v, const e_float& u) | |
323 | { | |
324 | return ::ef::atan2(v.value(), u.value()); | |
325 | } | |
326 | ||
327 | inline e_float ldexp(const e_float& v, int e) | |
328 | { | |
329 | return v.value() * ::ef::pow2(e); | |
330 | } | |
331 | ||
332 | inline e_float frexp(const e_float& v, int* expon) | |
333 | { | |
334 | double d; | |
335 | INT64 i; | |
336 | v.value().extract_parts(d, i); | |
337 | *expon = static_cast<int>(i); | |
338 | return v.value() * ::ef::pow2(-i); | |
339 | } | |
340 | ||
341 | inline e_float sinh (const e_float& x) | |
342 | { | |
343 | return ::ef::sinh(x.value()); | |
344 | } | |
345 | ||
346 | inline e_float cosh (const e_float& x) | |
347 | { | |
348 | return ::ef::cosh(x.value()); | |
349 | } | |
350 | ||
351 | inline e_float tanh (const e_float& x) | |
352 | { | |
353 | return ::ef::tanh(x.value()); | |
354 | } | |
355 | ||
356 | inline e_float asinh (const e_float& x) | |
357 | { | |
358 | return ::ef::asinh(x.value()); | |
359 | } | |
360 | ||
361 | inline e_float acosh (const e_float& x) | |
362 | { | |
363 | return ::ef::acosh(x.value()); | |
364 | } | |
365 | ||
366 | inline e_float atanh (const e_float& x) | |
367 | { | |
368 | return ::ef::atanh(x.value()); | |
369 | } | |
370 | ||
371 | e_float fmod(const e_float& v1, const e_float& v2) | |
372 | { | |
373 | e_float n; | |
374 | if(v1 < 0) | |
375 | n = ceil(v1 / v2); | |
376 | else | |
377 | n = floor(v1 / v2); | |
378 | return v1 - n * v2; | |
379 | } | |
380 | ||
381 | } namespace detail{ | |
382 | ||
383 | template <> | |
384 | inline int fpclassify_imp< boost::math::ef::e_float> BOOST_NO_MACRO_EXPAND(boost::math::ef::e_float x, const generic_tag<true>&) | |
385 | { | |
386 | if(x.value().isnan()) | |
387 | return FP_NAN; | |
388 | if(x.value().isinf()) | |
389 | return FP_INFINITE; | |
390 | if(x == 0) | |
391 | return FP_ZERO; | |
392 | return FP_NORMAL; | |
393 | } | |
394 | ||
395 | } namespace ef{ | |
396 | ||
397 | template <class Policy> | |
398 | inline int itrunc(const e_float& v, const Policy& pol) | |
399 | { | |
400 | BOOST_MATH_STD_USING | |
401 | e_float r = boost::math::trunc(v, pol); | |
402 | if(fabs(r) > (std::numeric_limits<int>::max)()) | |
403 | return static_cast<int>(policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, 0, v, pol)); | |
404 | return static_cast<int>(r.value().extract_int64()); | |
405 | } | |
406 | ||
407 | template <class Policy> | |
408 | inline long ltrunc(const e_float& v, const Policy& pol) | |
409 | { | |
410 | BOOST_MATH_STD_USING | |
411 | e_float r = boost::math::trunc(v, pol); | |
412 | if(fabs(r) > (std::numeric_limits<long>::max)()) | |
413 | return static_cast<long>(policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, 0L, v, pol)); | |
414 | return static_cast<long>(r.value().extract_int64()); | |
415 | } | |
416 | ||
417 | #ifdef BOOST_HAS_LONG_LONG | |
418 | template <class Policy> | |
419 | inline boost::long_long_type lltrunc(const e_float& v, const Policy& pol) | |
420 | { | |
421 | BOOST_MATH_STD_USING | |
422 | e_float r = boost::math::trunc(v, pol); | |
423 | if(fabs(r) > (std::numeric_limits<boost::long_long_type>::max)()) | |
424 | return static_cast<boost::long_long_type>(policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, 0LL, pol).value().extract_int64()); | |
425 | return static_cast<boost::long_long_type>(r.value().extract_int64()); | |
426 | } | |
427 | #endif | |
428 | ||
429 | template <class Policy> | |
430 | inline int iround(const e_float& v, const Policy& pol) | |
431 | { | |
432 | BOOST_MATH_STD_USING | |
433 | e_float r = boost::math::round(v, pol); | |
434 | if(fabs(r) > (std::numeric_limits<int>::max)()) | |
435 | return static_cast<int>(policies::raise_rounding_error("boost::math::iround<%1%>(%1%)", 0, v, 0, pol).value().extract_int64()); | |
436 | return static_cast<int>(r.value().extract_int64()); | |
437 | } | |
438 | ||
439 | template <class Policy> | |
440 | inline long lround(const e_float& v, const Policy& pol) | |
441 | { | |
442 | BOOST_MATH_STD_USING | |
443 | e_float r = boost::math::round(v, pol); | |
444 | if(fabs(r) > (std::numeric_limits<long>::max)()) | |
445 | return static_cast<long int>(policies::raise_rounding_error("boost::math::lround<%1%>(%1%)", 0, v, 0L, pol).value().extract_int64()); | |
446 | return static_cast<long int>(r.value().extract_int64()); | |
447 | } | |
448 | ||
449 | #ifdef BOOST_HAS_LONG_LONG | |
450 | template <class Policy> | |
451 | inline boost::long_long_type llround(const e_float& v, const Policy& pol) | |
452 | { | |
453 | BOOST_MATH_STD_USING | |
454 | e_float r = boost::math::round(v, pol); | |
455 | if(fabs(r) > (std::numeric_limits<boost::long_long_type>::max)()) | |
456 | return static_cast<boost::long_long_type>(policies::raise_rounding_error("boost::math::llround<%1%>(%1%)", 0, v, 0LL, pol).value().extract_int64()); | |
457 | return static_cast<boost::long_long_type>(r.value().extract_int64()); | |
458 | } | |
459 | #endif | |
460 | ||
461 | }}} | |
462 | ||
463 | namespace std{ | |
464 | ||
465 | template<> | |
466 | class numeric_limits< ::boost::math::ef::e_float> : public numeric_limits< ::e_float> | |
467 | { | |
468 | public: | |
469 | static const ::boost::math::ef::e_float (min) (void) | |
470 | { | |
471 | return (numeric_limits< ::e_float>::min)(); | |
472 | } | |
473 | static const ::boost::math::ef::e_float (max) (void) | |
474 | { | |
475 | return (numeric_limits< ::e_float>::max)(); | |
476 | } | |
477 | static const ::boost::math::ef::e_float epsilon (void) | |
478 | { | |
479 | return (numeric_limits< ::e_float>::epsilon)(); | |
480 | } | |
481 | static const ::boost::math::ef::e_float round_error(void) | |
482 | { | |
483 | return (numeric_limits< ::e_float>::round_error)(); | |
484 | } | |
485 | static const ::boost::math::ef::e_float infinity (void) | |
486 | { | |
487 | return (numeric_limits< ::e_float>::infinity)(); | |
488 | } | |
489 | static const ::boost::math::ef::e_float quiet_NaN (void) | |
490 | { | |
491 | return (numeric_limits< ::e_float>::quiet_NaN)(); | |
492 | } | |
493 | // | |
494 | // e_float's supplied digits member is wrong | |
495 | // - it should be same the same as digits 10 | |
496 | // - given that radix is 10. | |
497 | // | |
498 | static const int digits = digits10; | |
499 | }; | |
500 | ||
501 | } // namespace std | |
502 | ||
503 | namespace boost{ namespace math{ | |
504 | ||
505 | namespace policies{ | |
506 | ||
507 | template <class Policy> | |
508 | struct precision< ::boost::math::ef::e_float, Policy> | |
509 | { | |
510 | typedef typename Policy::precision_type precision_type; | |
511 | typedef digits2<((::std::numeric_limits< ::boost::math::ef::e_float>::digits10 + 1) * 1000L) / 301L> digits_2; | |
512 | typedef typename mpl::if_c< | |
513 | ((digits_2::value <= precision_type::value) | |
514 | || (Policy::precision_type::value <= 0)), | |
515 | // Default case, full precision for RealType: | |
516 | digits_2, | |
517 | // User customised precision: | |
518 | precision_type | |
519 | >::type type; | |
520 | }; | |
521 | ||
522 | } | |
523 | ||
524 | namespace tools{ | |
525 | ||
526 | template <> | |
527 | inline int digits< ::boost::math::ef::e_float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC( ::boost::math::ef::e_float)) | |
528 | { | |
529 | return ((::std::numeric_limits< ::boost::math::ef::e_float>::digits10 + 1) * 1000L) / 301L; | |
530 | } | |
531 | ||
532 | template <> | |
533 | inline ::boost::math::ef::e_float root_epsilon< ::boost::math::ef::e_float>() | |
534 | { | |
f67539c2 | 535 | return detail::root_epsilon_imp(static_cast< ::boost::math::ef::e_float const*>(0), boost::integral_constant<int, 0>()); |
7c673cae FG |
536 | } |
537 | ||
538 | template <> | |
539 | inline ::boost::math::ef::e_float forth_root_epsilon< ::boost::math::ef::e_float>() | |
540 | { | |
f67539c2 | 541 | return detail::forth_root_epsilon_imp(static_cast< ::boost::math::ef::e_float const*>(0), boost::integral_constant<int, 0>()); |
7c673cae FG |
542 | } |
543 | ||
544 | } | |
545 | ||
546 | namespace lanczos{ | |
547 | ||
548 | template<class Policy> | |
549 | struct lanczos<boost::math::ef::e_float, Policy> | |
550 | { | |
551 | typedef typename mpl::if_c< | |
552 | std::numeric_limits< ::e_float>::digits10 < 22, | |
553 | lanczos13UDT, | |
554 | typename mpl::if_c< | |
555 | std::numeric_limits< ::e_float>::digits10 < 36, | |
556 | lanczos22UDT, | |
557 | typename mpl::if_c< | |
558 | std::numeric_limits< ::e_float>::digits10 < 50, | |
559 | lanczos31UDT, | |
560 | typename mpl::if_c< | |
561 | std::numeric_limits< ::e_float>::digits10 < 110, | |
562 | lanczos61UDT, | |
563 | undefined_lanczos | |
564 | >::type | |
565 | >::type | |
566 | >::type | |
567 | >::type type; | |
568 | }; | |
569 | ||
570 | } // namespace lanczos | |
571 | ||
572 | template <class Policy> | |
573 | inline boost::math::ef::e_float skewness(const extreme_value_distribution<boost::math::ef::e_float, Policy>& /*dist*/) | |
574 | { | |
575 | // | |
576 | // This is 12 * sqrt(6) * zeta(3) / pi^3: | |
577 | // See http://mathworld.wolfram.com/ExtremeValueDistribution.html | |
578 | // | |
579 | return boost::lexical_cast<boost::math::ef::e_float>("1.1395470994046486574927930193898461120875997958366"); | |
580 | } | |
581 | ||
582 | template <class Policy> | |
583 | inline boost::math::ef::e_float skewness(const rayleigh_distribution<boost::math::ef::e_float, Policy>& /*dist*/) | |
584 | { | |
585 | // using namespace boost::math::constants; | |
586 | return boost::lexical_cast<boost::math::ef::e_float>("0.63111065781893713819189935154422777984404221106391"); | |
587 | // Computed using NTL at 150 bit, about 50 decimal digits. | |
588 | // return 2 * root_pi<RealType>() * pi_minus_three<RealType>() / pow23_four_minus_pi<RealType>(); | |
589 | } | |
590 | ||
591 | template <class Policy> | |
592 | inline boost::math::ef::e_float kurtosis(const rayleigh_distribution<boost::math::ef::e_float, Policy>& /*dist*/) | |
593 | { | |
594 | // using namespace boost::math::constants; | |
595 | return boost::lexical_cast<boost::math::ef::e_float>("3.2450893006876380628486604106197544154170667057995"); | |
596 | // Computed using NTL at 150 bit, about 50 decimal digits. | |
597 | // return 3 - (6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / | |
598 | // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); | |
599 | } | |
600 | ||
601 | template <class Policy> | |
602 | inline boost::math::ef::e_float kurtosis_excess(const rayleigh_distribution<boost::math::ef::e_float, Policy>& /*dist*/) | |
603 | { | |
604 | //using namespace boost::math::constants; | |
605 | // Computed using NTL at 150 bit, about 50 decimal digits. | |
606 | return boost::lexical_cast<boost::math::ef::e_float>("0.2450893006876380628486604106197544154170667057995"); | |
607 | // return -(6 * pi<RealType>() * pi<RealType>() - 24 * pi<RealType>() + 16) / | |
608 | // (four_minus_pi<RealType>() * four_minus_pi<RealType>()); | |
609 | } // kurtosis | |
610 | ||
611 | namespace detail{ | |
612 | ||
613 | // | |
614 | // Version of Digamma accurate to ~100 decimal digits. | |
615 | // | |
616 | template <class Policy> | |
f67539c2 | 617 | boost::math::ef::e_float digamma_imp(boost::math::ef::e_float x, const boost::integral_constant<int, 0>* , const Policy& pol) |
7c673cae FG |
618 | { |
619 | // | |
620 | // This handles reflection of negative arguments, and all our | |
621 | // eboost::math::ef::e_floator handling, then forwards to the T-specific approximation. | |
622 | // | |
623 | BOOST_MATH_STD_USING // ADL of std functions. | |
624 | ||
625 | boost::math::ef::e_float result = 0; | |
626 | // | |
627 | // Check for negative arguments and use reflection: | |
628 | // | |
629 | if(x < 0) | |
630 | { | |
631 | // Reflect: | |
632 | x = 1 - x; | |
633 | // Argument reduction for tan: | |
634 | boost::math::ef::e_float remainder = x - floor(x); | |
635 | // Shift to negative if > 0.5: | |
636 | if(remainder > 0.5) | |
637 | { | |
638 | remainder -= 1; | |
639 | } | |
640 | // | |
641 | // check for evaluation at a negative pole: | |
642 | // | |
643 | if(remainder == 0) | |
644 | { | |
645 | return policies::raise_pole_error<boost::math::ef::e_float>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol); | |
646 | } | |
647 | result = constants::pi<boost::math::ef::e_float>() / tan(constants::pi<boost::math::ef::e_float>() * remainder); | |
648 | } | |
649 | result += big_digamma(x); | |
650 | return result; | |
651 | } | |
652 | boost::math::ef::e_float bessel_i0(boost::math::ef::e_float x) | |
653 | { | |
654 | static const boost::math::ef::e_float P1[] = { | |
655 | boost::lexical_cast<boost::math::ef::e_float>("-2.2335582639474375249e+15"), | |
656 | boost::lexical_cast<boost::math::ef::e_float>("-5.5050369673018427753e+14"), | |
657 | boost::lexical_cast<boost::math::ef::e_float>("-3.2940087627407749166e+13"), | |
658 | boost::lexical_cast<boost::math::ef::e_float>("-8.4925101247114157499e+11"), | |
659 | boost::lexical_cast<boost::math::ef::e_float>("-1.1912746104985237192e+10"), | |
660 | boost::lexical_cast<boost::math::ef::e_float>("-1.0313066708737980747e+08"), | |
661 | boost::lexical_cast<boost::math::ef::e_float>("-5.9545626019847898221e+05"), | |
662 | boost::lexical_cast<boost::math::ef::e_float>("-2.4125195876041896775e+03"), | |
663 | boost::lexical_cast<boost::math::ef::e_float>("-7.0935347449210549190e+00"), | |
664 | boost::lexical_cast<boost::math::ef::e_float>("-1.5453977791786851041e-02"), | |
665 | boost::lexical_cast<boost::math::ef::e_float>("-2.5172644670688975051e-05"), | |
666 | boost::lexical_cast<boost::math::ef::e_float>("-3.0517226450451067446e-08"), | |
667 | boost::lexical_cast<boost::math::ef::e_float>("-2.6843448573468483278e-11"), | |
668 | boost::lexical_cast<boost::math::ef::e_float>("-1.5982226675653184646e-14"), | |
669 | boost::lexical_cast<boost::math::ef::e_float>("-5.2487866627945699800e-18"), | |
670 | }; | |
671 | static const boost::math::ef::e_float Q1[] = { | |
672 | boost::lexical_cast<boost::math::ef::e_float>("-2.2335582639474375245e+15"), | |
673 | boost::lexical_cast<boost::math::ef::e_float>("7.8858692566751002988e+12"), | |
674 | boost::lexical_cast<boost::math::ef::e_float>("-1.2207067397808979846e+10"), | |
675 | boost::lexical_cast<boost::math::ef::e_float>("1.0377081058062166144e+07"), | |
676 | boost::lexical_cast<boost::math::ef::e_float>("-4.8527560179962773045e+03"), | |
677 | boost::lexical_cast<boost::math::ef::e_float>("1.0"), | |
678 | }; | |
679 | static const boost::math::ef::e_float P2[] = { | |
680 | boost::lexical_cast<boost::math::ef::e_float>("-2.2210262233306573296e-04"), | |
681 | boost::lexical_cast<boost::math::ef::e_float>("1.3067392038106924055e-02"), | |
682 | boost::lexical_cast<boost::math::ef::e_float>("-4.4700805721174453923e-01"), | |
683 | boost::lexical_cast<boost::math::ef::e_float>("5.5674518371240761397e+00"), | |
684 | boost::lexical_cast<boost::math::ef::e_float>("-2.3517945679239481621e+01"), | |
685 | boost::lexical_cast<boost::math::ef::e_float>("3.1611322818701131207e+01"), | |
686 | boost::lexical_cast<boost::math::ef::e_float>("-9.6090021968656180000e+00"), | |
687 | }; | |
688 | static const boost::math::ef::e_float Q2[] = { | |
689 | boost::lexical_cast<boost::math::ef::e_float>("-5.5194330231005480228e-04"), | |
690 | boost::lexical_cast<boost::math::ef::e_float>("3.2547697594819615062e-02"), | |
691 | boost::lexical_cast<boost::math::ef::e_float>("-1.1151759188741312645e+00"), | |
692 | boost::lexical_cast<boost::math::ef::e_float>("1.3982595353892851542e+01"), | |
693 | boost::lexical_cast<boost::math::ef::e_float>("-6.0228002066743340583e+01"), | |
694 | boost::lexical_cast<boost::math::ef::e_float>("8.5539563258012929600e+01"), | |
695 | boost::lexical_cast<boost::math::ef::e_float>("-3.1446690275135491500e+01"), | |
696 | boost::lexical_cast<boost::math::ef::e_float>("1.0"), | |
697 | }; | |
698 | boost::math::ef::e_float value, factor, r; | |
699 | ||
700 | BOOST_MATH_STD_USING | |
701 | using namespace boost::math::tools; | |
702 | ||
703 | if (x < 0) | |
704 | { | |
705 | x = -x; // even function | |
706 | } | |
707 | if (x == 0) | |
708 | { | |
709 | return static_cast<boost::math::ef::e_float>(1); | |
710 | } | |
711 | if (x <= 15) // x in (0, 15] | |
712 | { | |
713 | boost::math::ef::e_float y = x * x; | |
714 | value = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); | |
715 | } | |
716 | else // x in (15, \infty) | |
717 | { | |
718 | boost::math::ef::e_float y = 1 / x - boost::math::ef::e_float(1) / 15; | |
719 | r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); | |
720 | factor = exp(x) / sqrt(x); | |
721 | value = factor * r; | |
722 | } | |
723 | ||
724 | return value; | |
725 | } | |
726 | ||
727 | boost::math::ef::e_float bessel_i1(boost::math::ef::e_float x) | |
728 | { | |
729 | static const boost::math::ef::e_float P1[] = { | |
730 | lexical_cast<boost::math::ef::e_float>("-1.4577180278143463643e+15"), | |
731 | lexical_cast<boost::math::ef::e_float>("-1.7732037840791591320e+14"), | |
732 | lexical_cast<boost::math::ef::e_float>("-6.9876779648010090070e+12"), | |
733 | lexical_cast<boost::math::ef::e_float>("-1.3357437682275493024e+11"), | |
734 | lexical_cast<boost::math::ef::e_float>("-1.4828267606612366099e+09"), | |
735 | lexical_cast<boost::math::ef::e_float>("-1.0588550724769347106e+07"), | |
736 | lexical_cast<boost::math::ef::e_float>("-5.1894091982308017540e+04"), | |
737 | lexical_cast<boost::math::ef::e_float>("-1.8225946631657315931e+02"), | |
738 | lexical_cast<boost::math::ef::e_float>("-4.7207090827310162436e-01"), | |
739 | lexical_cast<boost::math::ef::e_float>("-9.1746443287817501309e-04"), | |
740 | lexical_cast<boost::math::ef::e_float>("-1.3466829827635152875e-06"), | |
741 | lexical_cast<boost::math::ef::e_float>("-1.4831904935994647675e-09"), | |
742 | lexical_cast<boost::math::ef::e_float>("-1.1928788903603238754e-12"), | |
743 | lexical_cast<boost::math::ef::e_float>("-6.5245515583151902910e-16"), | |
744 | lexical_cast<boost::math::ef::e_float>("-1.9705291802535139930e-19"), | |
745 | }; | |
746 | static const boost::math::ef::e_float Q1[] = { | |
747 | lexical_cast<boost::math::ef::e_float>("-2.9154360556286927285e+15"), | |
748 | lexical_cast<boost::math::ef::e_float>("9.7887501377547640438e+12"), | |
749 | lexical_cast<boost::math::ef::e_float>("-1.4386907088588283434e+10"), | |
750 | lexical_cast<boost::math::ef::e_float>("1.1594225856856884006e+07"), | |
751 | lexical_cast<boost::math::ef::e_float>("-5.1326864679904189920e+03"), | |
752 | lexical_cast<boost::math::ef::e_float>("1.0"), | |
753 | }; | |
754 | static const boost::math::ef::e_float P2[] = { | |
755 | lexical_cast<boost::math::ef::e_float>("1.4582087408985668208e-05"), | |
756 | lexical_cast<boost::math::ef::e_float>("-8.9359825138577646443e-04"), | |
757 | lexical_cast<boost::math::ef::e_float>("2.9204895411257790122e-02"), | |
758 | lexical_cast<boost::math::ef::e_float>("-3.4198728018058047439e-01"), | |
759 | lexical_cast<boost::math::ef::e_float>("1.3960118277609544334e+00"), | |
760 | lexical_cast<boost::math::ef::e_float>("-1.9746376087200685843e+00"), | |
761 | lexical_cast<boost::math::ef::e_float>("8.5591872901933459000e-01"), | |
762 | lexical_cast<boost::math::ef::e_float>("-6.0437159056137599999e-02"), | |
763 | }; | |
764 | static const boost::math::ef::e_float Q2[] = { | |
765 | lexical_cast<boost::math::ef::e_float>("3.7510433111922824643e-05"), | |
766 | lexical_cast<boost::math::ef::e_float>("-2.2835624489492512649e-03"), | |
767 | lexical_cast<boost::math::ef::e_float>("7.4212010813186530069e-02"), | |
768 | lexical_cast<boost::math::ef::e_float>("-8.5017476463217924408e-01"), | |
769 | lexical_cast<boost::math::ef::e_float>("3.2593714889036996297e+00"), | |
770 | lexical_cast<boost::math::ef::e_float>("-3.8806586721556593450e+00"), | |
771 | lexical_cast<boost::math::ef::e_float>("1.0"), | |
772 | }; | |
773 | boost::math::ef::e_float value, factor, r, w; | |
774 | ||
775 | BOOST_MATH_STD_USING | |
776 | using namespace boost::math::tools; | |
777 | ||
778 | w = abs(x); | |
779 | if (x == 0) | |
780 | { | |
781 | return static_cast<boost::math::ef::e_float>(0); | |
782 | } | |
783 | if (w <= 15) // w in (0, 15] | |
784 | { | |
785 | boost::math::ef::e_float y = x * x; | |
786 | r = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y); | |
787 | factor = w; | |
788 | value = factor * r; | |
789 | } | |
790 | else // w in (15, \infty) | |
791 | { | |
792 | boost::math::ef::e_float y = 1 / w - boost::math::ef::e_float(1) / 15; | |
793 | r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y); | |
794 | factor = exp(w) / sqrt(w); | |
795 | value = factor * r; | |
796 | } | |
797 | ||
798 | if (x < 0) | |
799 | { | |
800 | value *= -value; // odd function | |
801 | } | |
802 | return value; | |
803 | } | |
804 | ||
805 | } // namespace detail | |
806 | ||
807 | }} | |
808 | #endif // BOOST_MATH_E_FLOAT_BINDINGS_HPP | |
809 |