Debian Codegraph @

third-party/boost-math/include/boost/math/special_functions/detail/unchecked_factorial.hpp

raw
1 // Copyright John Maddock 2006.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_MATH_SP_UC_FACTORIALS_HPP
7 #define BOOST_MATH_SP_UC_FACTORIALS_HPP
8
9 #ifdef _MSC_VER
10 #pragma once
11 #endif
12
13 #include <boost/math/tools/config.hpp>
14 #include <boost/math/tools/type_traits.hpp>
15 #include <boost/math/tools/array.hpp>
16 #include <boost/math/tools/numeric_limits.hpp>
17 #include <boost/math/special_functions/math_fwd.hpp>
18
19 #ifndef BOOST_MATH_HAS_GPU_SUPPORT
20 # ifdef _MSC_VER
21 # pragma warning(push) // Temporary until lexical cast fixed.
22 # pragma warning(disable: 4127 4701)
23 # endif
24 # include <boost/math/tools/convert_from_string.hpp>
25 # ifdef _MSC_VER
26 # pragma warning(pop)
27 # endif
28 #endif
29
30
31 #if defined(__GNUC__) && defined(BOOST_MATH_USE_FLOAT128)
32 //
33 // This is the only way we can avoid
34 // warning: non-standard suffix on floating constant [-Wpedantic]
35 // when building with -Wall -pedantic. Neither __extension__
36 // nor #pragma diagnostic ignored work :(
37 //
38 #pragma GCC system_header
39 #endif
40
41 namespace boost { namespace math
42 {
43 // Forward declarations:
44 template <class T>
45 struct max_factorial;
46 //
47 // see https://github.com/boostorg/math/issues/923
48 // for the rationale behin using struct's for constexpr data:
49 //
50 template <class T, bool = true>
51 struct unchecked_factorial_data;
52
53 #ifdef BOOST_MATH_HAS_NVRTC
54
55 // Need fwd decl
56 template <typename T>
57 BOOST_MATH_GPU_ENABLED inline T unchecked_factorial(unsigned i);
58
59 #endif
60
61 #ifndef BOOST_MATH_HAS_GPU_SUPPORT
62
63 template <bool b>
64 struct unchecked_factorial_data<float, b>
65 {
66 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
67 static constexpr boost::math::array<float, 35> factorials = { {
68 1.0F,
69 1.0F,
70 2.0F,
71 6.0F,
72 24.0F,
73 120.0F,
74 720.0F,
75 5040.0F,
76 40320.0F,
77 362880.0F,
78 3628800.0F,
79 39916800.0F,
80 479001600.0F,
81 6227020800.0F,
82 87178291200.0F,
83 1307674368000.0F,
84 20922789888000.0F,
85 355687428096000.0F,
86 6402373705728000.0F,
87 121645100408832000.0F,
88 0.243290200817664e19F,
89 0.5109094217170944e20F,
90 0.112400072777760768e22F,
91 0.2585201673888497664e23F,
92 0.62044840173323943936e24F,
93 0.15511210043330985984e26F,
94 0.403291461126605635584e27F,
95 0.10888869450418352160768e29F,
96 0.304888344611713860501504e30F,
97 0.8841761993739701954543616e31F,
98 0.26525285981219105863630848e33F,
99 0.822283865417792281772556288e34F,
100 0.26313083693369353016721801216e36F,
101 0.868331761881188649551819440128e37F,
102 0.29523279903960414084761860964352e39F,
103 }};
104 #else
105 static const boost::math::array<float, 35> factorials;
106 #endif
107 };
108
109 template<bool b>
110 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
111 constexpr boost::math::array<float, 35> unchecked_factorial_data<float, b>::factorials;
112 #else
113 const boost::math::array<float, 35> unchecked_factorial_data<float, b>::factorials = {{
114 1.0F,
115 1.0F,
116 2.0F,
117 6.0F,
118 24.0F,
119 120.0F,
120 720.0F,
121 5040.0F,
122 40320.0F,
123 362880.0F,
124 3628800.0F,
125 39916800.0F,
126 479001600.0F,
127 6227020800.0F,
128 87178291200.0F,
129 1307674368000.0F,
130 20922789888000.0F,
131 355687428096000.0F,
132 6402373705728000.0F,
133 121645100408832000.0F,
134 0.243290200817664e19F,
135 0.5109094217170944e20F,
136 0.112400072777760768e22F,
137 0.2585201673888497664e23F,
138 0.62044840173323943936e24F,
139 0.15511210043330985984e26F,
140 0.403291461126605635584e27F,
141 0.10888869450418352160768e29F,
142 0.304888344611713860501504e30F,
143 0.8841761993739701954543616e31F,
144 0.26525285981219105863630848e33F,
145 0.822283865417792281772556288e34F,
146 0.26313083693369353016721801216e36F,
147 0.868331761881188649551819440128e37F,
148 0.29523279903960414084761860964352e39F,
149 }};
150 #endif
151
152 // Definitions:
153 template <>
154 BOOST_MATH_GPU_ENABLED inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION float unchecked_factorial<float>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
155 {
156 return unchecked_factorial_data<float>::factorials[i];
157 }
158
159 #else
160
161 template <>
162 BOOST_MATH_GPU_ENABLED inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION float unchecked_factorial<float>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
163 {
164 constexpr float factorials[] = {
165 1.0F,
166 1.0F,
167 2.0F,
168 6.0F,
169 24.0F,
170 120.0F,
171 720.0F,
172 5040.0F,
173 40320.0F,
174 362880.0F,
175 3628800.0F,
176 39916800.0F,
177 479001600.0F,
178 6227020800.0F,
179 87178291200.0F,
180 1307674368000.0F,
181 20922789888000.0F,
182 355687428096000.0F,
183 6402373705728000.0F,
184 121645100408832000.0F,
185 0.243290200817664e19F,
186 0.5109094217170944e20F,
187 0.112400072777760768e22F,
188 0.2585201673888497664e23F,
189 0.62044840173323943936e24F,
190 0.15511210043330985984e26F,
191 0.403291461126605635584e27F,
192 0.10888869450418352160768e29F,
193 0.304888344611713860501504e30F,
194 0.8841761993739701954543616e31F,
195 0.26525285981219105863630848e33F,
196 0.822283865417792281772556288e34F,
197 0.26313083693369353016721801216e36F,
198 0.868331761881188649551819440128e37F,
199 0.29523279903960414084761860964352e39F,
200 };
201
202 return factorials[i];
203 }
204
205 #endif
206
207 template <>
208 struct max_factorial<float>
209 {
210 static constexpr unsigned value = 34;
211 };
212
213 #ifndef BOOST_MATH_HAS_GPU_SUPPORT
214
215 template <bool b>
216 struct unchecked_factorial_data<double, b>
217 {
218 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
219 static constexpr boost::math::array<double, 171> factorials = { {
220 1.0,
221 1.0,
222 2.0,
223 6.0,
224 24.0,
225 120.0,
226 720.0,
227 5040.0,
228 40320.0,
229 362880.0,
230 3628800.0,
231 39916800.0,
232 479001600.0,
233 6227020800.0,
234 87178291200.0,
235 1307674368000.0,
236 20922789888000.0,
237 355687428096000.0,
238 6402373705728000.0,
239 121645100408832000.0,
240 0.243290200817664e19,
241 0.5109094217170944e20,
242 0.112400072777760768e22,
243 0.2585201673888497664e23,
244 0.62044840173323943936e24,
245 0.15511210043330985984e26,
246 0.403291461126605635584e27,
247 0.10888869450418352160768e29,
248 0.304888344611713860501504e30,
249 0.8841761993739701954543616e31,
250 0.26525285981219105863630848e33,
251 0.822283865417792281772556288e34,
252 0.26313083693369353016721801216e36,
253 0.868331761881188649551819440128e37,
254 0.29523279903960414084761860964352e39,
255 0.103331479663861449296666513375232e41,
256 0.3719933267899012174679994481508352e42,
257 0.137637530912263450463159795815809024e44,
258 0.5230226174666011117600072241000742912e45,
259 0.203978820811974433586402817399028973568e47,
260 0.815915283247897734345611269596115894272e48,
261 0.3345252661316380710817006205344075166515e50,
262 0.1405006117752879898543142606244511569936e52,
263 0.6041526306337383563735513206851399750726e53,
264 0.265827157478844876804362581101461589032e55,
265 0.1196222208654801945619631614956577150644e57,
266 0.5502622159812088949850305428800254892962e58,
267 0.2586232415111681806429643551536119799692e60,
268 0.1241391559253607267086228904737337503852e62,
269 0.6082818640342675608722521633212953768876e63,
270 0.3041409320171337804361260816606476884438e65,
271 0.1551118753287382280224243016469303211063e67,
272 0.8065817517094387857166063685640376697529e68,
273 0.427488328406002556429801375338939964969e70,
274 0.2308436973392413804720927426830275810833e72,
275 0.1269640335365827592596510084756651695958e74,
276 0.7109985878048634518540456474637249497365e75,
277 0.4052691950487721675568060190543232213498e77,
278 0.2350561331282878571829474910515074683829e79,
279 0.1386831185456898357379390197203894063459e81,
280 0.8320987112741390144276341183223364380754e82,
281 0.507580213877224798800856812176625227226e84,
282 0.3146997326038793752565312235495076408801e86,
283 0.1982608315404440064116146708361898137545e88,
284 0.1268869321858841641034333893351614808029e90,
285 0.8247650592082470666723170306785496252186e91,
286 0.5443449390774430640037292402478427526443e93,
287 0.3647111091818868528824985909660546442717e95,
288 0.2480035542436830599600990418569171581047e97,
289 0.1711224524281413113724683388812728390923e99,
290 0.1197857166996989179607278372168909873646e101,
291 0.8504785885678623175211676442399260102886e102,
292 0.6123445837688608686152407038527467274078e104,
293 0.4470115461512684340891257138125051110077e106,
294 0.3307885441519386412259530282212537821457e108,
295 0.2480914081139539809194647711659403366093e110,
296 0.188549470166605025498793226086114655823e112,
297 0.1451830920282858696340707840863082849837e114,
298 0.1132428117820629783145752115873204622873e116,
299 0.8946182130782975286851441715398316520698e117,
300 0.7156945704626380229481153372318653216558e119,
301 0.5797126020747367985879734231578109105412e121,
302 0.4753643337012841748421382069894049466438e123,
303 0.3945523969720658651189747118012061057144e125,
304 0.3314240134565353266999387579130131288001e127,
305 0.2817104114380550276949479442260611594801e129,
306 0.2422709538367273238176552320344125971528e131,
307 0.210775729837952771721360051869938959523e133,
308 0.1854826422573984391147968456455462843802e135,
309 0.1650795516090846108121691926245361930984e137,
310 0.1485715964481761497309522733620825737886e139,
311 0.1352001527678402962551665687594951421476e141,
312 0.1243841405464130725547532432587355307758e143,
313 0.1156772507081641574759205162306240436215e145,
314 0.1087366156656743080273652852567866010042e147,
315 0.103299784882390592625997020993947270954e149,
316 0.9916779348709496892095714015418938011582e150,
317 0.9619275968248211985332842594956369871234e152,
318 0.942689044888324774562618574305724247381e154,
319 0.9332621544394415268169923885626670049072e156,
320 0.9332621544394415268169923885626670049072e158,
321 0.9425947759838359420851623124482936749562e160,
322 0.9614466715035126609268655586972595484554e162,
323 0.990290071648618040754671525458177334909e164,
324 0.1029901674514562762384858386476504428305e167,
325 0.1081396758240290900504101305800329649721e169,
326 0.1146280563734708354534347384148349428704e171,
327 0.1226520203196137939351751701038733888713e173,
328 0.132464181945182897449989183712183259981e175,
329 0.1443859583202493582204882102462797533793e177,
330 0.1588245541522742940425370312709077287172e179,
331 0.1762952551090244663872161047107075788761e181,
332 0.1974506857221074023536820372759924883413e183,
333 0.2231192748659813646596607021218715118256e185,
334 0.2543559733472187557120132004189335234812e187,
335 0.2925093693493015690688151804817735520034e189,
336 0.339310868445189820119825609358857320324e191,
337 0.396993716080872089540195962949863064779e193,
338 0.4684525849754290656574312362808384164393e195,
339 0.5574585761207605881323431711741977155627e197,
340 0.6689502913449127057588118054090372586753e199,
341 0.8094298525273443739681622845449350829971e201,
342 0.9875044200833601362411579871448208012564e203,
343 0.1214630436702532967576624324188129585545e206,
344 0.1506141741511140879795014161993280686076e208,
345 0.1882677176888926099743767702491600857595e210,
346 0.237217324288004688567714730513941708057e212,
347 0.3012660018457659544809977077527059692324e214,
348 0.3856204823625804217356770659234636406175e216,
349 0.4974504222477287440390234150412680963966e218,
350 0.6466855489220473672507304395536485253155e220,
351 0.8471580690878820510984568758152795681634e222,
352 0.1118248651196004307449963076076169029976e225,
353 0.1487270706090685728908450891181304809868e227,
354 0.1992942746161518876737324194182948445223e229,
355 0.269047270731805048359538766214698040105e231,
356 0.3659042881952548657689727220519893345429e233,
357 0.5012888748274991661034926292112253883237e235,
358 0.6917786472619488492228198283114910358867e237,
359 0.9615723196941089004197195613529725398826e239,
360 0.1346201247571752460587607385894161555836e242,
361 0.1898143759076170969428526414110767793728e244,
362 0.2695364137888162776588507508037290267094e246,
363 0.3854370717180072770521565736493325081944e248,
364 0.5550293832739304789551054660550388118e250,
365 0.80479260574719919448490292577980627711e252,
366 0.1174997204390910823947958271638517164581e255,
367 0.1727245890454638911203498659308620231933e257,
368 0.2556323917872865588581178015776757943262e259,
369 0.380892263763056972698595524350736933546e261,
370 0.571338395644585459047893286526105400319e263,
371 0.8627209774233240431623188626544191544816e265,
372 0.1311335885683452545606724671234717114812e268,
373 0.2006343905095682394778288746989117185662e270,
374 0.308976961384735088795856467036324046592e272,
375 0.4789142901463393876335775239063022722176e274,
376 0.7471062926282894447083809372938315446595e276,
377 0.1172956879426414428192158071551315525115e279,
378 0.1853271869493734796543609753051078529682e281,
379 0.2946702272495038326504339507351214862195e283,
380 0.4714723635992061322406943211761943779512e285,
381 0.7590705053947218729075178570936729485014e287,
382 0.1229694218739449434110178928491750176572e290,
383 0.2004401576545302577599591653441552787813e292,
384 0.3287218585534296227263330311644146572013e294,
385 0.5423910666131588774984495014212841843822e296,
386 0.9003691705778437366474261723593317460744e298,
387 0.1503616514864999040201201707840084015944e301,
388 0.2526075744973198387538018869171341146786e303,
389 0.4269068009004705274939251888899566538069e305,
390 0.7257415615307998967396728211129263114717e307,
391 }};
392 #else
393 static const boost::math::array<double, 171> factorials;
394 #endif
395 };
396
397 template <bool b>
398 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
399 constexpr boost::math::array<double, 171> unchecked_factorial_data<double, b>::factorials;
400 #else
401 const boost::math::array<double, 171> unchecked_factorial_data<double, b>::factorials = {{
402 1.0,
403 1.0,
404 2.0,
405 6.0,
406 24.0,
407 120.0,
408 720.0,
409 5040.0,
410 40320.0,
411 362880.0,
412 3628800.0,
413 39916800.0,
414 479001600.0,
415 6227020800.0,
416 87178291200.0,
417 1307674368000.0,
418 20922789888000.0,
419 355687428096000.0,
420 6402373705728000.0,
421 121645100408832000.0,
422 0.243290200817664e19,
423 0.5109094217170944e20,
424 0.112400072777760768e22,
425 0.2585201673888497664e23,
426 0.62044840173323943936e24,
427 0.15511210043330985984e26,
428 0.403291461126605635584e27,
429 0.10888869450418352160768e29,
430 0.304888344611713860501504e30,
431 0.8841761993739701954543616e31,
432 0.26525285981219105863630848e33,
433 0.822283865417792281772556288e34,
434 0.26313083693369353016721801216e36,
435 0.868331761881188649551819440128e37,
436 0.29523279903960414084761860964352e39,
437 0.103331479663861449296666513375232e41,
438 0.3719933267899012174679994481508352e42,
439 0.137637530912263450463159795815809024e44,
440 0.5230226174666011117600072241000742912e45,
441 0.203978820811974433586402817399028973568e47,
442 0.815915283247897734345611269596115894272e48,
443 0.3345252661316380710817006205344075166515e50,
444 0.1405006117752879898543142606244511569936e52,
445 0.6041526306337383563735513206851399750726e53,
446 0.265827157478844876804362581101461589032e55,
447 0.1196222208654801945619631614956577150644e57,
448 0.5502622159812088949850305428800254892962e58,
449 0.2586232415111681806429643551536119799692e60,
450 0.1241391559253607267086228904737337503852e62,
451 0.6082818640342675608722521633212953768876e63,
452 0.3041409320171337804361260816606476884438e65,
453 0.1551118753287382280224243016469303211063e67,
454 0.8065817517094387857166063685640376697529e68,
455 0.427488328406002556429801375338939964969e70,
456 0.2308436973392413804720927426830275810833e72,
457 0.1269640335365827592596510084756651695958e74,
458 0.7109985878048634518540456474637249497365e75,
459 0.4052691950487721675568060190543232213498e77,
460 0.2350561331282878571829474910515074683829e79,
461 0.1386831185456898357379390197203894063459e81,
462 0.8320987112741390144276341183223364380754e82,
463 0.507580213877224798800856812176625227226e84,
464 0.3146997326038793752565312235495076408801e86,
465 0.1982608315404440064116146708361898137545e88,
466 0.1268869321858841641034333893351614808029e90,
467 0.8247650592082470666723170306785496252186e91,
468 0.5443449390774430640037292402478427526443e93,
469 0.3647111091818868528824985909660546442717e95,
470 0.2480035542436830599600990418569171581047e97,
471 0.1711224524281413113724683388812728390923e99,
472 0.1197857166996989179607278372168909873646e101,
473 0.8504785885678623175211676442399260102886e102,
474 0.6123445837688608686152407038527467274078e104,
475 0.4470115461512684340891257138125051110077e106,
476 0.3307885441519386412259530282212537821457e108,
477 0.2480914081139539809194647711659403366093e110,
478 0.188549470166605025498793226086114655823e112,
479 0.1451830920282858696340707840863082849837e114,
480 0.1132428117820629783145752115873204622873e116,
481 0.8946182130782975286851441715398316520698e117,
482 0.7156945704626380229481153372318653216558e119,
483 0.5797126020747367985879734231578109105412e121,
484 0.4753643337012841748421382069894049466438e123,
485 0.3945523969720658651189747118012061057144e125,
486 0.3314240134565353266999387579130131288001e127,
487 0.2817104114380550276949479442260611594801e129,
488 0.2422709538367273238176552320344125971528e131,
489 0.210775729837952771721360051869938959523e133,
490 0.1854826422573984391147968456455462843802e135,
491 0.1650795516090846108121691926245361930984e137,
492 0.1485715964481761497309522733620825737886e139,
493 0.1352001527678402962551665687594951421476e141,
494 0.1243841405464130725547532432587355307758e143,
495 0.1156772507081641574759205162306240436215e145,
496 0.1087366156656743080273652852567866010042e147,
497 0.103299784882390592625997020993947270954e149,
498 0.9916779348709496892095714015418938011582e150,
499 0.9619275968248211985332842594956369871234e152,
500 0.942689044888324774562618574305724247381e154,
501 0.9332621544394415268169923885626670049072e156,
502 0.9332621544394415268169923885626670049072e158,
503 0.9425947759838359420851623124482936749562e160,
504 0.9614466715035126609268655586972595484554e162,
505 0.990290071648618040754671525458177334909e164,
506 0.1029901674514562762384858386476504428305e167,
507 0.1081396758240290900504101305800329649721e169,
508 0.1146280563734708354534347384148349428704e171,
509 0.1226520203196137939351751701038733888713e173,
510 0.132464181945182897449989183712183259981e175,
511 0.1443859583202493582204882102462797533793e177,
512 0.1588245541522742940425370312709077287172e179,
513 0.1762952551090244663872161047107075788761e181,
514 0.1974506857221074023536820372759924883413e183,
515 0.2231192748659813646596607021218715118256e185,
516 0.2543559733472187557120132004189335234812e187,
517 0.2925093693493015690688151804817735520034e189,
518 0.339310868445189820119825609358857320324e191,
519 0.396993716080872089540195962949863064779e193,
520 0.4684525849754290656574312362808384164393e195,
521 0.5574585761207605881323431711741977155627e197,
522 0.6689502913449127057588118054090372586753e199,
523 0.8094298525273443739681622845449350829971e201,
524 0.9875044200833601362411579871448208012564e203,
525 0.1214630436702532967576624324188129585545e206,
526 0.1506141741511140879795014161993280686076e208,
527 0.1882677176888926099743767702491600857595e210,
528 0.237217324288004688567714730513941708057e212,
529 0.3012660018457659544809977077527059692324e214,
530 0.3856204823625804217356770659234636406175e216,
531 0.4974504222477287440390234150412680963966e218,
532 0.6466855489220473672507304395536485253155e220,
533 0.8471580690878820510984568758152795681634e222,
534 0.1118248651196004307449963076076169029976e225,
535 0.1487270706090685728908450891181304809868e227,
536 0.1992942746161518876737324194182948445223e229,
537 0.269047270731805048359538766214698040105e231,
538 0.3659042881952548657689727220519893345429e233,
539 0.5012888748274991661034926292112253883237e235,
540 0.6917786472619488492228198283114910358867e237,
541 0.9615723196941089004197195613529725398826e239,
542 0.1346201247571752460587607385894161555836e242,
543 0.1898143759076170969428526414110767793728e244,
544 0.2695364137888162776588507508037290267094e246,
545 0.3854370717180072770521565736493325081944e248,
546 0.5550293832739304789551054660550388118e250,
547 0.80479260574719919448490292577980627711e252,
548 0.1174997204390910823947958271638517164581e255,
549 0.1727245890454638911203498659308620231933e257,
550 0.2556323917872865588581178015776757943262e259,
551 0.380892263763056972698595524350736933546e261,
552 0.571338395644585459047893286526105400319e263,
553 0.8627209774233240431623188626544191544816e265,
554 0.1311335885683452545606724671234717114812e268,
555 0.2006343905095682394778288746989117185662e270,
556 0.308976961384735088795856467036324046592e272,
557 0.4789142901463393876335775239063022722176e274,
558 0.7471062926282894447083809372938315446595e276,
559 0.1172956879426414428192158071551315525115e279,
560 0.1853271869493734796543609753051078529682e281,
561 0.2946702272495038326504339507351214862195e283,
562 0.4714723635992061322406943211761943779512e285,
563 0.7590705053947218729075178570936729485014e287,
564 0.1229694218739449434110178928491750176572e290,
565 0.2004401576545302577599591653441552787813e292,
566 0.3287218585534296227263330311644146572013e294,
567 0.5423910666131588774984495014212841843822e296,
568 0.9003691705778437366474261723593317460744e298,
569 0.1503616514864999040201201707840084015944e301,
570 0.2526075744973198387538018869171341146786e303,
571 0.4269068009004705274939251888899566538069e305,
572 0.7257415615307998967396728211129263114717e307,
573 }};
574 #endif
575
576 template <>
577 BOOST_MATH_GPU_ENABLED inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION double unchecked_factorial<double>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
578 {
579 return unchecked_factorial_data<double>::factorials[i];
580 }
581
582 template <>
583 struct max_factorial<double>
584 {
585 static constexpr unsigned value = 170;
586 };
587
588 #else
589
590 template <>
591 BOOST_MATH_GPU_ENABLED inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION double unchecked_factorial<double>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(double))
592 {
593 constexpr double factorials[] = {
594 1,
595 1,
596 2,
597 6,
598 24,
599 120,
600 720,
601 5040,
602 40320,
603 362880.0,
604 3628800.0,
605 39916800.0,
606 479001600.0,
607 6227020800.0,
608 87178291200.0,
609 1307674368000.0,
610 20922789888000.0,
611 355687428096000.0,
612 6402373705728000.0,
613 121645100408832000.0,
614 0.243290200817664e19,
615 0.5109094217170944e20,
616 0.112400072777760768e22,
617 0.2585201673888497664e23,
618 0.62044840173323943936e24,
619 0.15511210043330985984e26,
620 0.403291461126605635584e27,
621 0.10888869450418352160768e29,
622 0.304888344611713860501504e30,
623 0.8841761993739701954543616e31,
624 0.26525285981219105863630848e33,
625 0.822283865417792281772556288e34,
626 0.26313083693369353016721801216e36,
627 0.868331761881188649551819440128e37,
628 0.29523279903960414084761860964352e39,
629 };
630
631 return factorials[i];
632 }
633
634 template <>
635 struct max_factorial<double>
636 {
637 static constexpr unsigned value = 34;
638 };
639
640 #endif
641
642 #ifndef BOOST_MATH_HAS_GPU_SUPPORT
643
644 template <bool b>
645 struct unchecked_factorial_data<long double, b>
646 {
647 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
648 static constexpr boost::math::array<long double, 171> factorials = { {
649 1L,
650 1L,
651 2L,
652 6L,
653 24L,
654 120L,
655 720L,
656 5040L,
657 40320L,
658 362880.0L,
659 3628800.0L,
660 39916800.0L,
661 479001600.0L,
662 6227020800.0L,
663 87178291200.0L,
664 1307674368000.0L,
665 20922789888000.0L,
666 355687428096000.0L,
667 6402373705728000.0L,
668 121645100408832000.0L,
669 0.243290200817664e19L,
670 0.5109094217170944e20L,
671 0.112400072777760768e22L,
672 0.2585201673888497664e23L,
673 0.62044840173323943936e24L,
674 0.15511210043330985984e26L,
675 0.403291461126605635584e27L,
676 0.10888869450418352160768e29L,
677 0.304888344611713860501504e30L,
678 0.8841761993739701954543616e31L,
679 0.26525285981219105863630848e33L,
680 0.822283865417792281772556288e34L,
681 0.26313083693369353016721801216e36L,
682 0.868331761881188649551819440128e37L,
683 0.29523279903960414084761860964352e39L,
684 0.103331479663861449296666513375232e41L,
685 0.3719933267899012174679994481508352e42L,
686 0.137637530912263450463159795815809024e44L,
687 0.5230226174666011117600072241000742912e45L,
688 0.203978820811974433586402817399028973568e47L,
689 0.815915283247897734345611269596115894272e48L,
690 0.3345252661316380710817006205344075166515e50L,
691 0.1405006117752879898543142606244511569936e52L,
692 0.6041526306337383563735513206851399750726e53L,
693 0.265827157478844876804362581101461589032e55L,
694 0.1196222208654801945619631614956577150644e57L,
695 0.5502622159812088949850305428800254892962e58L,
696 0.2586232415111681806429643551536119799692e60L,
697 0.1241391559253607267086228904737337503852e62L,
698 0.6082818640342675608722521633212953768876e63L,
699 0.3041409320171337804361260816606476884438e65L,
700 0.1551118753287382280224243016469303211063e67L,
701 0.8065817517094387857166063685640376697529e68L,
702 0.427488328406002556429801375338939964969e70L,
703 0.2308436973392413804720927426830275810833e72L,
704 0.1269640335365827592596510084756651695958e74L,
705 0.7109985878048634518540456474637249497365e75L,
706 0.4052691950487721675568060190543232213498e77L,
707 0.2350561331282878571829474910515074683829e79L,
708 0.1386831185456898357379390197203894063459e81L,
709 0.8320987112741390144276341183223364380754e82L,
710 0.507580213877224798800856812176625227226e84L,
711 0.3146997326038793752565312235495076408801e86L,
712 0.1982608315404440064116146708361898137545e88L,
713 0.1268869321858841641034333893351614808029e90L,
714 0.8247650592082470666723170306785496252186e91L,
715 0.5443449390774430640037292402478427526443e93L,
716 0.3647111091818868528824985909660546442717e95L,
717 0.2480035542436830599600990418569171581047e97L,
718 0.1711224524281413113724683388812728390923e99L,
719 0.1197857166996989179607278372168909873646e101L,
720 0.8504785885678623175211676442399260102886e102L,
721 0.6123445837688608686152407038527467274078e104L,
722 0.4470115461512684340891257138125051110077e106L,
723 0.3307885441519386412259530282212537821457e108L,
724 0.2480914081139539809194647711659403366093e110L,
725 0.188549470166605025498793226086114655823e112L,
726 0.1451830920282858696340707840863082849837e114L,
727 0.1132428117820629783145752115873204622873e116L,
728 0.8946182130782975286851441715398316520698e117L,
729 0.7156945704626380229481153372318653216558e119L,
730 0.5797126020747367985879734231578109105412e121L,
731 0.4753643337012841748421382069894049466438e123L,
732 0.3945523969720658651189747118012061057144e125L,
733 0.3314240134565353266999387579130131288001e127L,
734 0.2817104114380550276949479442260611594801e129L,
735 0.2422709538367273238176552320344125971528e131L,
736 0.210775729837952771721360051869938959523e133L,
737 0.1854826422573984391147968456455462843802e135L,
738 0.1650795516090846108121691926245361930984e137L,
739 0.1485715964481761497309522733620825737886e139L,
740 0.1352001527678402962551665687594951421476e141L,
741 0.1243841405464130725547532432587355307758e143L,
742 0.1156772507081641574759205162306240436215e145L,
743 0.1087366156656743080273652852567866010042e147L,
744 0.103299784882390592625997020993947270954e149L,
745 0.9916779348709496892095714015418938011582e150L,
746 0.9619275968248211985332842594956369871234e152L,
747 0.942689044888324774562618574305724247381e154L,
748 0.9332621544394415268169923885626670049072e156L,
749 0.9332621544394415268169923885626670049072e158L,
750 0.9425947759838359420851623124482936749562e160L,
751 0.9614466715035126609268655586972595484554e162L,
752 0.990290071648618040754671525458177334909e164L,
753 0.1029901674514562762384858386476504428305e167L,
754 0.1081396758240290900504101305800329649721e169L,
755 0.1146280563734708354534347384148349428704e171L,
756 0.1226520203196137939351751701038733888713e173L,
757 0.132464181945182897449989183712183259981e175L,
758 0.1443859583202493582204882102462797533793e177L,
759 0.1588245541522742940425370312709077287172e179L,
760 0.1762952551090244663872161047107075788761e181L,
761 0.1974506857221074023536820372759924883413e183L,
762 0.2231192748659813646596607021218715118256e185L,
763 0.2543559733472187557120132004189335234812e187L,
764 0.2925093693493015690688151804817735520034e189L,
765 0.339310868445189820119825609358857320324e191L,
766 0.396993716080872089540195962949863064779e193L,
767 0.4684525849754290656574312362808384164393e195L,
768 0.5574585761207605881323431711741977155627e197L,
769 0.6689502913449127057588118054090372586753e199L,
770 0.8094298525273443739681622845449350829971e201L,
771 0.9875044200833601362411579871448208012564e203L,
772 0.1214630436702532967576624324188129585545e206L,
773 0.1506141741511140879795014161993280686076e208L,
774 0.1882677176888926099743767702491600857595e210L,
775 0.237217324288004688567714730513941708057e212L,
776 0.3012660018457659544809977077527059692324e214L,
777 0.3856204823625804217356770659234636406175e216L,
778 0.4974504222477287440390234150412680963966e218L,
779 0.6466855489220473672507304395536485253155e220L,
780 0.8471580690878820510984568758152795681634e222L,
781 0.1118248651196004307449963076076169029976e225L,
782 0.1487270706090685728908450891181304809868e227L,
783 0.1992942746161518876737324194182948445223e229L,
784 0.269047270731805048359538766214698040105e231L,
785 0.3659042881952548657689727220519893345429e233L,
786 0.5012888748274991661034926292112253883237e235L,
787 0.6917786472619488492228198283114910358867e237L,
788 0.9615723196941089004197195613529725398826e239L,
789 0.1346201247571752460587607385894161555836e242L,
790 0.1898143759076170969428526414110767793728e244L,
791 0.2695364137888162776588507508037290267094e246L,
792 0.3854370717180072770521565736493325081944e248L,
793 0.5550293832739304789551054660550388118e250L,
794 0.80479260574719919448490292577980627711e252L,
795 0.1174997204390910823947958271638517164581e255L,
796 0.1727245890454638911203498659308620231933e257L,
797 0.2556323917872865588581178015776757943262e259L,
798 0.380892263763056972698595524350736933546e261L,
799 0.571338395644585459047893286526105400319e263L,
800 0.8627209774233240431623188626544191544816e265L,
801 0.1311335885683452545606724671234717114812e268L,
802 0.2006343905095682394778288746989117185662e270L,
803 0.308976961384735088795856467036324046592e272L,
804 0.4789142901463393876335775239063022722176e274L,
805 0.7471062926282894447083809372938315446595e276L,
806 0.1172956879426414428192158071551315525115e279L,
807 0.1853271869493734796543609753051078529682e281L,
808 0.2946702272495038326504339507351214862195e283L,
809 0.4714723635992061322406943211761943779512e285L,
810 0.7590705053947218729075178570936729485014e287L,
811 0.1229694218739449434110178928491750176572e290L,
812 0.2004401576545302577599591653441552787813e292L,
813 0.3287218585534296227263330311644146572013e294L,
814 0.5423910666131588774984495014212841843822e296L,
815 0.9003691705778437366474261723593317460744e298L,
816 0.1503616514864999040201201707840084015944e301L,
817 0.2526075744973198387538018869171341146786e303L,
818 0.4269068009004705274939251888899566538069e305L,
819 0.7257415615307998967396728211129263114717e307L,
820 }};
821 #else
822 static const boost::math::array<long double, 171> factorials;
823 #endif
824 };
825
826 template <bool b>
827 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
828 constexpr boost::math::array<long double, 171> unchecked_factorial_data<long double, b>::factorials;
829 #else
830 const boost::math::array<long double, 171> unchecked_factorial_data<long double, b>::factorials = {{
831 1L,
832 1L,
833 2L,
834 6L,
835 24L,
836 120L,
837 720L,
838 5040L,
839 40320L,
840 362880.0L,
841 3628800.0L,
842 39916800.0L,
843 479001600.0L,
844 6227020800.0L,
845 87178291200.0L,
846 1307674368000.0L,
847 20922789888000.0L,
848 355687428096000.0L,
849 6402373705728000.0L,
850 121645100408832000.0L,
851 0.243290200817664e19L,
852 0.5109094217170944e20L,
853 0.112400072777760768e22L,
854 0.2585201673888497664e23L,
855 0.62044840173323943936e24L,
856 0.15511210043330985984e26L,
857 0.403291461126605635584e27L,
858 0.10888869450418352160768e29L,
859 0.304888344611713860501504e30L,
860 0.8841761993739701954543616e31L,
861 0.26525285981219105863630848e33L,
862 0.822283865417792281772556288e34L,
863 0.26313083693369353016721801216e36L,
864 0.868331761881188649551819440128e37L,
865 0.29523279903960414084761860964352e39L,
866 0.103331479663861449296666513375232e41L,
867 0.3719933267899012174679994481508352e42L,
868 0.137637530912263450463159795815809024e44L,
869 0.5230226174666011117600072241000742912e45L,
870 0.203978820811974433586402817399028973568e47L,
871 0.815915283247897734345611269596115894272e48L,
872 0.3345252661316380710817006205344075166515e50L,
873 0.1405006117752879898543142606244511569936e52L,
874 0.6041526306337383563735513206851399750726e53L,
875 0.265827157478844876804362581101461589032e55L,
876 0.1196222208654801945619631614956577150644e57L,
877 0.5502622159812088949850305428800254892962e58L,
878 0.2586232415111681806429643551536119799692e60L,
879 0.1241391559253607267086228904737337503852e62L,
880 0.6082818640342675608722521633212953768876e63L,
881 0.3041409320171337804361260816606476884438e65L,
882 0.1551118753287382280224243016469303211063e67L,
883 0.8065817517094387857166063685640376697529e68L,
884 0.427488328406002556429801375338939964969e70L,
885 0.2308436973392413804720927426830275810833e72L,
886 0.1269640335365827592596510084756651695958e74L,
887 0.7109985878048634518540456474637249497365e75L,
888 0.4052691950487721675568060190543232213498e77L,
889 0.2350561331282878571829474910515074683829e79L,
890 0.1386831185456898357379390197203894063459e81L,
891 0.8320987112741390144276341183223364380754e82L,
892 0.507580213877224798800856812176625227226e84L,
893 0.3146997326038793752565312235495076408801e86L,
894 0.1982608315404440064116146708361898137545e88L,
895 0.1268869321858841641034333893351614808029e90L,
896 0.8247650592082470666723170306785496252186e91L,
897 0.5443449390774430640037292402478427526443e93L,
898 0.3647111091818868528824985909660546442717e95L,
899 0.2480035542436830599600990418569171581047e97L,
900 0.1711224524281413113724683388812728390923e99L,
901 0.1197857166996989179607278372168909873646e101L,
902 0.8504785885678623175211676442399260102886e102L,
903 0.6123445837688608686152407038527467274078e104L,
904 0.4470115461512684340891257138125051110077e106L,
905 0.3307885441519386412259530282212537821457e108L,
906 0.2480914081139539809194647711659403366093e110L,
907 0.188549470166605025498793226086114655823e112L,
908 0.1451830920282858696340707840863082849837e114L,
909 0.1132428117820629783145752115873204622873e116L,
910 0.8946182130782975286851441715398316520698e117L,
911 0.7156945704626380229481153372318653216558e119L,
912 0.5797126020747367985879734231578109105412e121L,
913 0.4753643337012841748421382069894049466438e123L,
914 0.3945523969720658651189747118012061057144e125L,
915 0.3314240134565353266999387579130131288001e127L,
916 0.2817104114380550276949479442260611594801e129L,
917 0.2422709538367273238176552320344125971528e131L,
918 0.210775729837952771721360051869938959523e133L,
919 0.1854826422573984391147968456455462843802e135L,
920 0.1650795516090846108121691926245361930984e137L,
921 0.1485715964481761497309522733620825737886e139L,
922 0.1352001527678402962551665687594951421476e141L,
923 0.1243841405464130725547532432587355307758e143L,
924 0.1156772507081641574759205162306240436215e145L,
925 0.1087366156656743080273652852567866010042e147L,
926 0.103299784882390592625997020993947270954e149L,
927 0.9916779348709496892095714015418938011582e150L,
928 0.9619275968248211985332842594956369871234e152L,
929 0.942689044888324774562618574305724247381e154L,
930 0.9332621544394415268169923885626670049072e156L,
931 0.9332621544394415268169923885626670049072e158L,
932 0.9425947759838359420851623124482936749562e160L,
933 0.9614466715035126609268655586972595484554e162L,
934 0.990290071648618040754671525458177334909e164L,
935 0.1029901674514562762384858386476504428305e167L,
936 0.1081396758240290900504101305800329649721e169L,
937 0.1146280563734708354534347384148349428704e171L,
938 0.1226520203196137939351751701038733888713e173L,
939 0.132464181945182897449989183712183259981e175L,
940 0.1443859583202493582204882102462797533793e177L,
941 0.1588245541522742940425370312709077287172e179L,
942 0.1762952551090244663872161047107075788761e181L,
943 0.1974506857221074023536820372759924883413e183L,
944 0.2231192748659813646596607021218715118256e185L,
945 0.2543559733472187557120132004189335234812e187L,
946 0.2925093693493015690688151804817735520034e189L,
947 0.339310868445189820119825609358857320324e191L,
948 0.396993716080872089540195962949863064779e193L,
949 0.4684525849754290656574312362808384164393e195L,
950 0.5574585761207605881323431711741977155627e197L,
951 0.6689502913449127057588118054090372586753e199L,
952 0.8094298525273443739681622845449350829971e201L,
953 0.9875044200833601362411579871448208012564e203L,
954 0.1214630436702532967576624324188129585545e206L,
955 0.1506141741511140879795014161993280686076e208L,
956 0.1882677176888926099743767702491600857595e210L,
957 0.237217324288004688567714730513941708057e212L,
958 0.3012660018457659544809977077527059692324e214L,
959 0.3856204823625804217356770659234636406175e216L,
960 0.4974504222477287440390234150412680963966e218L,
961 0.6466855489220473672507304395536485253155e220L,
962 0.8471580690878820510984568758152795681634e222L,
963 0.1118248651196004307449963076076169029976e225L,
964 0.1487270706090685728908450891181304809868e227L,
965 0.1992942746161518876737324194182948445223e229L,
966 0.269047270731805048359538766214698040105e231L,
967 0.3659042881952548657689727220519893345429e233L,
968 0.5012888748274991661034926292112253883237e235L,
969 0.6917786472619488492228198283114910358867e237L,
970 0.9615723196941089004197195613529725398826e239L,
971 0.1346201247571752460587607385894161555836e242L,
972 0.1898143759076170969428526414110767793728e244L,
973 0.2695364137888162776588507508037290267094e246L,
974 0.3854370717180072770521565736493325081944e248L,
975 0.5550293832739304789551054660550388118e250L,
976 0.80479260574719919448490292577980627711e252L,
977 0.1174997204390910823947958271638517164581e255L,
978 0.1727245890454638911203498659308620231933e257L,
979 0.2556323917872865588581178015776757943262e259L,
980 0.380892263763056972698595524350736933546e261L,
981 0.571338395644585459047893286526105400319e263L,
982 0.8627209774233240431623188626544191544816e265L,
983 0.1311335885683452545606724671234717114812e268L,
984 0.2006343905095682394778288746989117185662e270L,
985 0.308976961384735088795856467036324046592e272L,
986 0.4789142901463393876335775239063022722176e274L,
987 0.7471062926282894447083809372938315446595e276L,
988 0.1172956879426414428192158071551315525115e279L,
989 0.1853271869493734796543609753051078529682e281L,
990 0.2946702272495038326504339507351214862195e283L,
991 0.4714723635992061322406943211761943779512e285L,
992 0.7590705053947218729075178570936729485014e287L,
993 0.1229694218739449434110178928491750176572e290L,
994 0.2004401576545302577599591653441552787813e292L,
995 0.3287218585534296227263330311644146572013e294L,
996 0.5423910666131588774984495014212841843822e296L,
997 0.9003691705778437366474261723593317460744e298L,
998 0.1503616514864999040201201707840084015944e301L,
999 0.2526075744973198387538018869171341146786e303L,
1000 0.4269068009004705274939251888899566538069e305L,
1001 0.7257415615307998967396728211129263114717e307L,
1002 }};
1003 #endif
1004
1005 template <>
1006 inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION long double unchecked_factorial<long double>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(long double))
1007 {
1008 return unchecked_factorial_data<long double>::factorials[i];
1009 }
1010
1011 template <>
1012 struct max_factorial<long double>
1013 {
1014 static constexpr unsigned value = 170;
1015 };
1016
1017 #ifdef BOOST_MATH_USE_FLOAT128
1018
1019 template <bool b>
1020 struct unchecked_factorial_data<BOOST_MATH_FLOAT128_TYPE, b>
1021 {
1022 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
1023 static constexpr boost::math::array<BOOST_MATH_FLOAT128_TYPE, 171> factorials = { {
1024 1,
1025 1,
1026 2,
1027 6,
1028 24,
1029 120,
1030 720,
1031 5040,
1032 40320,
1033 362880.0Q,
1034 3628800.0Q,
1035 39916800.0Q,
1036 479001600.0Q,
1037 6227020800.0Q,
1038 87178291200.0Q,
1039 1307674368000.0Q,
1040 20922789888000.0Q,
1041 355687428096000.0Q,
1042 6402373705728000.0Q,
1043 121645100408832000.0Q,
1044 0.243290200817664e19Q,
1045 0.5109094217170944e20Q,
1046 0.112400072777760768e22Q,
1047 0.2585201673888497664e23Q,
1048 0.62044840173323943936e24Q,
1049 0.15511210043330985984e26Q,
1050 0.403291461126605635584e27Q,
1051 0.10888869450418352160768e29Q,
1052 0.304888344611713860501504e30Q,
1053 0.8841761993739701954543616e31Q,
1054 0.26525285981219105863630848e33Q,
1055 0.822283865417792281772556288e34Q,
1056 0.26313083693369353016721801216e36Q,
1057 0.868331761881188649551819440128e37Q,
1058 0.29523279903960414084761860964352e39Q,
1059 0.103331479663861449296666513375232e41Q,
1060 0.3719933267899012174679994481508352e42Q,
1061 0.137637530912263450463159795815809024e44Q,
1062 0.5230226174666011117600072241000742912e45Q,
1063 0.203978820811974433586402817399028973568e47Q,
1064 0.815915283247897734345611269596115894272e48Q,
1065 0.3345252661316380710817006205344075166515e50Q,
1066 0.1405006117752879898543142606244511569936e52Q,
1067 0.6041526306337383563735513206851399750726e53Q,
1068 0.265827157478844876804362581101461589032e55Q,
1069 0.1196222208654801945619631614956577150644e57Q,
1070 0.5502622159812088949850305428800254892962e58Q,
1071 0.2586232415111681806429643551536119799692e60Q,
1072 0.1241391559253607267086228904737337503852e62Q,
1073 0.6082818640342675608722521633212953768876e63Q,
1074 0.3041409320171337804361260816606476884438e65Q,
1075 0.1551118753287382280224243016469303211063e67Q,
1076 0.8065817517094387857166063685640376697529e68Q,
1077 0.427488328406002556429801375338939964969e70Q,
1078 0.2308436973392413804720927426830275810833e72Q,
1079 0.1269640335365827592596510084756651695958e74Q,
1080 0.7109985878048634518540456474637249497365e75Q,
1081 0.4052691950487721675568060190543232213498e77Q,
1082 0.2350561331282878571829474910515074683829e79Q,
1083 0.1386831185456898357379390197203894063459e81Q,
1084 0.8320987112741390144276341183223364380754e82Q,
1085 0.507580213877224798800856812176625227226e84Q,
1086 0.3146997326038793752565312235495076408801e86Q,
1087 0.1982608315404440064116146708361898137545e88Q,
1088 0.1268869321858841641034333893351614808029e90Q,
1089 0.8247650592082470666723170306785496252186e91Q,
1090 0.5443449390774430640037292402478427526443e93Q,
1091 0.3647111091818868528824985909660546442717e95Q,
1092 0.2480035542436830599600990418569171581047e97Q,
1093 0.1711224524281413113724683388812728390923e99Q,
1094 0.1197857166996989179607278372168909873646e101Q,
1095 0.8504785885678623175211676442399260102886e102Q,
1096 0.6123445837688608686152407038527467274078e104Q,
1097 0.4470115461512684340891257138125051110077e106Q,
1098 0.3307885441519386412259530282212537821457e108Q,
1099 0.2480914081139539809194647711659403366093e110Q,
1100 0.188549470166605025498793226086114655823e112Q,
1101 0.1451830920282858696340707840863082849837e114Q,
1102 0.1132428117820629783145752115873204622873e116Q,
1103 0.8946182130782975286851441715398316520698e117Q,
1104 0.7156945704626380229481153372318653216558e119Q,
1105 0.5797126020747367985879734231578109105412e121Q,
1106 0.4753643337012841748421382069894049466438e123Q,
1107 0.3945523969720658651189747118012061057144e125Q,
1108 0.3314240134565353266999387579130131288001e127Q,
1109 0.2817104114380550276949479442260611594801e129Q,
1110 0.2422709538367273238176552320344125971528e131Q,
1111 0.210775729837952771721360051869938959523e133Q,
1112 0.1854826422573984391147968456455462843802e135Q,
1113 0.1650795516090846108121691926245361930984e137Q,
1114 0.1485715964481761497309522733620825737886e139Q,
1115 0.1352001527678402962551665687594951421476e141Q,
1116 0.1243841405464130725547532432587355307758e143Q,
1117 0.1156772507081641574759205162306240436215e145Q,
1118 0.1087366156656743080273652852567866010042e147Q,
1119 0.103299784882390592625997020993947270954e149Q,
1120 0.9916779348709496892095714015418938011582e150Q,
1121 0.9619275968248211985332842594956369871234e152Q,
1122 0.942689044888324774562618574305724247381e154Q,
1123 0.9332621544394415268169923885626670049072e156Q,
1124 0.9332621544394415268169923885626670049072e158Q,
1125 0.9425947759838359420851623124482936749562e160Q,
1126 0.9614466715035126609268655586972595484554e162Q,
1127 0.990290071648618040754671525458177334909e164Q,
1128 0.1029901674514562762384858386476504428305e167Q,
1129 0.1081396758240290900504101305800329649721e169Q,
1130 0.1146280563734708354534347384148349428704e171Q,
1131 0.1226520203196137939351751701038733888713e173Q,
1132 0.132464181945182897449989183712183259981e175Q,
1133 0.1443859583202493582204882102462797533793e177Q,
1134 0.1588245541522742940425370312709077287172e179Q,
1135 0.1762952551090244663872161047107075788761e181Q,
1136 0.1974506857221074023536820372759924883413e183Q,
1137 0.2231192748659813646596607021218715118256e185Q,
1138 0.2543559733472187557120132004189335234812e187Q,
1139 0.2925093693493015690688151804817735520034e189Q,
1140 0.339310868445189820119825609358857320324e191Q,
1141 0.396993716080872089540195962949863064779e193Q,
1142 0.4684525849754290656574312362808384164393e195Q,
1143 0.5574585761207605881323431711741977155627e197Q,
1144 0.6689502913449127057588118054090372586753e199Q,
1145 0.8094298525273443739681622845449350829971e201Q,
1146 0.9875044200833601362411579871448208012564e203Q,
1147 0.1214630436702532967576624324188129585545e206Q,
1148 0.1506141741511140879795014161993280686076e208Q,
1149 0.1882677176888926099743767702491600857595e210Q,
1150 0.237217324288004688567714730513941708057e212Q,
1151 0.3012660018457659544809977077527059692324e214Q,
1152 0.3856204823625804217356770659234636406175e216Q,
1153 0.4974504222477287440390234150412680963966e218Q,
1154 0.6466855489220473672507304395536485253155e220Q,
1155 0.8471580690878820510984568758152795681634e222Q,
1156 0.1118248651196004307449963076076169029976e225Q,
1157 0.1487270706090685728908450891181304809868e227Q,
1158 0.1992942746161518876737324194182948445223e229Q,
1159 0.269047270731805048359538766214698040105e231Q,
1160 0.3659042881952548657689727220519893345429e233Q,
1161 0.5012888748274991661034926292112253883237e235Q,
1162 0.6917786472619488492228198283114910358867e237Q,
1163 0.9615723196941089004197195613529725398826e239Q,
1164 0.1346201247571752460587607385894161555836e242Q,
1165 0.1898143759076170969428526414110767793728e244Q,
1166 0.2695364137888162776588507508037290267094e246Q,
1167 0.3854370717180072770521565736493325081944e248Q,
1168 0.5550293832739304789551054660550388118e250Q,
1169 0.80479260574719919448490292577980627711e252Q,
1170 0.1174997204390910823947958271638517164581e255Q,
1171 0.1727245890454638911203498659308620231933e257Q,
1172 0.2556323917872865588581178015776757943262e259Q,
1173 0.380892263763056972698595524350736933546e261Q,
1174 0.571338395644585459047893286526105400319e263Q,
1175 0.8627209774233240431623188626544191544816e265Q,
1176 0.1311335885683452545606724671234717114812e268Q,
1177 0.2006343905095682394778288746989117185662e270Q,
1178 0.308976961384735088795856467036324046592e272Q,
1179 0.4789142901463393876335775239063022722176e274Q,
1180 0.7471062926282894447083809372938315446595e276Q,
1181 0.1172956879426414428192158071551315525115e279Q,
1182 0.1853271869493734796543609753051078529682e281Q,
1183 0.2946702272495038326504339507351214862195e283Q,
1184 0.4714723635992061322406943211761943779512e285Q,
1185 0.7590705053947218729075178570936729485014e287Q,
1186 0.1229694218739449434110178928491750176572e290Q,
1187 0.2004401576545302577599591653441552787813e292Q,
1188 0.3287218585534296227263330311644146572013e294Q,
1189 0.5423910666131588774984495014212841843822e296Q,
1190 0.9003691705778437366474261723593317460744e298Q,
1191 0.1503616514864999040201201707840084015944e301Q,
1192 0.2526075744973198387538018869171341146786e303Q,
1193 0.4269068009004705274939251888899566538069e305Q,
1194 0.7257415615307998967396728211129263114717e307Q,
1195 } };
1196 #else
1197 static const boost::math::array<BOOST_MATH_FLOAT128_TYPE, 171> factorials;
1198 #endif
1199 };
1200
1201 template <bool b>
1202 #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES
1203 constexpr boost::math::array<BOOST_MATH_FLOAT128_TYPE, 171> unchecked_factorial_data<BOOST_MATH_FLOAT128_TYPE, b>::factorials;
1204 #else
1205 const boost::math::array<BOOST_MATH_FLOAT128_TYPE, 171> unchecked_factorial_data<BOOST_MATH_FLOAT128_TYPE, b>::factorials = { {
1206 1,
1207 1,
1208 2,
1209 6,
1210 24,
1211 120,
1212 720,
1213 5040,
1214 40320,
1215 362880.0Q,
1216 3628800.0Q,
1217 39916800.0Q,
1218 479001600.0Q,
1219 6227020800.0Q,
1220 87178291200.0Q,
1221 1307674368000.0Q,
1222 20922789888000.0Q,
1223 355687428096000.0Q,
1224 6402373705728000.0Q,
1225 121645100408832000.0Q,
1226 0.243290200817664e19Q,
1227 0.5109094217170944e20Q,
1228 0.112400072777760768e22Q,
1229 0.2585201673888497664e23Q,
1230 0.62044840173323943936e24Q,
1231 0.15511210043330985984e26Q,
1232 0.403291461126605635584e27Q,
1233 0.10888869450418352160768e29Q,
1234 0.304888344611713860501504e30Q,
1235 0.8841761993739701954543616e31Q,
1236 0.26525285981219105863630848e33Q,
1237 0.822283865417792281772556288e34Q,
1238 0.26313083693369353016721801216e36Q,
1239 0.868331761881188649551819440128e37Q,
1240 0.29523279903960414084761860964352e39Q,
1241 0.103331479663861449296666513375232e41Q,
1242 0.3719933267899012174679994481508352e42Q,
1243 0.137637530912263450463159795815809024e44Q,
1244 0.5230226174666011117600072241000742912e45Q,
1245 0.203978820811974433586402817399028973568e47Q,
1246 0.815915283247897734345611269596115894272e48Q,
1247 0.3345252661316380710817006205344075166515e50Q,
1248 0.1405006117752879898543142606244511569936e52Q,
1249 0.6041526306337383563735513206851399750726e53Q,
1250 0.265827157478844876804362581101461589032e55Q,
1251 0.1196222208654801945619631614956577150644e57Q,
1252 0.5502622159812088949850305428800254892962e58Q,
1253 0.2586232415111681806429643551536119799692e60Q,
1254 0.1241391559253607267086228904737337503852e62Q,
1255 0.6082818640342675608722521633212953768876e63Q,
1256 0.3041409320171337804361260816606476884438e65Q,
1257 0.1551118753287382280224243016469303211063e67Q,
1258 0.8065817517094387857166063685640376697529e68Q,
1259 0.427488328406002556429801375338939964969e70Q,
1260 0.2308436973392413804720927426830275810833e72Q,
1261 0.1269640335365827592596510084756651695958e74Q,
1262 0.7109985878048634518540456474637249497365e75Q,
1263 0.4052691950487721675568060190543232213498e77Q,
1264 0.2350561331282878571829474910515074683829e79Q,
1265 0.1386831185456898357379390197203894063459e81Q,
1266 0.8320987112741390144276341183223364380754e82Q,
1267 0.507580213877224798800856812176625227226e84Q,
1268 0.3146997326038793752565312235495076408801e86Q,
1269 0.1982608315404440064116146708361898137545e88Q,
1270 0.1268869321858841641034333893351614808029e90Q,
1271 0.8247650592082470666723170306785496252186e91Q,
1272 0.5443449390774430640037292402478427526443e93Q,
1273 0.3647111091818868528824985909660546442717e95Q,
1274 0.2480035542436830599600990418569171581047e97Q,
1275 0.1711224524281413113724683388812728390923e99Q,
1276 0.1197857166996989179607278372168909873646e101Q,
1277 0.8504785885678623175211676442399260102886e102Q,
1278 0.6123445837688608686152407038527467274078e104Q,
1279 0.4470115461512684340891257138125051110077e106Q,
1280 0.3307885441519386412259530282212537821457e108Q,
1281 0.2480914081139539809194647711659403366093e110Q,
1282 0.188549470166605025498793226086114655823e112Q,
1283 0.1451830920282858696340707840863082849837e114Q,
1284 0.1132428117820629783145752115873204622873e116Q,
1285 0.8946182130782975286851441715398316520698e117Q,
1286 0.7156945704626380229481153372318653216558e119Q,
1287 0.5797126020747367985879734231578109105412e121Q,
1288 0.4753643337012841748421382069894049466438e123Q,
1289 0.3945523969720658651189747118012061057144e125Q,
1290 0.3314240134565353266999387579130131288001e127Q,
1291 0.2817104114380550276949479442260611594801e129Q,
1292 0.2422709538367273238176552320344125971528e131Q,
1293 0.210775729837952771721360051869938959523e133Q,
1294 0.1854826422573984391147968456455462843802e135Q,
1295 0.1650795516090846108121691926245361930984e137Q,
1296 0.1485715964481761497309522733620825737886e139Q,
1297 0.1352001527678402962551665687594951421476e141Q,
1298 0.1243841405464130725547532432587355307758e143Q,
1299 0.1156772507081641574759205162306240436215e145Q,
1300 0.1087366156656743080273652852567866010042e147Q,
1301 0.103299784882390592625997020993947270954e149Q,
1302 0.9916779348709496892095714015418938011582e150Q,
1303 0.9619275968248211985332842594956369871234e152Q,
1304 0.942689044888324774562618574305724247381e154Q,
1305 0.9332621544394415268169923885626670049072e156Q,
1306 0.9332621544394415268169923885626670049072e158Q,
1307 0.9425947759838359420851623124482936749562e160Q,
1308 0.9614466715035126609268655586972595484554e162Q,
1309 0.990290071648618040754671525458177334909e164Q,
1310 0.1029901674514562762384858386476504428305e167Q,
1311 0.1081396758240290900504101305800329649721e169Q,
1312 0.1146280563734708354534347384148349428704e171Q,
1313 0.1226520203196137939351751701038733888713e173Q,
1314 0.132464181945182897449989183712183259981e175Q,
1315 0.1443859583202493582204882102462797533793e177Q,
1316 0.1588245541522742940425370312709077287172e179Q,
1317 0.1762952551090244663872161047107075788761e181Q,
1318 0.1974506857221074023536820372759924883413e183Q,
1319 0.2231192748659813646596607021218715118256e185Q,
1320 0.2543559733472187557120132004189335234812e187Q,
1321 0.2925093693493015690688151804817735520034e189Q,
1322 0.339310868445189820119825609358857320324e191Q,
1323 0.396993716080872089540195962949863064779e193Q,
1324 0.4684525849754290656574312362808384164393e195Q,
1325 0.5574585761207605881323431711741977155627e197Q,
1326 0.6689502913449127057588118054090372586753e199Q,
1327 0.8094298525273443739681622845449350829971e201Q,
1328 0.9875044200833601362411579871448208012564e203Q,
1329 0.1214630436702532967576624324188129585545e206Q,
1330 0.1506141741511140879795014161993280686076e208Q,
1331 0.1882677176888926099743767702491600857595e210Q,
1332 0.237217324288004688567714730513941708057e212Q,
1333 0.3012660018457659544809977077527059692324e214Q,
1334 0.3856204823625804217356770659234636406175e216Q,
1335 0.4974504222477287440390234150412680963966e218Q,
1336 0.6466855489220473672507304395536485253155e220Q,
1337 0.8471580690878820510984568758152795681634e222Q,
1338 0.1118248651196004307449963076076169029976e225Q,
1339 0.1487270706090685728908450891181304809868e227Q,
1340 0.1992942746161518876737324194182948445223e229Q,
1341 0.269047270731805048359538766214698040105e231Q,
1342 0.3659042881952548657689727220519893345429e233Q,
1343 0.5012888748274991661034926292112253883237e235Q,
1344 0.6917786472619488492228198283114910358867e237Q,
1345 0.9615723196941089004197195613529725398826e239Q,
1346 0.1346201247571752460587607385894161555836e242Q,
1347 0.1898143759076170969428526414110767793728e244Q,
1348 0.2695364137888162776588507508037290267094e246Q,
1349 0.3854370717180072770521565736493325081944e248Q,
1350 0.5550293832739304789551054660550388118e250Q,
1351 0.80479260574719919448490292577980627711e252Q,
1352 0.1174997204390910823947958271638517164581e255Q,
1353 0.1727245890454638911203498659308620231933e257Q,
1354 0.2556323917872865588581178015776757943262e259Q,
1355 0.380892263763056972698595524350736933546e261Q,
1356 0.571338395644585459047893286526105400319e263Q,
1357 0.8627209774233240431623188626544191544816e265Q,
1358 0.1311335885683452545606724671234717114812e268Q,
1359 0.2006343905095682394778288746989117185662e270Q,
1360 0.308976961384735088795856467036324046592e272Q,
1361 0.4789142901463393876335775239063022722176e274Q,
1362 0.7471062926282894447083809372938315446595e276Q,
1363 0.1172956879426414428192158071551315525115e279Q,
1364 0.1853271869493734796543609753051078529682e281Q,
1365 0.2946702272495038326504339507351214862195e283Q,
1366 0.4714723635992061322406943211761943779512e285Q,
1367 0.7590705053947218729075178570936729485014e287Q,
1368 0.1229694218739449434110178928491750176572e290Q,
1369 0.2004401576545302577599591653441552787813e292Q,
1370 0.3287218585534296227263330311644146572013e294Q,
1371 0.5423910666131588774984495014212841843822e296Q,
1372 0.9003691705778437366474261723593317460744e298Q,
1373 0.1503616514864999040201201707840084015944e301Q,
1374 0.2526075744973198387538018869171341146786e303Q,
1375 0.4269068009004705274939251888899566538069e305Q,
1376 0.7257415615307998967396728211129263114717e307Q,
1377 } };
1378 #endif
1379
1380 template <>
1381 inline BOOST_MATH_CONSTEXPR_TABLE_FUNCTION BOOST_MATH_FLOAT128_TYPE unchecked_factorial<BOOST_MATH_FLOAT128_TYPE>(unsigned i)
1382 {
1383 return unchecked_factorial_data<BOOST_MATH_FLOAT128_TYPE>::factorials[i];
1384 }
1385
1386 template <>
1387 struct max_factorial<BOOST_MATH_FLOAT128_TYPE>
1388 {
1389 static constexpr unsigned value = 170;
1390 };
1391
1392 #endif
1393
1394 template <class T, int N>
1395 inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, N>&)
1396 {
1397 //
1398 // If you're foolish enough to instantiate factorial
1399 // on an integer type then you end up here. But this code is
1400 // only intended for (fixed precision) multiprecision types.
1401 //
1402 // Note, factorial<unsigned int>(n) is not implemented
1403 // because it would overflow integral type T for too small n
1404 // to be useful. Use instead a floating-point type,
1405 // and convert to an unsigned type if essential, for example:
1406 // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n));
1407 // See factorial documentation for more detail.
1408 //
1409 static_assert(!boost::math::is_integral<T>::value && !boost::math::numeric_limits<T>::is_integer, "Type T must not be an integral type");
1410
1411 // We rely on C++11 thread safe initialization here:
1412 static const boost::math::array<T, 101> factorials = {{
1413 T(boost::math::tools::convert_from_string<T>("1")),
1414 T(boost::math::tools::convert_from_string<T>("1")),
1415 T(boost::math::tools::convert_from_string<T>("2")),
1416 T(boost::math::tools::convert_from_string<T>("6")),
1417 T(boost::math::tools::convert_from_string<T>("24")),
1418 T(boost::math::tools::convert_from_string<T>("120")),
1419 T(boost::math::tools::convert_from_string<T>("720")),
1420 T(boost::math::tools::convert_from_string<T>("5040")),
1421 T(boost::math::tools::convert_from_string<T>("40320")),
1422 T(boost::math::tools::convert_from_string<T>("362880")),
1423 T(boost::math::tools::convert_from_string<T>("3628800")),
1424 T(boost::math::tools::convert_from_string<T>("39916800")),
1425 T(boost::math::tools::convert_from_string<T>("479001600")),
1426 T(boost::math::tools::convert_from_string<T>("6227020800")),
1427 T(boost::math::tools::convert_from_string<T>("87178291200")),
1428 T(boost::math::tools::convert_from_string<T>("1307674368000")),
1429 T(boost::math::tools::convert_from_string<T>("20922789888000")),
1430 T(boost::math::tools::convert_from_string<T>("355687428096000")),
1431 T(boost::math::tools::convert_from_string<T>("6402373705728000")),
1432 T(boost::math::tools::convert_from_string<T>("121645100408832000")),
1433 T(boost::math::tools::convert_from_string<T>("2432902008176640000")),
1434 T(boost::math::tools::convert_from_string<T>("51090942171709440000")),
1435 T(boost::math::tools::convert_from_string<T>("1124000727777607680000")),
1436 T(boost::math::tools::convert_from_string<T>("25852016738884976640000")),
1437 T(boost::math::tools::convert_from_string<T>("620448401733239439360000")),
1438 T(boost::math::tools::convert_from_string<T>("15511210043330985984000000")),
1439 T(boost::math::tools::convert_from_string<T>("403291461126605635584000000")),
1440 T(boost::math::tools::convert_from_string<T>("10888869450418352160768000000")),
1441 T(boost::math::tools::convert_from_string<T>("304888344611713860501504000000")),
1442 T(boost::math::tools::convert_from_string<T>("8841761993739701954543616000000")),
1443 T(boost::math::tools::convert_from_string<T>("265252859812191058636308480000000")),
1444 T(boost::math::tools::convert_from_string<T>("8222838654177922817725562880000000")),
1445 T(boost::math::tools::convert_from_string<T>("263130836933693530167218012160000000")),
1446 T(boost::math::tools::convert_from_string<T>("8683317618811886495518194401280000000")),
1447 T(boost::math::tools::convert_from_string<T>("295232799039604140847618609643520000000")),
1448 T(boost::math::tools::convert_from_string<T>("10333147966386144929666651337523200000000")),
1449 T(boost::math::tools::convert_from_string<T>("371993326789901217467999448150835200000000")),
1450 T(boost::math::tools::convert_from_string<T>("13763753091226345046315979581580902400000000")),
1451 T(boost::math::tools::convert_from_string<T>("523022617466601111760007224100074291200000000")),
1452 T(boost::math::tools::convert_from_string<T>("20397882081197443358640281739902897356800000000")),
1453 T(boost::math::tools::convert_from_string<T>("815915283247897734345611269596115894272000000000")),
1454 T(boost::math::tools::convert_from_string<T>("33452526613163807108170062053440751665152000000000")),
1455 T(boost::math::tools::convert_from_string<T>("1405006117752879898543142606244511569936384000000000")),
1456 T(boost::math::tools::convert_from_string<T>("60415263063373835637355132068513997507264512000000000")),
1457 T(boost::math::tools::convert_from_string<T>("2658271574788448768043625811014615890319638528000000000")),
1458 T(boost::math::tools::convert_from_string<T>("119622220865480194561963161495657715064383733760000000000")),
1459 T(boost::math::tools::convert_from_string<T>("5502622159812088949850305428800254892961651752960000000000")),
1460 T(boost::math::tools::convert_from_string<T>("258623241511168180642964355153611979969197632389120000000000")),
1461 T(boost::math::tools::convert_from_string<T>("12413915592536072670862289047373375038521486354677760000000000")),
1462 T(boost::math::tools::convert_from_string<T>("608281864034267560872252163321295376887552831379210240000000000")),
1463 T(boost::math::tools::convert_from_string<T>("30414093201713378043612608166064768844377641568960512000000000000")),
1464 T(boost::math::tools::convert_from_string<T>("1551118753287382280224243016469303211063259720016986112000000000000")),
1465 T(boost::math::tools::convert_from_string<T>("80658175170943878571660636856403766975289505440883277824000000000000")),
1466 T(boost::math::tools::convert_from_string<T>("4274883284060025564298013753389399649690343788366813724672000000000000")),
1467 T(boost::math::tools::convert_from_string<T>("230843697339241380472092742683027581083278564571807941132288000000000000")),
1468 T(boost::math::tools::convert_from_string<T>("12696403353658275925965100847566516959580321051449436762275840000000000000")),
1469 T(boost::math::tools::convert_from_string<T>("710998587804863451854045647463724949736497978881168458687447040000000000000")),
1470 T(boost::math::tools::convert_from_string<T>("40526919504877216755680601905432322134980384796226602145184481280000000000000")),
1471 T(boost::math::tools::convert_from_string<T>("2350561331282878571829474910515074683828862318181142924420699914240000000000000")),
1472 T(boost::math::tools::convert_from_string<T>("138683118545689835737939019720389406345902876772687432540821294940160000000000000")),
1473 T(boost::math::tools::convert_from_string<T>("8320987112741390144276341183223364380754172606361245952449277696409600000000000000")),
1474 T(boost::math::tools::convert_from_string<T>("507580213877224798800856812176625227226004528988036003099405939480985600000000000000")),
1475 T(boost::math::tools::convert_from_string<T>("31469973260387937525653122354950764088012280797258232192163168247821107200000000000000")),
1476 T(boost::math::tools::convert_from_string<T>("1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000")),
1477 T(boost::math::tools::convert_from_string<T>("126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000")),
1478 T(boost::math::tools::convert_from_string<T>("8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000")),
1479 T(boost::math::tools::convert_from_string<T>("544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000")),
1480 T(boost::math::tools::convert_from_string<T>("36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000")),
1481 T(boost::math::tools::convert_from_string<T>("2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000")),
1482 T(boost::math::tools::convert_from_string<T>("171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000")),
1483 T(boost::math::tools::convert_from_string<T>("11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000")),
1484 T(boost::math::tools::convert_from_string<T>("850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000")),
1485 T(boost::math::tools::convert_from_string<T>("61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000")),
1486 T(boost::math::tools::convert_from_string<T>("4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000")),
1487 T(boost::math::tools::convert_from_string<T>("330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000")),
1488 T(boost::math::tools::convert_from_string<T>("24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000")),
1489 T(boost::math::tools::convert_from_string<T>("1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000")),
1490 T(boost::math::tools::convert_from_string<T>("145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000")),
1491 T(boost::math::tools::convert_from_string<T>("11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000")),
1492 T(boost::math::tools::convert_from_string<T>("894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000")),
1493 T(boost::math::tools::convert_from_string<T>("71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000")),
1494 T(boost::math::tools::convert_from_string<T>("5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000")),
1495 T(boost::math::tools::convert_from_string<T>("475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000")),
1496 T(boost::math::tools::convert_from_string<T>("39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000")),
1497 T(boost::math::tools::convert_from_string<T>("3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000")),
1498 T(boost::math::tools::convert_from_string<T>("281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000")),
1499 T(boost::math::tools::convert_from_string<T>("24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000")),
1500 T(boost::math::tools::convert_from_string<T>("2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000")),
1501 T(boost::math::tools::convert_from_string<T>("185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000")),
1502 T(boost::math::tools::convert_from_string<T>("16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000")),
1503 T(boost::math::tools::convert_from_string<T>("1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000")),
1504 T(boost::math::tools::convert_from_string<T>("135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000")),
1505 T(boost::math::tools::convert_from_string<T>("12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000")),
1506 T(boost::math::tools::convert_from_string<T>("1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000")),
1507 T(boost::math::tools::convert_from_string<T>("108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000")),
1508 T(boost::math::tools::convert_from_string<T>("10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000")),
1509 T(boost::math::tools::convert_from_string<T>("991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000")),
1510 T(boost::math::tools::convert_from_string<T>("96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000")),
1511 T(boost::math::tools::convert_from_string<T>("9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000")),
1512 T(boost::math::tools::convert_from_string<T>("933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000")),
1513 T(boost::math::tools::convert_from_string<T>("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000")),
1514 }};
1515
1516 return factorials[i];
1517 }
1518
1519 template <class T>
1520 inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, 0>&)
1521 {
1522 //
1523 // If you're foolish enough to instantiate factorial
1524 // on an integer type then you end up here. But this code is
1525 // only intended for (variable precision) multiprecision types.
1526 //
1527 // Note, factorial<unsigned int>(n) is not implemented
1528 // because it would overflow integral type T for too small n
1529 // to be useful. Use instead a floating-point type,
1530 // and convert to an unsigned type if essential, for example:
1531 // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n));
1532 // See factorial documentation for more detail.
1533 //
1534 static_assert(!boost::math::is_integral<T>::value && !boost::math::numeric_limits<T>::is_integer, "Type T must not be an integral type");
1535
1536 static const char* const factorial_strings[] = {
1537 "1",
1538 "1",
1539 "2",
1540 "6",
1541 "24",
1542 "120",
1543 "720",
1544 "5040",
1545 "40320",
1546 "362880",
1547 "3628800",
1548 "39916800",
1549 "479001600",
1550 "6227020800",
1551 "87178291200",
1552 "1307674368000",
1553 "20922789888000",
1554 "355687428096000",
1555 "6402373705728000",
1556 "121645100408832000",
1557 "2432902008176640000",
1558 "51090942171709440000",
1559 "1124000727777607680000",
1560 "25852016738884976640000",
1561 "620448401733239439360000",
1562 "15511210043330985984000000",
1563 "403291461126605635584000000",
1564 "10888869450418352160768000000",
1565 "304888344611713860501504000000",
1566 "8841761993739701954543616000000",
1567 "265252859812191058636308480000000",
1568 "8222838654177922817725562880000000",
1569 "263130836933693530167218012160000000",
1570 "8683317618811886495518194401280000000",
1571 "295232799039604140847618609643520000000",
1572 "10333147966386144929666651337523200000000",
1573 "371993326789901217467999448150835200000000",
1574 "13763753091226345046315979581580902400000000",
1575 "523022617466601111760007224100074291200000000",
1576 "20397882081197443358640281739902897356800000000",
1577 "815915283247897734345611269596115894272000000000",
1578 "33452526613163807108170062053440751665152000000000",
1579 "1405006117752879898543142606244511569936384000000000",
1580 "60415263063373835637355132068513997507264512000000000",
1581 "2658271574788448768043625811014615890319638528000000000",
1582 "119622220865480194561963161495657715064383733760000000000",
1583 "5502622159812088949850305428800254892961651752960000000000",
1584 "258623241511168180642964355153611979969197632389120000000000",
1585 "12413915592536072670862289047373375038521486354677760000000000",
1586 "608281864034267560872252163321295376887552831379210240000000000",
1587 "30414093201713378043612608166064768844377641568960512000000000000",
1588 "1551118753287382280224243016469303211063259720016986112000000000000",
1589 "80658175170943878571660636856403766975289505440883277824000000000000",
1590 "4274883284060025564298013753389399649690343788366813724672000000000000",
1591 "230843697339241380472092742683027581083278564571807941132288000000000000",
1592 "12696403353658275925965100847566516959580321051449436762275840000000000000",
1593 "710998587804863451854045647463724949736497978881168458687447040000000000000",
1594 "40526919504877216755680601905432322134980384796226602145184481280000000000000",
1595 "2350561331282878571829474910515074683828862318181142924420699914240000000000000",
1596 "138683118545689835737939019720389406345902876772687432540821294940160000000000000",
1597 "8320987112741390144276341183223364380754172606361245952449277696409600000000000000",
1598 "507580213877224798800856812176625227226004528988036003099405939480985600000000000000",
1599 "31469973260387937525653122354950764088012280797258232192163168247821107200000000000000",
1600 "1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000",
1601 "126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000",
1602 "8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000",
1603 "544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000",
1604 "36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000",
1605 "2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000",
1606 "171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000",
1607 "11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000",
1608 "850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000",
1609 "61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000",
1610 "4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000",
1611 "330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000",
1612 "24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000",
1613 "1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000",
1614 "145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000",
1615 "11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000",
1616 "894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000",
1617 "71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000",
1618 "5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000",
1619 "475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000",
1620 "39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000",
1621 "3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000",
1622 "281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000",
1623 "24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000",
1624 "2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000",
1625 "185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000",
1626 "16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000",
1627 "1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000",
1628 "135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000",
1629 "12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000",
1630 "1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000",
1631 "108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000",
1632 "10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000",
1633 "991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000",
1634 "96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000",
1635 "9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000",
1636 "933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000",
1637 "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000",
1638 };
1639 //
1640 // we rely on C++11 thread safe initialization in the event that we have no thread locals:
1641 //
1642 static BOOST_MATH_THREAD_LOCAL T factorials[sizeof(factorial_strings) / sizeof(factorial_strings[0])];
1643 static BOOST_MATH_THREAD_LOCAL int digits = 0;
1644
1645 int current_digits = boost::math::tools::digits<T>();
1646
1647 if(digits != current_digits)
1648 {
1649 digits = current_digits;
1650 for(unsigned k = 0; k < sizeof(factorials) / sizeof(factorials[0]); ++k)
1651 factorials[k] = static_cast<T>(boost::math::tools::convert_from_string<T>(factorial_strings[k]));
1652 }
1653
1654 return factorials[i];
1655 }
1656
1657 #endif // BOOST_MATH_HAS_GPU_SUPPORT
1658
1659 template <class T>
1660 BOOST_MATH_GPU_ENABLED inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, boost::math::numeric_limits<float>::digits>&)
1661 {
1662 return unchecked_factorial<float>(i);
1663 }
1664
1665 template <class T>
1666 BOOST_MATH_GPU_ENABLED inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, boost::math::numeric_limits<double>::digits>&)
1667 {
1668 return unchecked_factorial<double>(i);
1669 }
1670
1671 #ifndef BOOST_MATH_HAS_GPU_SUPPORT
1672
1673 #if DBL_MANT_DIG != LDBL_MANT_DIG
1674 template <class T>
1675 inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, LDBL_MANT_DIG>&)
1676 {
1677 return unchecked_factorial<long double>(i);
1678 }
1679 #endif
1680 #ifdef BOOST_MATH_USE_FLOAT128
1681 template <class T>
1682 inline T unchecked_factorial_imp(unsigned i, const boost::math::integral_constant<int, 113>&)
1683 {
1684 return unchecked_factorial<BOOST_MATH_FLOAT128_TYPE>(i);
1685 }
1686 #endif
1687
1688 #endif // BOOST_MATH_HAS_GPU_SUPPORT
1689
1690 template <class T>
1691 BOOST_MATH_GPU_ENABLED inline T unchecked_factorial(unsigned i)
1692 {
1693 typedef typename boost::math::policies::precision<T, boost::math::policies::policy<> >::type tag_type;
1694 return unchecked_factorial_imp<T>(i, tag_type());
1695 }
1696
1697 #ifdef BOOST_MATH_USE_FLOAT128
1698 #define BOOST_MATH_DETAIL_FLOAT128_MAX_FACTORIAL : boost::math::numeric_limits<T>::digits == 113 ? max_factorial<BOOST_MATH_FLOAT128_TYPE>::value
1699 #else
1700 #define BOOST_MATH_DETAIL_FLOAT128_MAX_FACTORIAL
1701 #endif
1702
1703 template <class T>
1704 struct max_factorial
1705 {
1706 static constexpr unsigned value =
1707 boost::math::numeric_limits<T>::digits == boost::math::numeric_limits<float>::digits ? max_factorial<float>::value
1708 : boost::math::numeric_limits<T>::digits == boost::math::numeric_limits<double>::digits ? max_factorial<double>::value
1709 #ifndef BOOST_MATH_GPU_ENABLED
1710 : boost::math::numeric_limits<T>::digits == boost::math::numeric_limits<long double>::digits ? max_factorial<long double>::value
1711 BOOST_MATH_DETAIL_FLOAT128_MAX_FACTORIAL
1712 #endif
1713 : 100;
1714 };
1715
1716 #undef BOOST_MATH_DETAIL_FLOAT128_MAX_FACTORIAL
1717
1718 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
1719 template <class T>
1720 constexpr unsigned max_factorial<T>::value;
1721 #endif
1722
1723 } // namespace math
1724 } // namespace boost
1725
1726 #endif // BOOST_MATH_SP_UC_FACTORIALS_HPP
1727