12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109 |
- #ifndef BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
- #define BOOST_MATH_CALCULATE_CONSTANTS_CONSTANTS_INCLUDED
- #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>)))
- {
-
-
-
-
- static_assert(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::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
|