thermite_special/tables/factorial.rs
1// @generated by gen_consts.py at the workspace root. DO NOT EDIT BY HAND.
2//! Factorials `$n!$`, as one static table per float format.
3//!
4//! Entry `i` is `$i!$` (so the table starts `1, 1, 2, 6, ...`), correctly rounded once
5//! from the exact integer. Tabulating rather than accumulating is an accuracy decision
6//! as much as a speed one: a running product rounds at every step, while the table entry
7//! is the nearest float to the true value.
8//!
9//! # The table ends where the format does
10//!
11//! Each format has a last representable factorial and nothing beyond it to return, so
12//! **`FACTORIALS.len()` is the overflow boundary**: `FACTORIALS.get(n)` is `None`
13//! precisely where `$n!$` would be infinite. There is no overflow policy, no error type
14//! and no limit constant, because the slice length already carries that information.
15//!
16//! | format | entries | last finite | first to overflow |
17//! |---|---|---|---|
18//! | `f32` | 35 | `$34!$` | `$35!$` |
19//! | `f64` | 171 | `$170!$` | `$171!$` |
20
21use thermite::element::FloatElement;
22
23/// Static factorial tables for a float format.
24pub trait Factorials: FloatElement {
25 /// `$0!, 1!, 2!, \ldots$`, every factorial finite in `Self`, so entry `i` is `$i!$`.
26 ///
27 /// See the [module docs](self) for why the table ends where it does.
28 const FACTORIALS: &'static [Self];
29}
30
31/// `$n!$`, or `None` when it overflows `E`.
32#[inline]
33#[must_use]
34pub fn factorial<E: Factorials>(n: usize) -> Option<E> {
35 E::FACTORIALS.get(n).copied()
36}
37
38impl Factorials for f32 {
39 #[rustfmt::skip]
40 const FACTORIALS: &'static [f32] = &[
41 1.0, // 0!
42 1.0, // 1!
43 2.0, // 2!
44 6.0, // 3!
45 24.0, // 4!
46 1.2e+02, // 5!
47 7.2e+02, // 6!
48 5.04e+03, // 7!
49 4.032e+04, // 8!
50 3.6288e+05, // 9!
51 3.6288e+06, // 10!
52 3.99168e+07, // 11!
53 4.790016e+08, // 12!
54 6.227021e+09, // 13!
55 8.717829e+10, // 14!
56 1.3076744e+12, // 15!
57 2.092279e+13, // 16!
58 3.556874e+14, // 17!
59 6.4023735e+15, // 18!
60 1.21645105e+17, // 19!
61 2.432902e+18, // 20!
62 5.109094e+19, // 21!
63 1.1240007e+21, // 22!
64 2.5852017e+22, // 23!
65 6.204484e+23, // 24!
66 1.551121e+25, // 25!
67 4.0329146e+26, // 26!
68 1.0888869e+28, // 27!
69 3.0488835e+29, // 28!
70 8.841762e+30, // 29!
71 2.6525285e+32, // 30!
72 8.2228384e+33, // 31!
73 2.6313083e+35, // 32!
74 8.683318e+36, // 33!
75 2.952328e+38, // 34!
76 ];
77}
78
79impl Factorials for f64 {
80 #[rustfmt::skip]
81 const FACTORIALS: &'static [f64] = &[
82 1.0, // 0!
83 1.0, // 1!
84 2.0, // 2!
85 6.0, // 3!
86 24.0, // 4!
87 120.0, // 5!
88 720.0, // 6!
89 5040.0, // 7!
90 40320.0, // 8!
91 362880.0, // 9!
92 3628800.0, // 10!
93 39916800.0, // 11!
94 479001600.0, // 12!
95 6227020800.0, // 13!
96 87178291200.0, // 14!
97 1307674368000.0, // 15!
98 20922789888000.0, // 16!
99 355687428096000.0, // 17!
100 6402373705728000.0, // 18!
101 1.21645100408832e+17, // 19!
102 2.43290200817664e+18, // 20!
103 5.109094217170944e+19, // 21!
104 1.1240007277776077e+21, // 22!
105 2.585201673888498e+22, // 23!
106 6.204484017332394e+23, // 24!
107 1.5511210043330986e+25, // 25!
108 4.0329146112660565e+26, // 26!
109 1.0888869450418352e+28, // 27!
110 3.0488834461171387e+29, // 28!
111 8.841761993739702e+30, // 29!
112 2.6525285981219107e+32, // 30!
113 8.222838654177922e+33, // 31!
114 2.631308369336935e+35, // 32!
115 8.683317618811886e+36, // 33!
116 2.9523279903960416e+38, // 34!
117 1.0333147966386145e+40, // 35!
118 3.7199332678990125e+41, // 36!
119 1.3763753091226346e+43, // 37!
120 5.230226174666011e+44, // 38!
121 2.0397882081197444e+46, // 39!
122 8.159152832478977e+47, // 40!
123 3.345252661316381e+49, // 41!
124 1.40500611775288e+51, // 42!
125 6.041526306337383e+52, // 43!
126 2.658271574788449e+54, // 44!
127 1.1962222086548019e+56, // 45!
128 5.502622159812089e+57, // 46!
129 2.5862324151116818e+59, // 47!
130 1.2413915592536073e+61, // 48!
131 6.082818640342675e+62, // 49!
132 3.0414093201713376e+64, // 50!
133 1.5511187532873822e+66, // 51!
134 8.065817517094388e+67, // 52!
135 4.2748832840600255e+69, // 53!
136 2.308436973392414e+71, // 54!
137 1.2696403353658276e+73, // 55!
138 7.109985878048635e+74, // 56!
139 4.0526919504877214e+76, // 57!
140 2.3505613312828785e+78, // 58!
141 1.3868311854568984e+80, // 59!
142 8.32098711274139e+81, // 60!
143 5.075802138772248e+83, // 61!
144 3.146997326038794e+85, // 62!
145 1.98260831540444e+87, // 63!
146 1.2688693218588417e+89, // 64!
147 8.247650592082472e+90, // 65!
148 5.443449390774431e+92, // 66!
149 3.647111091818868e+94, // 67!
150 2.4800355424368305e+96, // 68!
151 1.711224524281413e+98, // 69!
152 1.1978571669969892e+100, // 70!
153 8.504785885678623e+101, // 71!
154 6.1234458376886085e+103, // 72!
155 4.4701154615126844e+105, // 73!
156 3.307885441519386e+107, // 74!
157 2.48091408113954e+109, // 75!
158 1.8854947016660504e+111, // 76!
159 1.4518309202828587e+113, // 77!
160 1.1324281178206297e+115, // 78!
161 8.946182130782976e+116, // 79!
162 7.156945704626381e+118, // 80!
163 5.797126020747368e+120, // 81!
164 4.753643337012842e+122, // 82!
165 3.945523969720659e+124, // 83!
166 3.314240134565353e+126, // 84!
167 2.81710411438055e+128, // 85!
168 2.4227095383672734e+130, // 86!
169 2.107757298379528e+132, // 87!
170 1.8548264225739844e+134, // 88!
171 1.650795516090846e+136, // 89!
172 1.4857159644817615e+138, // 90!
173 1.352001527678403e+140, // 91!
174 1.2438414054641308e+142, // 92!
175 1.1567725070816416e+144, // 93!
176 1.087366156656743e+146, // 94!
177 1.032997848823906e+148, // 95!
178 9.916779348709496e+149, // 96!
179 9.619275968248212e+151, // 97!
180 9.426890448883248e+153, // 98!
181 9.332621544394415e+155, // 99!
182 9.332621544394415e+157, // 100!
183 9.42594775983836e+159, // 101!
184 9.614466715035127e+161, // 102!
185 9.90290071648618e+163, // 103!
186 1.0299016745145628e+166, // 104!
187 1.081396758240291e+168, // 105!
188 1.1462805637347084e+170, // 106!
189 1.226520203196138e+172, // 107!
190 1.324641819451829e+174, // 108!
191 1.4438595832024937e+176, // 109!
192 1.588245541522743e+178, // 110!
193 1.7629525510902446e+180, // 111!
194 1.974506857221074e+182, // 112!
195 2.2311927486598138e+184, // 113!
196 2.5435597334721877e+186, // 114!
197 2.925093693493016e+188, // 115!
198 3.393108684451898e+190, // 116!
199 3.969937160808721e+192, // 117!
200 4.684525849754291e+194, // 118!
201 5.574585761207606e+196, // 119!
202 6.689502913449127e+198, // 120!
203 8.094298525273444e+200, // 121!
204 9.875044200833601e+202, // 122!
205 1.214630436702533e+205, // 123!
206 1.506141741511141e+207, // 124!
207 1.882677176888926e+209, // 125!
208 2.372173242880047e+211, // 126!
209 3.0126600184576594e+213, // 127!
210 3.856204823625804e+215, // 128!
211 4.974504222477287e+217, // 129!
212 6.466855489220474e+219, // 130!
213 8.47158069087882e+221, // 131!
214 1.1182486511960043e+224, // 132!
215 1.4872707060906857e+226, // 133!
216 1.9929427461615188e+228, // 134!
217 2.6904727073180504e+230, // 135!
218 3.659042881952549e+232, // 136!
219 5.012888748274992e+234, // 137!
220 6.917786472619489e+236, // 138!
221 9.615723196941089e+238, // 139!
222 1.3462012475717526e+241, // 140!
223 1.898143759076171e+243, // 141!
224 2.695364137888163e+245, // 142!
225 3.854370717180073e+247, // 143!
226 5.5502938327393044e+249, // 144!
227 8.047926057471992e+251, // 145!
228 1.1749972043909107e+254, // 146!
229 1.727245890454639e+256, // 147!
230 2.5563239178728654e+258, // 148!
231 3.80892263763057e+260, // 149!
232 5.713383956445855e+262, // 150!
233 8.62720977423324e+264, // 151!
234 1.3113358856834524e+267, // 152!
235 2.0063439050956823e+269, // 153!
236 3.0897696138473508e+271, // 154!
237 4.789142901463394e+273, // 155!
238 7.471062926282894e+275, // 156!
239 1.1729568794264145e+278, // 157!
240 1.853271869493735e+280, // 158!
241 2.9467022724950384e+282, // 159!
242 4.7147236359920616e+284, // 160!
243 7.590705053947219e+286, // 161!
244 1.2296942187394494e+289, // 162!
245 2.0044015765453026e+291, // 163!
246 3.287218585534296e+293, // 164!
247 5.423910666131589e+295, // 165!
248 9.003691705778438e+297, // 166!
249 1.503616514864999e+300, // 167!
250 2.5260757449731984e+302, // 168!
251 4.269068009004705e+304, // 169!
252 7.257415615307999e+306, // 170!
253 ];
254}