1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111 |
- #ifndef BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
- #define BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
- #include <boost/static_assert.hpp>
- #include <type_traits>
- namespace boost{ namespace math{ namespace constants{ namespace detail{
- template <class T>
- template<int N>
- inline T constant_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return ldexp(acos(T(0)), 1);
-
- }
- template <class T>
- template<int N>
- inline T constant_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 2 * pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T> // 2 / pi
- template<int N>
- inline T constant_two_div_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 2 / pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T> // sqrt(2/pi)
- template <int N>
- inline T constant_root_two_div_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt((2 / pi<T, policies::policy<policies::digits2<N> > >()));
- }
- template <class T>
- template<int N>
- inline T constant_one_div_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 1 / two_pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_root_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(pi<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_root_half_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(pi<T, policies::policy<policies::digits2<N> > >() / 2);
- }
- template <class T>
- template<int N>
- inline T constant_root_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(two_pi<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_log_root_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return log(root_two_pi<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_root_ln_four<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(log(static_cast<T>(4)));
- }
- template <class T>
- template<int N>
- inline T constant_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
-
- BOOST_MATH_STD_USING
- return exp(static_cast<T>(1));
- }
- template <class T>
- template<int N>
- inline T constant_half<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return static_cast<T>(1) / static_cast<T>(2);
- }
- template <class T>
- template<int M>
- inline T constant_euler<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, M>)))
- {
- BOOST_MATH_STD_USING
-
-
-
-
-
-
-
- T n = 3 + (M ? (std::min)(M, tools::digits<T>()) : tools::digits<T>()) / 4;
- T lim = M ? ldexp(T(1), 1 - (std::min)(M, tools::digits<T>())) : tools::epsilon<T>();
- T lnn = log(n);
- T term = 1;
- T N = -lnn;
- T D = 1;
- T Hk = 0;
- T one = 1;
- for(unsigned k = 1;; ++k)
- {
- term *= n * n;
- term /= k * k;
- Hk += one / k;
- N += term * (Hk - lnn);
- D += term;
- if(term < D * lim)
- break;
- }
- return N / D;
- }
- template <class T>
- template<int N>
- inline T constant_euler_sqr<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return euler<T, policies::policy<policies::digits2<N> > >()
- * euler<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_one_div_euler<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1)
- / euler<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_root_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(static_cast<T>(2));
- }
- template <class T>
- template<int N>
- inline T constant_root_three<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(static_cast<T>(3));
- }
- template <class T>
- template<int N>
- inline T constant_half_root_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(static_cast<T>(2)) / 2;
- }
- template <class T>
- template<int N>
- inline T constant_ln_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
-
- BOOST_MATH_STD_USING
- return log(static_cast<T>(2));
- }
- template <class T>
- template<int N>
- inline T constant_ln_ten<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return log(static_cast<T>(10));
- }
- template <class T>
- template<int N>
- inline T constant_ln_ln_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return log(log(static_cast<T>(2)));
- }
- template <class T>
- template<int N>
- inline T constant_third<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1) / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_twothirds<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(2) / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_two_thirds<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(2) / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_three_quarters<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(3) / static_cast<T>(4);
- }
- template <class T>
- template<int N>
- inline T constant_sixth<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1) / static_cast<T>(6);
- }
- template <class T>
- template<int N>
- inline T constant_pi_minus_three<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return pi<T, policies::policy<policies::digits2<N> > >() - static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_four_minus_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return static_cast<T>(4) - pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_exp_minus_half<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return exp(static_cast<T>(-0.5));
- }
- template <class T>
- template<int N>
- inline T constant_exp_minus_one<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return exp(static_cast<T>(-1.));
- }
- template <class T>
- template<int N>
- inline T constant_one_div_root_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return static_cast<T>(1) / root_two<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_one_div_root_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return static_cast<T>(1) / root_pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_one_div_root_two_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return static_cast<T>(1) / root_two_pi<T, policies::policy<policies::digits2<N> > >();
- }
- template <class T>
- template<int N>
- inline T constant_root_one_div_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(static_cast<T>(1) / pi<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_four_thirds_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() * static_cast<T>(4) / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_half_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() / static_cast<T>(2);
- }
- template <class T>
- template<int N>
- inline T constant_third_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_sixth_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() / static_cast<T>(6);
- }
- template <class T>
- template<int N>
- inline T constant_two_thirds_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() * static_cast<T>(2) / static_cast<T>(3);
- }
- template <class T>
- template<int N>
- inline T constant_three_quarters_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >() * static_cast<T>(3) / static_cast<T>(4);
- }
- template <class T>
- template<int N>
- inline T constant_pi_pow_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pow(pi<T, policies::policy<policies::digits2<N> > >(), e<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_pi_sqr<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >() ;
- }
- template <class T>
- template<int N>
- inline T constant_pi_sqr_div_six<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >()
- / static_cast<T>(6);
- }
- template <class T>
- template<int N>
- inline T constant_pi_cubed<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >()
- ;
- }
- template <class T>
- template<int N>
- inline T constant_cbrt_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pow(pi<T, policies::policy<policies::digits2<N> > >(), static_cast<T>(1)/ static_cast<T>(3));
- }
- template <class T>
- template<int N>
- inline T constant_one_div_cbrt_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1)
- / pow(pi<T, policies::policy<policies::digits2<N> > >(), static_cast<T>(1)/ static_cast<T>(3));
- }
- template <class T>
- template<int N>
- inline T constant_e_pow_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pow(e<T, policies::policy<policies::digits2<N> > >(), pi<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_root_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sqrt(e<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_log10_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return log10(e<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_one_div_log10_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1) /
- log10(e<T, policies::policy<policies::digits2<N> > >());
- }
- template <class T>
- template<int N>
- inline T constant_degree<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >()
- / static_cast<T>(180)
- ;
- }
- template <class T>
- template<int N>
- inline T constant_radian<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(180)
- / pi<T, policies::policy<policies::digits2<N> > >()
- ;
- }
- template <class T>
- template<int N>
- inline T constant_sin_one<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sin(static_cast<T>(1)) ;
- }
- template <class T>
- template<int N>
- inline T constant_cos_one<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return cos(static_cast<T>(1)) ;
- }
- template <class T>
- template<int N>
- inline T constant_sinh_one<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return sinh(static_cast<T>(1)) ;
- }
- template <class T>
- template<int N>
- inline T constant_cosh_one<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return cosh(static_cast<T>(1)) ;
- }
- template <class T>
- template<int N>
- inline T constant_phi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return (static_cast<T>(1) + sqrt(static_cast<T>(5)) )/static_cast<T>(2) ;
- }
- template <class T>
- template<int N>
- inline T constant_ln_phi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return log((static_cast<T>(1) + sqrt(static_cast<T>(5)) )/static_cast<T>(2) );
- }
- template <class T>
- template<int N>
- inline T constant_one_div_ln_phi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return static_cast<T>(1) /
- log((static_cast<T>(1) + sqrt(static_cast<T>(5)) )/static_cast<T>(2) );
- }
- template <class T>
- template<int N>
- inline T constant_zeta_two<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- return pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >()
- /static_cast<T>(6);
- }
- template <class T>
- template<int N>
- inline T constant_zeta_three<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
- BOOST_MATH_STD_USING
- T n_fact=static_cast<T>(1);
- T sum = static_cast<double>(77);
-
-
- T lim = N ? ldexp(T(1), 1 - (std::min)(N, tools::digits<T>())) : tools::epsilon<T>();
- for(unsigned int n = 1; n < 40; ++n)
- {
-
- n_fact *= n;
- T n_fact_p10 = n_fact * n_fact * n_fact * n_fact * n_fact * n_fact * n_fact * n_fact * n_fact * n_fact;
- T num = ((205 * n * n) + (250 * n) + 77) * n_fact_p10;
-
-
- T d = 1;
- for(unsigned int i = 1; i <= (n+n + 1); ++i)
- {
- d *= i;
- }
- T den = d * d * d * d * d;
-
- T term = num/den;
- if (n % 2 != 0)
- {
- sum -= term;
- }
- else
- {
- sum += term;
- }
-
-
- if(abs(term) < lim)
- {
- break;
- }
- }
- return sum / 64;
- }
- template <class T>
- template<int N>
- inline T constant_catalan<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
-
-
- BOOST_MATH_STD_USING
- T k_fact = 1;
- T tk_fact = 1;
- T sum = 1;
- T term;
- T lim = N ? ldexp(T(1), 1 - (std::min)(N, tools::digits<T>())) : tools::epsilon<T>();
- for(unsigned k = 1;; ++k)
- {
- k_fact *= k;
- tk_fact *= (2 * k) * (2 * k - 1);
- term = k_fact * k_fact / (tk_fact * (2 * k + 1) * (2 * k + 1));
- sum += term;
- if(term < lim)
- {
- break;
- }
- }
- return boost::math::constants::pi<T, boost::math::policies::policy<> >()
- * log(2 + boost::math::constants::root_three<T, boost::math::policies::policy<> >())
- / 8
- + 3 * sum / 8;
- }
- namespace khinchin_detail{
- template <class T>
- T zeta_polynomial_series(T s, T sc, int digits)
- {
- BOOST_MATH_STD_USING
-
-
-
-
-
-
-
- BOOST_MATH_STD_USING
- int n = (digits * 19) / 53;
- T sum = 0;
- T two_n = ldexp(T(1), n);
- int ej_sign = 1;
- for(int j = 0; j < n; ++j)
- {
- sum += ej_sign * -two_n / pow(T(j + 1), s);
- ej_sign = -ej_sign;
- }
- T ej_sum = 1;
- T ej_term = 1;
- for(int j = n; j <= 2 * n - 1; ++j)
- {
- sum += ej_sign * (ej_sum - two_n) / pow(T(j + 1), s);
- ej_sign = -ej_sign;
- ej_term *= 2 * n - j;
- ej_term /= j - n + 1;
- ej_sum += ej_term;
- }
- return -sum / (two_n * (1 - pow(T(2), sc)));
- }
- template <class T>
- T khinchin(int digits)
- {
- BOOST_MATH_STD_USING
- T sum = 0;
- T term;
- T lim = ldexp(T(1), 1-digits);
- T factor = 0;
- unsigned last_k = 1;
- T num = 1;
- for(unsigned n = 1;; ++n)
- {
- for(unsigned k = last_k; k <= 2 * n - 1; ++k)
- {
- factor += num / k;
- num = -num;
- }
- last_k = 2 * n;
- term = (zeta_polynomial_series(T(2 * n), T(1 - T(2 * n)), digits) - 1) * factor / n;
- sum += term;
- if(term < lim)
- break;
- }
- return exp(sum / boost::math::constants::ln_two<T, boost::math::policies::policy<> >());
- }
- }
- template <class T>
- template<int N>
- inline T constant_khinchin<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- int n = N ? (std::min)(N, tools::digits<T>()) : tools::digits<T>();
- return khinchin_detail::khinchin<T>(n);
- }
- template <class T>
- template<int N>
- inline T constant_extreme_value_skewness<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- T ev(12 * sqrt(static_cast<T>(6)) * zeta_three<T, policies::policy<policies::digits2<N> > >()
- / pi_cubed<T, policies::policy<policies::digits2<N> > >() );
- return ev;
- }
- namespace detail{
- template <class T>
- T zeta_series_derivative_2(unsigned digits)
- {
-
- BOOST_MATH_STD_USING
- int n = digits * 301 * 13 / 10000;
- T d = pow(3 + sqrt(T(8)), n);
- d = (d + 1 / d) / 2;
- T b = -1;
- T c = -d;
- T s = 0;
- for(int k = 0; k < n; ++k)
- {
- T a = -log(T(k+1)) / ((k+1) * (k+1));
- c = b - c;
- s = s + c * a;
- b = (k + n) * (k - n) * b / ((k + T(0.5f)) * (k + 1));
- }
- return s / d;
- }
- template <class T>
- T zeta_series_2(unsigned digits)
- {
-
- BOOST_MATH_STD_USING
- int n = digits * 301 * 13 / 10000;
- T d = pow(3 + sqrt(T(8)), n);
- d = (d + 1 / d) / 2;
- T b = -1;
- T c = -d;
- T s = 0;
- for(int k = 0; k < n; ++k)
- {
- T a = T(1) / ((k + 1) * (k + 1));
- c = b - c;
- s = s + c * a;
- b = (k + n) * (k - n) * b / ((k + T(0.5f)) * (k + 1));
- }
- return s / d;
- }
- template <class T>
- inline T zeta_series_lead_2()
- {
-
- return 2;
- }
- template <class T>
- inline T zeta_series_derivative_lead_2()
- {
-
- return -2 * boost::math::constants::ln_two<T>();
- }
- template <class T>
- inline T zeta_derivative_2(unsigned n)
- {
-
- return zeta_series_derivative_2<T>(n) * zeta_series_lead_2<T>()
- + zeta_series_derivative_lead_2<T>() * zeta_series_2<T>(n);
- }
- }
- template <class T>
- template<int N>
- inline T constant_glaisher<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- BOOST_MATH_STD_USING
- typedef policies::policy<policies::digits2<N> > forwarding_policy;
- int n = N ? (std::min)(N, tools::digits<T>()) : tools::digits<T>();
- T v = detail::zeta_derivative_2<T>(n);
- v *= 6;
- v /= boost::math::constants::pi<T, forwarding_policy>() * boost::math::constants::pi<T, forwarding_policy>();
- v -= boost::math::constants::euler<T, forwarding_policy>();
- v -= log(2 * boost::math::constants::pi<T, forwarding_policy>());
- v /= -12;
- return exp(v);
-
- }
- template <class T>
- template<int N>
- inline T constant_rayleigh_skewness<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
- BOOST_MATH_STD_USING
- T rs(2 * root_pi<T, policies::policy<policies::digits2<N> > >()
- * pi_minus_three<T, policies::policy<policies::digits2<N> > >()
- / pow(four_minus_pi<T, policies::policy<policies::digits2<N> > >(), static_cast<T>(3./2))
- );
-
-
-
-
-
-
-
-
-
-
-
-
- return rs;
- }
- template <class T>
- template<int N>
- inline T constant_rayleigh_kurtosis_excess<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
- BOOST_MATH_STD_USING
- return - (((static_cast<T>(6) * pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >())
- - (static_cast<T>(24) * pi<T, policies::policy<policies::digits2<N> > >()) + static_cast<T>(16) )
- /
- ((pi<T, policies::policy<policies::digits2<N> > >() - static_cast<T>(4))
- * (pi<T, policies::policy<policies::digits2<N> > >() - static_cast<T>(4)))
- );
- }
- template <class T>
- template<int N>
- inline T constant_rayleigh_kurtosis<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
- BOOST_MATH_STD_USING
- return static_cast<T>(3) - (((static_cast<T>(6) * pi<T, policies::policy<policies::digits2<N> > >()
- * pi<T, policies::policy<policies::digits2<N> > >())
- - (static_cast<T>(24) * pi<T, policies::policy<policies::digits2<N> > >()) + static_cast<T>(16) )
- /
- ((pi<T, policies::policy<policies::digits2<N> > >() - static_cast<T>(4))
- * (pi<T, policies::policy<policies::digits2<N> > >() - static_cast<T>(4)))
- );
- }
- template <class T>
- template<int N>
- inline T constant_log2_e<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 1 / boost::math::constants::ln_two<T>();
- }
- template <class T>
- template<int N>
- inline T constant_quarter_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return boost::math::constants::pi<T>() / 4;
- }
- template <class T>
- template<int N>
- inline T constant_one_div_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 1 / boost::math::constants::pi<T>();
- }
- template <class T>
- template<int N>
- inline T constant_two_div_root_pi<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- return 2 * boost::math::constants::one_div_root_pi<T>();
- }
- #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
- template <class T>
- template<int N>
- inline T constant_first_feigenbaum<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
- BOOST_STATIC_ASSERT_MSG(N < 3.321*1018, "\nThe first Feigenbaum constant cannot be computed at runtime; it is too expensive. It is known to 1018 decimal digits; you must request less than that.");
- T alpha{"4.6692016091029906718532038204662016172581855774757686327456513430041343302113147371386897440239480138171659848551898151344086271420279325223124429888908908599449354632367134115324817142199474556443658237932020095610583305754586176522220703854106467494942849814533917262005687556659523398756038256372256480040951071283890611844702775854285419801113440175002428585382498335715522052236087250291678860362674527213399057131606875345083433934446103706309452019115876972432273589838903794946257251289097948986768334611626889116563123474460575179539122045562472807095202198199094558581946136877445617396074115614074243754435499204869180982648652368438702799649017397793425134723808737136211601860128186102056381818354097598477964173900328936171432159878240789776614391395764037760537119096932066998361984288981837003229412030210655743295550388845849737034727532121925706958414074661841981961006129640161487712944415901405467941800198133253378592493365883070459999938375411726563553016862529032210862320550634510679399023341675"};
- return alpha;
- }
- template <class T>
- template<int N>
- inline T constant_plastic<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- using std::cbrt;
- using std::sqrt;
- return (cbrt(9-sqrt(T(69))) + cbrt(9+sqrt(T(69))))/cbrt(T(18));
- }
- template <class T>
- template<int N>
- inline T constant_gauss<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
- using std::sqrt;
- T a = sqrt(T(2));
- T g = 1;
- const T scale = sqrt(std::numeric_limits<T>::epsilon())/512;
- while (a-g > scale*g)
- {
- T anp1 = (a + g)/2;
- g = sqrt(a*g);
- a = anp1;
- }
- return 2/(a + g);
- }
- template <class T>
- template<int N>
- inline T constant_dottie<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
- using std::cos;
- using std::abs;
- using std::sin;
- T x{".739085133215160641655312087673873404013411758900757464965680635773284654883547594599376106931766531849801246"};
- T residual = cos(x) - x;
- do {
- x += residual/(sin(x)+1);
- residual = cos(x) - x;
- } while(abs(residual) > std::numeric_limits<T>::epsilon());
- return x;
- }
- template <class T>
- template<int N>
- inline T constant_reciprocal_fibonacci<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
- T x0 = 1;
- T x1 = 1;
- T sum = 2;
- T diff = 1;
- while (diff > std::numeric_limits<T>::epsilon()) {
- T tmp = x1 + x0;
- diff = 1/tmp;
- sum += diff;
- x0 = x1;
- x1 = tmp;
- }
- return sum;
- }
- template <class T>
- template<int N>
- inline T constant_laplace_limit<T>::compute(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC((std::integral_constant<int, N>)))
- {
-
-
-
-
- using std::abs;
- using std::exp;
- using std::sqrt;
- T x{"0.66274341934918158097474209710925290705623354911502241752039253499097185308651127724965480259895818168"};
- T tmp = sqrt(1+x*x);
- T etmp = exp(tmp);
- T residual = x*exp(tmp) - 1 - tmp;
- T df = etmp -x/tmp + etmp*x*x/tmp;
- do {
- x -= residual/df;
- tmp = sqrt(1+x*x);
- etmp = exp(tmp);
- residual = x*exp(tmp) - 1 - tmp;
- df = etmp -x/tmp + etmp*x*x/tmp;
- } while(abs(residual) > 2*std::numeric_limits<T>::epsilon());
- return x;
- }
- #endif
- }
- }
- }
- }
- #endif
|