lexical_util/
step.rs

1//! The maximum digits that can be held in a u64 for a given radix without
2//! overflow.
3//!
4//! This is useful for 128-bit division and operations, since it can
5//! reduces the number of inefficient, non-native operations.
6//!
7//! # Generation
8//!
9//! See [`etc/step.py`] for the script to generate the divisors and the
10//! constants, and the division algorithm.
11//!
12//! [`etc/step.py`]: https://github.com/Alexhuszagh/rust-lexical/blob/main/lexical-util/etc/step.py
13
14#![cfg(any(feature = "parse", feature = "write"))]
15
16// NOTE:
17//  Fallback radixes use 1 for the value to avoid infinite loops,
18//  but allowing them in `const fn`.
19
20/// Get the maximum number of digits that can be processed without overflowing.
21///
22/// Calculate the maximum number of digits that can always be processed
23/// without overflowing for a given type. For example, 19 digits can
24/// always be processed for a decimal string for `u64` without overflowing.
25#[inline(always)]
26#[allow(clippy::needless_return)] // reason="required depending on our radix configuration"
27pub const fn min_step(radix: u32, bits: usize, is_signed: bool) -> usize {
28    // NOTE: to avoid branching when w don't need it, we use the compile logic
29
30    #[cfg(feature = "radix")]
31    {
32        return match radix {
33            2 => min_step_2(bits, is_signed),
34            3 => min_step_3(bits, is_signed),
35            4 => min_step_4(bits, is_signed),
36            5 => min_step_5(bits, is_signed),
37            6 => min_step_6(bits, is_signed),
38            7 => min_step_7(bits, is_signed),
39            8 => min_step_8(bits, is_signed),
40            9 => min_step_9(bits, is_signed),
41            10 => min_step_10(bits, is_signed),
42            11 => min_step_11(bits, is_signed),
43            12 => min_step_12(bits, is_signed),
44            13 => min_step_13(bits, is_signed),
45            14 => min_step_14(bits, is_signed),
46            15 => min_step_15(bits, is_signed),
47            16 => min_step_16(bits, is_signed),
48            17 => min_step_17(bits, is_signed),
49            18 => min_step_18(bits, is_signed),
50            19 => min_step_19(bits, is_signed),
51            20 => min_step_20(bits, is_signed),
52            21 => min_step_21(bits, is_signed),
53            22 => min_step_22(bits, is_signed),
54            23 => min_step_23(bits, is_signed),
55            24 => min_step_24(bits, is_signed),
56            25 => min_step_25(bits, is_signed),
57            26 => min_step_26(bits, is_signed),
58            27 => min_step_27(bits, is_signed),
59            28 => min_step_28(bits, is_signed),
60            29 => min_step_29(bits, is_signed),
61            30 => min_step_30(bits, is_signed),
62            31 => min_step_31(bits, is_signed),
63            32 => min_step_32(bits, is_signed),
64            33 => min_step_33(bits, is_signed),
65            34 => min_step_34(bits, is_signed),
66            35 => min_step_35(bits, is_signed),
67            36 => min_step_36(bits, is_signed),
68            _ => 1,
69        };
70    }
71
72    #[cfg(all(feature = "power-of-two", not(feature = "radix")))]
73    {
74        return match radix {
75            2 => min_step_2(bits, is_signed),
76            4 => min_step_4(bits, is_signed),
77            8 => min_step_8(bits, is_signed),
78            10 => min_step_10(bits, is_signed),
79            16 => min_step_16(bits, is_signed),
80            32 => min_step_32(bits, is_signed),
81            _ => 1,
82        };
83    }
84
85    #[cfg(not(feature = "power-of-two"))]
86    {
87        _ = radix;
88        return min_step_10(bits, is_signed);
89    }
90}
91
92/// Get the maximum number of digits that can be processed without overflowing.
93///
94/// Calculate the maximum number of digits that can be processed
95/// without always overflowing for a given type. For example, 20 digits can
96/// be processed for a decimal string for `u64` without overflowing, but
97/// it may overflow.
98#[inline(always)]
99#[allow(clippy::needless_return)] // reason="required depending on our radix configuration"
100pub const fn max_step(radix: u32, bits: usize, is_signed: bool) -> usize {
101    #[cfg(feature = "radix")]
102    {
103        return match radix {
104            2 => max_step_2(bits, is_signed),
105            3 => max_step_3(bits, is_signed),
106            4 => max_step_4(bits, is_signed),
107            5 => max_step_5(bits, is_signed),
108            6 => max_step_6(bits, is_signed),
109            7 => max_step_7(bits, is_signed),
110            8 => max_step_8(bits, is_signed),
111            9 => max_step_9(bits, is_signed),
112            10 => max_step_10(bits, is_signed),
113            11 => max_step_11(bits, is_signed),
114            12 => max_step_12(bits, is_signed),
115            13 => max_step_13(bits, is_signed),
116            14 => max_step_14(bits, is_signed),
117            15 => max_step_15(bits, is_signed),
118            16 => max_step_16(bits, is_signed),
119            17 => max_step_17(bits, is_signed),
120            18 => max_step_18(bits, is_signed),
121            19 => max_step_19(bits, is_signed),
122            20 => max_step_20(bits, is_signed),
123            21 => max_step_21(bits, is_signed),
124            22 => max_step_22(bits, is_signed),
125            23 => max_step_23(bits, is_signed),
126            24 => max_step_24(bits, is_signed),
127            25 => max_step_25(bits, is_signed),
128            26 => max_step_26(bits, is_signed),
129            27 => max_step_27(bits, is_signed),
130            28 => max_step_28(bits, is_signed),
131            29 => max_step_29(bits, is_signed),
132            30 => max_step_30(bits, is_signed),
133            31 => max_step_31(bits, is_signed),
134            32 => max_step_32(bits, is_signed),
135            33 => max_step_33(bits, is_signed),
136            34 => max_step_34(bits, is_signed),
137            35 => max_step_35(bits, is_signed),
138            36 => max_step_36(bits, is_signed),
139            _ => 1,
140        };
141    }
142
143    #[cfg(all(feature = "power-of-two", not(feature = "radix")))]
144    {
145        return match radix {
146            2 => max_step_2(bits, is_signed),
147            4 => max_step_4(bits, is_signed),
148            8 => max_step_8(bits, is_signed),
149            10 => max_step_10(bits, is_signed),
150            16 => max_step_16(bits, is_signed),
151            32 => max_step_32(bits, is_signed),
152            _ => 1,
153        };
154    }
155
156    #[cfg(not(feature = "power-of-two"))]
157    {
158        _ = radix;
159        return max_step_10(bits, is_signed);
160    }
161}
162
163/// Calculate the number of digits that can be processed without overflowing a
164/// u64. Helper function since this is used for 128-bit division.
165#[inline(always)]
166pub const fn u64_step(radix: u32) -> usize {
167    min_step(radix, 64, false)
168}
169
170// AUTO-GENERATED
171// These functions were auto-generated by `etc/step.py`.
172// Do not edit them unless there is a good reason to.
173// Preferably, edit the source code to generate the constants.
174//
175// NOTE: For the fallthrough value for types (in case of adding short
176// or wider type support in the future), use 1 so it doesn't infinitely
177// recurse. Under normal circumstances, this will never be called.
178
179#[inline(always)]
180#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
181const fn max_step_2(bits: usize, is_signed: bool) -> usize {
182    match bits {
183        8 if is_signed => 7,
184        8 if !is_signed => 8,
185        16 if is_signed => 15,
186        16 if !is_signed => 16,
187        32 if is_signed => 31,
188        32 if !is_signed => 32,
189        64 if is_signed => 63,
190        64 if !is_signed => 64,
191        128 if is_signed => 127,
192        128 if !is_signed => 128,
193        _ => 1,
194    }
195}
196
197#[inline(always)]
198#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
199const fn min_step_2(bits: usize, is_signed: bool) -> usize {
200    match bits {
201        8 if is_signed => 7,
202        8 if !is_signed => 8,
203        16 if is_signed => 15,
204        16 if !is_signed => 16,
205        32 if is_signed => 31,
206        32 if !is_signed => 32,
207        64 if is_signed => 63,
208        64 if !is_signed => 64,
209        128 if is_signed => 127,
210        128 if !is_signed => 128,
211        _ => 1,
212    }
213}
214
215#[inline(always)]
216#[cfg_attr(not(feature = "radix"), allow(dead_code))]
217const fn max_step_3(bits: usize, is_signed: bool) -> usize {
218    match bits {
219        8 if is_signed => 5,
220        8 if !is_signed => 6,
221        16 if is_signed => 10,
222        16 if !is_signed => 11,
223        32 if is_signed => 20,
224        32 if !is_signed => 21,
225        64 if is_signed => 40,
226        64 if !is_signed => 41,
227        128 if is_signed => 81,
228        128 if !is_signed => 81,
229        _ => 1,
230    }
231}
232
233#[inline(always)]
234#[cfg_attr(not(feature = "radix"), allow(dead_code))]
235const fn min_step_3(bits: usize, is_signed: bool) -> usize {
236    match bits {
237        8 if is_signed => 4,
238        8 if !is_signed => 5,
239        16 if is_signed => 9,
240        16 if !is_signed => 10,
241        32 if is_signed => 19,
242        32 if !is_signed => 20,
243        64 if is_signed => 39,
244        64 if !is_signed => 40,
245        128 if is_signed => 80,
246        128 if !is_signed => 80,
247        _ => 1,
248    }
249}
250
251#[inline(always)]
252#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
253const fn max_step_4(bits: usize, is_signed: bool) -> usize {
254    match bits {
255        8 if is_signed => 4,
256        8 if !is_signed => 4,
257        16 if is_signed => 8,
258        16 if !is_signed => 8,
259        32 if is_signed => 16,
260        32 if !is_signed => 16,
261        64 if is_signed => 32,
262        64 if !is_signed => 32,
263        128 if is_signed => 64,
264        128 if !is_signed => 64,
265        _ => 1,
266    }
267}
268
269#[inline(always)]
270#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
271const fn min_step_4(bits: usize, is_signed: bool) -> usize {
272    match bits {
273        8 if is_signed => 3,
274        8 if !is_signed => 4,
275        16 if is_signed => 7,
276        16 if !is_signed => 8,
277        32 if is_signed => 15,
278        32 if !is_signed => 16,
279        64 if is_signed => 31,
280        64 if !is_signed => 32,
281        128 if is_signed => 63,
282        128 if !is_signed => 64,
283        _ => 1,
284    }
285}
286
287#[inline(always)]
288#[cfg_attr(not(feature = "radix"), allow(dead_code))]
289const fn max_step_5(bits: usize, is_signed: bool) -> usize {
290    match bits {
291        8 if is_signed => 4,
292        8 if !is_signed => 4,
293        16 if is_signed => 7,
294        16 if !is_signed => 7,
295        32 if is_signed => 14,
296        32 if !is_signed => 14,
297        64 if is_signed => 28,
298        64 if !is_signed => 28,
299        128 if is_signed => 55,
300        128 if !is_signed => 56,
301        _ => 1,
302    }
303}
304
305#[inline(always)]
306#[cfg_attr(not(feature = "radix"), allow(dead_code))]
307const fn min_step_5(bits: usize, is_signed: bool) -> usize {
308    match bits {
309        8 if is_signed => 3,
310        8 if !is_signed => 3,
311        16 if is_signed => 6,
312        16 if !is_signed => 6,
313        32 if is_signed => 13,
314        32 if !is_signed => 13,
315        64 if is_signed => 27,
316        64 if !is_signed => 27,
317        128 if is_signed => 54,
318        128 if !is_signed => 55,
319        _ => 1,
320    }
321}
322
323#[inline(always)]
324#[cfg_attr(not(feature = "radix"), allow(dead_code))]
325const fn max_step_6(bits: usize, is_signed: bool) -> usize {
326    match bits {
327        8 if is_signed => 3,
328        8 if !is_signed => 4,
329        16 if is_signed => 6,
330        16 if !is_signed => 7,
331        32 if is_signed => 12,
332        32 if !is_signed => 13,
333        64 if is_signed => 25,
334        64 if !is_signed => 25,
335        128 if is_signed => 50,
336        128 if !is_signed => 50,
337        _ => 1,
338    }
339}
340
341#[inline(always)]
342#[cfg_attr(not(feature = "radix"), allow(dead_code))]
343const fn min_step_6(bits: usize, is_signed: bool) -> usize {
344    match bits {
345        8 if is_signed => 2,
346        8 if !is_signed => 3,
347        16 if is_signed => 5,
348        16 if !is_signed => 6,
349        32 if is_signed => 11,
350        32 if !is_signed => 12,
351        64 if is_signed => 24,
352        64 if !is_signed => 24,
353        128 if is_signed => 49,
354        128 if !is_signed => 49,
355        _ => 1,
356    }
357}
358
359#[inline(always)]
360#[cfg_attr(not(feature = "radix"), allow(dead_code))]
361const fn max_step_7(bits: usize, is_signed: bool) -> usize {
362    match bits {
363        8 if is_signed => 3,
364        8 if !is_signed => 3,
365        16 if is_signed => 6,
366        16 if !is_signed => 6,
367        32 if is_signed => 12,
368        32 if !is_signed => 12,
369        64 if is_signed => 23,
370        64 if !is_signed => 23,
371        128 if is_signed => 46,
372        128 if !is_signed => 46,
373        _ => 1,
374    }
375}
376
377#[inline(always)]
378#[cfg_attr(not(feature = "radix"), allow(dead_code))]
379const fn min_step_7(bits: usize, is_signed: bool) -> usize {
380    match bits {
381        8 if is_signed => 2,
382        8 if !is_signed => 2,
383        16 if is_signed => 5,
384        16 if !is_signed => 5,
385        32 if is_signed => 11,
386        32 if !is_signed => 11,
387        64 if is_signed => 22,
388        64 if !is_signed => 22,
389        128 if is_signed => 45,
390        128 if !is_signed => 45,
391        _ => 1,
392    }
393}
394
395#[inline(always)]
396#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
397const fn max_step_8(bits: usize, is_signed: bool) -> usize {
398    match bits {
399        8 if is_signed => 3,
400        8 if !is_signed => 3,
401        16 if is_signed => 5,
402        16 if !is_signed => 6,
403        32 if is_signed => 11,
404        32 if !is_signed => 11,
405        64 if is_signed => 21,
406        64 if !is_signed => 22,
407        128 if is_signed => 43,
408        128 if !is_signed => 43,
409        _ => 1,
410    }
411}
412
413#[inline(always)]
414#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
415const fn min_step_8(bits: usize, is_signed: bool) -> usize {
416    match bits {
417        8 if is_signed => 2,
418        8 if !is_signed => 2,
419        16 if is_signed => 5,
420        16 if !is_signed => 5,
421        32 if is_signed => 10,
422        32 if !is_signed => 10,
423        64 if is_signed => 21,
424        64 if !is_signed => 21,
425        128 if is_signed => 42,
426        128 if !is_signed => 42,
427        _ => 1,
428    }
429}
430
431#[inline(always)]
432#[cfg_attr(not(feature = "radix"), allow(dead_code))]
433const fn max_step_9(bits: usize, is_signed: bool) -> usize {
434    match bits {
435        8 if is_signed => 3,
436        8 if !is_signed => 3,
437        16 if is_signed => 5,
438        16 if !is_signed => 6,
439        32 if is_signed => 10,
440        32 if !is_signed => 11,
441        64 if is_signed => 20,
442        64 if !is_signed => 21,
443        128 if is_signed => 41,
444        128 if !is_signed => 41,
445        _ => 1,
446    }
447}
448
449#[inline(always)]
450#[cfg_attr(not(feature = "radix"), allow(dead_code))]
451const fn min_step_9(bits: usize, is_signed: bool) -> usize {
452    match bits {
453        8 if is_signed => 2,
454        8 if !is_signed => 2,
455        16 if is_signed => 4,
456        16 if !is_signed => 5,
457        32 if is_signed => 9,
458        32 if !is_signed => 10,
459        64 if is_signed => 19,
460        64 if !is_signed => 20,
461        128 if is_signed => 40,
462        128 if !is_signed => 40,
463        _ => 1,
464    }
465}
466
467#[inline(always)]
468const fn max_step_10(bits: usize, is_signed: bool) -> usize {
469    match bits {
470        8 if is_signed => 3,
471        8 if !is_signed => 3,
472        16 if is_signed => 5,
473        16 if !is_signed => 5,
474        32 if is_signed => 10,
475        32 if !is_signed => 10,
476        64 if is_signed => 19,
477        64 if !is_signed => 20,
478        128 if is_signed => 39,
479        128 if !is_signed => 39,
480        _ => 1,
481    }
482}
483
484#[inline(always)]
485const fn min_step_10(bits: usize, is_signed: bool) -> usize {
486    match bits {
487        8 if is_signed => 2,
488        8 if !is_signed => 2,
489        16 if is_signed => 4,
490        16 if !is_signed => 4,
491        32 if is_signed => 9,
492        32 if !is_signed => 9,
493        64 if is_signed => 18,
494        64 if !is_signed => 19,
495        128 if is_signed => 38,
496        128 if !is_signed => 38,
497        _ => 1,
498    }
499}
500
501#[inline(always)]
502#[cfg_attr(not(feature = "radix"), allow(dead_code))]
503const fn max_step_11(bits: usize, is_signed: bool) -> usize {
504    match bits {
505        8 if is_signed => 3,
506        8 if !is_signed => 3,
507        16 if is_signed => 5,
508        16 if !is_signed => 5,
509        32 if is_signed => 9,
510        32 if !is_signed => 10,
511        64 if is_signed => 19,
512        64 if !is_signed => 19,
513        128 if is_signed => 37,
514        128 if !is_signed => 38,
515        _ => 1,
516    }
517}
518
519#[inline(always)]
520#[cfg_attr(not(feature = "radix"), allow(dead_code))]
521const fn min_step_11(bits: usize, is_signed: bool) -> usize {
522    match bits {
523        8 if is_signed => 2,
524        8 if !is_signed => 2,
525        16 if is_signed => 4,
526        16 if !is_signed => 4,
527        32 if is_signed => 8,
528        32 if !is_signed => 9,
529        64 if is_signed => 18,
530        64 if !is_signed => 18,
531        128 if is_signed => 36,
532        128 if !is_signed => 37,
533        _ => 1,
534    }
535}
536
537#[inline(always)]
538#[cfg_attr(not(feature = "radix"), allow(dead_code))]
539const fn max_step_12(bits: usize, is_signed: bool) -> usize {
540    match bits {
541        8 if is_signed => 2,
542        8 if !is_signed => 3,
543        16 if is_signed => 5,
544        16 if !is_signed => 5,
545        32 if is_signed => 9,
546        32 if !is_signed => 9,
547        64 if is_signed => 18,
548        64 if !is_signed => 18,
549        128 if is_signed => 36,
550        128 if !is_signed => 36,
551        _ => 1,
552    }
553}
554
555#[inline(always)]
556#[cfg_attr(not(feature = "radix"), allow(dead_code))]
557const fn min_step_12(bits: usize, is_signed: bool) -> usize {
558    match bits {
559        8 if is_signed => 1,
560        8 if !is_signed => 2,
561        16 if is_signed => 4,
562        16 if !is_signed => 4,
563        32 if is_signed => 8,
564        32 if !is_signed => 8,
565        64 if is_signed => 17,
566        64 if !is_signed => 17,
567        128 if is_signed => 35,
568        128 if !is_signed => 35,
569        _ => 1,
570    }
571}
572
573#[inline(always)]
574#[cfg_attr(not(feature = "radix"), allow(dead_code))]
575const fn max_step_13(bits: usize, is_signed: bool) -> usize {
576    match bits {
577        8 if is_signed => 2,
578        8 if !is_signed => 3,
579        16 if is_signed => 5,
580        16 if !is_signed => 5,
581        32 if is_signed => 9,
582        32 if !is_signed => 9,
583        64 if is_signed => 18,
584        64 if !is_signed => 18,
585        128 if is_signed => 35,
586        128 if !is_signed => 35,
587        _ => 1,
588    }
589}
590
591#[inline(always)]
592#[cfg_attr(not(feature = "radix"), allow(dead_code))]
593const fn min_step_13(bits: usize, is_signed: bool) -> usize {
594    match bits {
595        8 if is_signed => 1,
596        8 if !is_signed => 2,
597        16 if is_signed => 4,
598        16 if !is_signed => 4,
599        32 if is_signed => 8,
600        32 if !is_signed => 8,
601        64 if is_signed => 17,
602        64 if !is_signed => 17,
603        128 if is_signed => 34,
604        128 if !is_signed => 34,
605        _ => 1,
606    }
607}
608
609#[inline(always)]
610#[cfg_attr(not(feature = "radix"), allow(dead_code))]
611const fn max_step_14(bits: usize, is_signed: bool) -> usize {
612    match bits {
613        8 if is_signed => 2,
614        8 if !is_signed => 3,
615        16 if is_signed => 4,
616        16 if !is_signed => 5,
617        32 if is_signed => 9,
618        32 if !is_signed => 9,
619        64 if is_signed => 17,
620        64 if !is_signed => 17,
621        128 if is_signed => 34,
622        128 if !is_signed => 34,
623        _ => 1,
624    }
625}
626
627#[inline(always)]
628#[cfg_attr(not(feature = "radix"), allow(dead_code))]
629const fn min_step_14(bits: usize, is_signed: bool) -> usize {
630    match bits {
631        8 if is_signed => 1,
632        8 if !is_signed => 2,
633        16 if is_signed => 3,
634        16 if !is_signed => 4,
635        32 if is_signed => 8,
636        32 if !is_signed => 8,
637        64 if is_signed => 16,
638        64 if !is_signed => 16,
639        128 if is_signed => 33,
640        128 if !is_signed => 33,
641        _ => 1,
642    }
643}
644
645#[inline(always)]
646#[cfg_attr(not(feature = "radix"), allow(dead_code))]
647const fn max_step_15(bits: usize, is_signed: bool) -> usize {
648    match bits {
649        8 if is_signed => 2,
650        8 if !is_signed => 3,
651        16 if is_signed => 4,
652        16 if !is_signed => 5,
653        32 if is_signed => 8,
654        32 if !is_signed => 9,
655        64 if is_signed => 17,
656        64 if !is_signed => 17,
657        128 if is_signed => 33,
658        128 if !is_signed => 33,
659        _ => 1,
660    }
661}
662
663#[inline(always)]
664#[cfg_attr(not(feature = "radix"), allow(dead_code))]
665const fn min_step_15(bits: usize, is_signed: bool) -> usize {
666    match bits {
667        8 if is_signed => 1,
668        8 if !is_signed => 2,
669        16 if is_signed => 3,
670        16 if !is_signed => 4,
671        32 if is_signed => 7,
672        32 if !is_signed => 8,
673        64 if is_signed => 16,
674        64 if !is_signed => 16,
675        128 if is_signed => 32,
676        128 if !is_signed => 32,
677        _ => 1,
678    }
679}
680
681#[inline(always)]
682#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
683const fn max_step_16(bits: usize, is_signed: bool) -> usize {
684    match bits {
685        8 if is_signed => 2,
686        8 if !is_signed => 2,
687        16 if is_signed => 4,
688        16 if !is_signed => 4,
689        32 if is_signed => 8,
690        32 if !is_signed => 8,
691        64 if is_signed => 16,
692        64 if !is_signed => 16,
693        128 if is_signed => 32,
694        128 if !is_signed => 32,
695        _ => 1,
696    }
697}
698
699#[inline(always)]
700#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
701const fn min_step_16(bits: usize, is_signed: bool) -> usize {
702    match bits {
703        8 if is_signed => 1,
704        8 if !is_signed => 2,
705        16 if is_signed => 3,
706        16 if !is_signed => 4,
707        32 if is_signed => 7,
708        32 if !is_signed => 8,
709        64 if is_signed => 15,
710        64 if !is_signed => 16,
711        128 if is_signed => 31,
712        128 if !is_signed => 32,
713        _ => 1,
714    }
715}
716
717#[inline(always)]
718#[cfg_attr(not(feature = "radix"), allow(dead_code))]
719const fn max_step_17(bits: usize, is_signed: bool) -> usize {
720    match bits {
721        8 if is_signed => 2,
722        8 if !is_signed => 2,
723        16 if is_signed => 4,
724        16 if !is_signed => 4,
725        32 if is_signed => 8,
726        32 if !is_signed => 8,
727        64 if is_signed => 16,
728        64 if !is_signed => 16,
729        128 if is_signed => 32,
730        128 if !is_signed => 32,
731        _ => 1,
732    }
733}
734
735#[inline(always)]
736#[cfg_attr(not(feature = "radix"), allow(dead_code))]
737const fn min_step_17(bits: usize, is_signed: bool) -> usize {
738    match bits {
739        8 if is_signed => 1,
740        8 if !is_signed => 1,
741        16 if is_signed => 3,
742        16 if !is_signed => 3,
743        32 if is_signed => 7,
744        32 if !is_signed => 7,
745        64 if is_signed => 15,
746        64 if !is_signed => 15,
747        128 if is_signed => 31,
748        128 if !is_signed => 31,
749        _ => 1,
750    }
751}
752
753#[inline(always)]
754#[cfg_attr(not(feature = "radix"), allow(dead_code))]
755const fn max_step_18(bits: usize, is_signed: bool) -> usize {
756    match bits {
757        8 if is_signed => 2,
758        8 if !is_signed => 2,
759        16 if is_signed => 4,
760        16 if !is_signed => 4,
761        32 if is_signed => 8,
762        32 if !is_signed => 8,
763        64 if is_signed => 16,
764        64 if !is_signed => 16,
765        128 if is_signed => 31,
766        128 if !is_signed => 31,
767        _ => 1,
768    }
769}
770
771#[inline(always)]
772#[cfg_attr(not(feature = "radix"), allow(dead_code))]
773const fn min_step_18(bits: usize, is_signed: bool) -> usize {
774    match bits {
775        8 if is_signed => 1,
776        8 if !is_signed => 1,
777        16 if is_signed => 3,
778        16 if !is_signed => 3,
779        32 if is_signed => 7,
780        32 if !is_signed => 7,
781        64 if is_signed => 15,
782        64 if !is_signed => 15,
783        128 if is_signed => 30,
784        128 if !is_signed => 30,
785        _ => 1,
786    }
787}
788
789#[inline(always)]
790#[cfg_attr(not(feature = "radix"), allow(dead_code))]
791const fn max_step_19(bits: usize, is_signed: bool) -> usize {
792    match bits {
793        8 if is_signed => 2,
794        8 if !is_signed => 2,
795        16 if is_signed => 4,
796        16 if !is_signed => 4,
797        32 if is_signed => 8,
798        32 if !is_signed => 8,
799        64 if is_signed => 15,
800        64 if !is_signed => 16,
801        128 if is_signed => 30,
802        128 if !is_signed => 31,
803        _ => 1,
804    }
805}
806
807#[inline(always)]
808#[cfg_attr(not(feature = "radix"), allow(dead_code))]
809const fn min_step_19(bits: usize, is_signed: bool) -> usize {
810    match bits {
811        8 if is_signed => 1,
812        8 if !is_signed => 1,
813        16 if is_signed => 3,
814        16 if !is_signed => 3,
815        32 if is_signed => 7,
816        32 if !is_signed => 7,
817        64 if is_signed => 14,
818        64 if !is_signed => 15,
819        128 if is_signed => 29,
820        128 if !is_signed => 30,
821        _ => 1,
822    }
823}
824
825#[inline(always)]
826#[cfg_attr(not(feature = "radix"), allow(dead_code))]
827const fn max_step_20(bits: usize, is_signed: bool) -> usize {
828    match bits {
829        8 if is_signed => 2,
830        8 if !is_signed => 2,
831        16 if is_signed => 4,
832        16 if !is_signed => 4,
833        32 if is_signed => 8,
834        32 if !is_signed => 8,
835        64 if is_signed => 15,
836        64 if !is_signed => 15,
837        128 if is_signed => 30,
838        128 if !is_signed => 30,
839        _ => 1,
840    }
841}
842
843#[inline(always)]
844#[cfg_attr(not(feature = "radix"), allow(dead_code))]
845const fn min_step_20(bits: usize, is_signed: bool) -> usize {
846    match bits {
847        8 if is_signed => 1,
848        8 if !is_signed => 1,
849        16 if is_signed => 3,
850        16 if !is_signed => 3,
851        32 if is_signed => 7,
852        32 if !is_signed => 7,
853        64 if is_signed => 14,
854        64 if !is_signed => 14,
855        128 if is_signed => 29,
856        128 if !is_signed => 29,
857        _ => 1,
858    }
859}
860
861#[inline(always)]
862#[cfg_attr(not(feature = "radix"), allow(dead_code))]
863const fn max_step_21(bits: usize, is_signed: bool) -> usize {
864    match bits {
865        8 if is_signed => 2,
866        8 if !is_signed => 2,
867        16 if is_signed => 4,
868        16 if !is_signed => 4,
869        32 if is_signed => 8,
870        32 if !is_signed => 8,
871        64 if is_signed => 15,
872        64 if !is_signed => 15,
873        128 if is_signed => 29,
874        128 if !is_signed => 30,
875        _ => 1,
876    }
877}
878
879#[inline(always)]
880#[cfg_attr(not(feature = "radix"), allow(dead_code))]
881const fn min_step_21(bits: usize, is_signed: bool) -> usize {
882    match bits {
883        8 if is_signed => 1,
884        8 if !is_signed => 1,
885        16 if is_signed => 3,
886        16 if !is_signed => 3,
887        32 if is_signed => 7,
888        32 if !is_signed => 7,
889        64 if is_signed => 14,
890        64 if !is_signed => 14,
891        128 if is_signed => 28,
892        128 if !is_signed => 29,
893        _ => 1,
894    }
895}
896
897#[inline(always)]
898#[cfg_attr(not(feature = "radix"), allow(dead_code))]
899const fn max_step_22(bits: usize, is_signed: bool) -> usize {
900    match bits {
901        8 if is_signed => 2,
902        8 if !is_signed => 2,
903        16 if is_signed => 4,
904        16 if !is_signed => 4,
905        32 if is_signed => 7,
906        32 if !is_signed => 8,
907        64 if is_signed => 15,
908        64 if !is_signed => 15,
909        128 if is_signed => 29,
910        128 if !is_signed => 29,
911        _ => 1,
912    }
913}
914
915#[inline(always)]
916#[cfg_attr(not(feature = "radix"), allow(dead_code))]
917const fn min_step_22(bits: usize, is_signed: bool) -> usize {
918    match bits {
919        8 if is_signed => 1,
920        8 if !is_signed => 1,
921        16 if is_signed => 3,
922        16 if !is_signed => 3,
923        32 if is_signed => 6,
924        32 if !is_signed => 7,
925        64 if is_signed => 14,
926        64 if !is_signed => 14,
927        128 if is_signed => 28,
928        128 if !is_signed => 28,
929        _ => 1,
930    }
931}
932
933#[inline(always)]
934#[cfg_attr(not(feature = "radix"), allow(dead_code))]
935const fn max_step_23(bits: usize, is_signed: bool) -> usize {
936    match bits {
937        8 if is_signed => 2,
938        8 if !is_signed => 2,
939        16 if is_signed => 4,
940        16 if !is_signed => 4,
941        32 if is_signed => 7,
942        32 if !is_signed => 8,
943        64 if is_signed => 14,
944        64 if !is_signed => 15,
945        128 if is_signed => 29,
946        128 if !is_signed => 29,
947        _ => 1,
948    }
949}
950
951#[inline(always)]
952#[cfg_attr(not(feature = "radix"), allow(dead_code))]
953const fn min_step_23(bits: usize, is_signed: bool) -> usize {
954    match bits {
955        8 if is_signed => 1,
956        8 if !is_signed => 1,
957        16 if is_signed => 3,
958        16 if !is_signed => 3,
959        32 if is_signed => 6,
960        32 if !is_signed => 7,
961        64 if is_signed => 13,
962        64 if !is_signed => 14,
963        128 if is_signed => 28,
964        128 if !is_signed => 28,
965        _ => 1,
966    }
967}
968
969#[inline(always)]
970#[cfg_attr(not(feature = "radix"), allow(dead_code))]
971const fn max_step_24(bits: usize, is_signed: bool) -> usize {
972    match bits {
973        8 if is_signed => 2,
974        8 if !is_signed => 2,
975        16 if is_signed => 4,
976        16 if !is_signed => 4,
977        32 if is_signed => 7,
978        32 if !is_signed => 7,
979        64 if is_signed => 14,
980        64 if !is_signed => 14,
981        128 if is_signed => 28,
982        128 if !is_signed => 28,
983        _ => 1,
984    }
985}
986
987#[inline(always)]
988#[cfg_attr(not(feature = "radix"), allow(dead_code))]
989const fn min_step_24(bits: usize, is_signed: bool) -> usize {
990    match bits {
991        8 if is_signed => 1,
992        8 if !is_signed => 1,
993        16 if is_signed => 3,
994        16 if !is_signed => 3,
995        32 if is_signed => 6,
996        32 if !is_signed => 6,
997        64 if is_signed => 13,
998        64 if !is_signed => 13,
999        128 if is_signed => 27,
1000        128 if !is_signed => 27,
1001        _ => 1,
1002    }
1003}
1004
1005#[inline(always)]
1006#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1007const fn max_step_25(bits: usize, is_signed: bool) -> usize {
1008    match bits {
1009        8 if is_signed => 2,
1010        8 if !is_signed => 2,
1011        16 if is_signed => 4,
1012        16 if !is_signed => 4,
1013        32 if is_signed => 7,
1014        32 if !is_signed => 7,
1015        64 if is_signed => 14,
1016        64 if !is_signed => 14,
1017        128 if is_signed => 28,
1018        128 if !is_signed => 28,
1019        _ => 1,
1020    }
1021}
1022
1023#[inline(always)]
1024#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1025const fn min_step_25(bits: usize, is_signed: bool) -> usize {
1026    match bits {
1027        8 if is_signed => 1,
1028        8 if !is_signed => 1,
1029        16 if is_signed => 3,
1030        16 if !is_signed => 3,
1031        32 if is_signed => 6,
1032        32 if !is_signed => 6,
1033        64 if is_signed => 13,
1034        64 if !is_signed => 13,
1035        128 if is_signed => 27,
1036        128 if !is_signed => 27,
1037        _ => 1,
1038    }
1039}
1040
1041#[inline(always)]
1042#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1043const fn max_step_26(bits: usize, is_signed: bool) -> usize {
1044    match bits {
1045        8 if is_signed => 2,
1046        8 if !is_signed => 2,
1047        16 if is_signed => 4,
1048        16 if !is_signed => 4,
1049        32 if is_signed => 7,
1050        32 if !is_signed => 7,
1051        64 if is_signed => 14,
1052        64 if !is_signed => 14,
1053        128 if is_signed => 28,
1054        128 if !is_signed => 28,
1055        _ => 1,
1056    }
1057}
1058
1059#[inline(always)]
1060#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1061const fn min_step_26(bits: usize, is_signed: bool) -> usize {
1062    match bits {
1063        8 if is_signed => 1,
1064        8 if !is_signed => 1,
1065        16 if is_signed => 3,
1066        16 if !is_signed => 3,
1067        32 if is_signed => 6,
1068        32 if !is_signed => 6,
1069        64 if is_signed => 13,
1070        64 if !is_signed => 13,
1071        128 if is_signed => 27,
1072        128 if !is_signed => 27,
1073        _ => 1,
1074    }
1075}
1076
1077#[inline(always)]
1078#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1079const fn max_step_27(bits: usize, is_signed: bool) -> usize {
1080    match bits {
1081        8 if is_signed => 2,
1082        8 if !is_signed => 2,
1083        16 if is_signed => 4,
1084        16 if !is_signed => 4,
1085        32 if is_signed => 7,
1086        32 if !is_signed => 7,
1087        64 if is_signed => 14,
1088        64 if !is_signed => 14,
1089        128 if is_signed => 27,
1090        128 if !is_signed => 27,
1091        _ => 1,
1092    }
1093}
1094
1095#[inline(always)]
1096#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1097const fn min_step_27(bits: usize, is_signed: bool) -> usize {
1098    match bits {
1099        8 if is_signed => 1,
1100        8 if !is_signed => 1,
1101        16 if is_signed => 3,
1102        16 if !is_signed => 3,
1103        32 if is_signed => 6,
1104        32 if !is_signed => 6,
1105        64 if is_signed => 13,
1106        64 if !is_signed => 13,
1107        128 if is_signed => 26,
1108        128 if !is_signed => 26,
1109        _ => 1,
1110    }
1111}
1112
1113#[inline(always)]
1114#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1115const fn max_step_28(bits: usize, is_signed: bool) -> usize {
1116    match bits {
1117        8 if is_signed => 2,
1118        8 if !is_signed => 2,
1119        16 if is_signed => 4,
1120        16 if !is_signed => 4,
1121        32 if is_signed => 7,
1122        32 if !is_signed => 7,
1123        64 if is_signed => 14,
1124        64 if !is_signed => 14,
1125        128 if is_signed => 27,
1126        128 if !is_signed => 27,
1127        _ => 1,
1128    }
1129}
1130
1131#[inline(always)]
1132#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1133const fn min_step_28(bits: usize, is_signed: bool) -> usize {
1134    match bits {
1135        8 if is_signed => 1,
1136        8 if !is_signed => 1,
1137        16 if is_signed => 3,
1138        16 if !is_signed => 3,
1139        32 if is_signed => 6,
1140        32 if !is_signed => 6,
1141        64 if is_signed => 13,
1142        64 if !is_signed => 13,
1143        128 if is_signed => 26,
1144        128 if !is_signed => 26,
1145        _ => 1,
1146    }
1147}
1148
1149#[inline(always)]
1150#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1151const fn max_step_29(bits: usize, is_signed: bool) -> usize {
1152    match bits {
1153        8 if is_signed => 2,
1154        8 if !is_signed => 2,
1155        16 if is_signed => 4,
1156        16 if !is_signed => 4,
1157        32 if is_signed => 7,
1158        32 if !is_signed => 7,
1159        64 if is_signed => 13,
1160        64 if !is_signed => 14,
1161        128 if is_signed => 27,
1162        128 if !is_signed => 27,
1163        _ => 1,
1164    }
1165}
1166
1167#[inline(always)]
1168#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1169const fn min_step_29(bits: usize, is_signed: bool) -> usize {
1170    match bits {
1171        8 if is_signed => 1,
1172        8 if !is_signed => 1,
1173        16 if is_signed => 3,
1174        16 if !is_signed => 3,
1175        32 if is_signed => 6,
1176        32 if !is_signed => 6,
1177        64 if is_signed => 12,
1178        64 if !is_signed => 13,
1179        128 if is_signed => 26,
1180        128 if !is_signed => 26,
1181        _ => 1,
1182    }
1183}
1184
1185#[inline(always)]
1186#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1187const fn max_step_30(bits: usize, is_signed: bool) -> usize {
1188    match bits {
1189        8 if is_signed => 2,
1190        8 if !is_signed => 2,
1191        16 if is_signed => 4,
1192        16 if !is_signed => 4,
1193        32 if is_signed => 7,
1194        32 if !is_signed => 7,
1195        64 if is_signed => 13,
1196        64 if !is_signed => 14,
1197        128 if is_signed => 26,
1198        128 if !is_signed => 27,
1199        _ => 1,
1200    }
1201}
1202
1203#[inline(always)]
1204#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1205const fn min_step_30(bits: usize, is_signed: bool) -> usize {
1206    match bits {
1207        8 if is_signed => 1,
1208        8 if !is_signed => 1,
1209        16 if is_signed => 3,
1210        16 if !is_signed => 3,
1211        32 if is_signed => 6,
1212        32 if !is_signed => 6,
1213        64 if is_signed => 12,
1214        64 if !is_signed => 13,
1215        128 if is_signed => 25,
1216        128 if !is_signed => 26,
1217        _ => 1,
1218    }
1219}
1220
1221#[inline(always)]
1222#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1223const fn max_step_31(bits: usize, is_signed: bool) -> usize {
1224    match bits {
1225        8 if is_signed => 2,
1226        8 if !is_signed => 2,
1227        16 if is_signed => 4,
1228        16 if !is_signed => 4,
1229        32 if is_signed => 7,
1230        32 if !is_signed => 7,
1231        64 if is_signed => 13,
1232        64 if !is_signed => 13,
1233        128 if is_signed => 26,
1234        128 if !is_signed => 26,
1235        _ => 1,
1236    }
1237}
1238
1239#[inline(always)]
1240#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1241const fn min_step_31(bits: usize, is_signed: bool) -> usize {
1242    match bits {
1243        8 if is_signed => 1,
1244        8 if !is_signed => 1,
1245        16 if is_signed => 3,
1246        16 if !is_signed => 3,
1247        32 if is_signed => 6,
1248        32 if !is_signed => 6,
1249        64 if is_signed => 12,
1250        64 if !is_signed => 12,
1251        128 if is_signed => 25,
1252        128 if !is_signed => 25,
1253        _ => 1,
1254    }
1255}
1256
1257#[inline(always)]
1258#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
1259const fn max_step_32(bits: usize, is_signed: bool) -> usize {
1260    match bits {
1261        8 if is_signed => 2,
1262        8 if !is_signed => 2,
1263        16 if is_signed => 3,
1264        16 if !is_signed => 4,
1265        32 if is_signed => 7,
1266        32 if !is_signed => 7,
1267        64 if is_signed => 13,
1268        64 if !is_signed => 13,
1269        128 if is_signed => 26,
1270        128 if !is_signed => 26,
1271        _ => 1,
1272    }
1273}
1274
1275#[inline(always)]
1276#[cfg_attr(not(feature = "power-of-two"), allow(dead_code))]
1277const fn min_step_32(bits: usize, is_signed: bool) -> usize {
1278    match bits {
1279        8 if is_signed => 1,
1280        8 if !is_signed => 1,
1281        16 if is_signed => 3,
1282        16 if !is_signed => 3,
1283        32 if is_signed => 6,
1284        32 if !is_signed => 6,
1285        64 if is_signed => 12,
1286        64 if !is_signed => 12,
1287        128 if is_signed => 25,
1288        128 if !is_signed => 25,
1289        _ => 1,
1290    }
1291}
1292
1293#[inline(always)]
1294#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1295const fn max_step_33(bits: usize, is_signed: bool) -> usize {
1296    match bits {
1297        8 if is_signed => 2,
1298        8 if !is_signed => 2,
1299        16 if is_signed => 3,
1300        16 if !is_signed => 4,
1301        32 if is_signed => 7,
1302        32 if !is_signed => 7,
1303        64 if is_signed => 13,
1304        64 if !is_signed => 13,
1305        128 if is_signed => 26,
1306        128 if !is_signed => 26,
1307        _ => 1,
1308    }
1309}
1310
1311#[inline(always)]
1312#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1313const fn min_step_33(bits: usize, is_signed: bool) -> usize {
1314    match bits {
1315        8 if is_signed => 1,
1316        8 if !is_signed => 1,
1317        16 if is_signed => 2,
1318        16 if !is_signed => 3,
1319        32 if is_signed => 6,
1320        32 if !is_signed => 6,
1321        64 if is_signed => 12,
1322        64 if !is_signed => 12,
1323        128 if is_signed => 25,
1324        128 if !is_signed => 25,
1325        _ => 1,
1326    }
1327}
1328
1329#[inline(always)]
1330#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1331const fn max_step_34(bits: usize, is_signed: bool) -> usize {
1332    match bits {
1333        8 if is_signed => 2,
1334        8 if !is_signed => 2,
1335        16 if is_signed => 3,
1336        16 if !is_signed => 4,
1337        32 if is_signed => 7,
1338        32 if !is_signed => 7,
1339        64 if is_signed => 13,
1340        64 if !is_signed => 13,
1341        128 if is_signed => 25,
1342        128 if !is_signed => 26,
1343        _ => 1,
1344    }
1345}
1346
1347#[inline(always)]
1348#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1349const fn min_step_34(bits: usize, is_signed: bool) -> usize {
1350    match bits {
1351        8 if is_signed => 1,
1352        8 if !is_signed => 1,
1353        16 if is_signed => 2,
1354        16 if !is_signed => 3,
1355        32 if is_signed => 6,
1356        32 if !is_signed => 6,
1357        64 if is_signed => 12,
1358        64 if !is_signed => 12,
1359        128 if is_signed => 24,
1360        128 if !is_signed => 25,
1361        _ => 1,
1362    }
1363}
1364
1365#[inline(always)]
1366#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1367const fn max_step_35(bits: usize, is_signed: bool) -> usize {
1368    match bits {
1369        8 if is_signed => 2,
1370        8 if !is_signed => 2,
1371        16 if is_signed => 3,
1372        16 if !is_signed => 4,
1373        32 if is_signed => 7,
1374        32 if !is_signed => 7,
1375        64 if is_signed => 13,
1376        64 if !is_signed => 13,
1377        128 if is_signed => 25,
1378        128 if !is_signed => 25,
1379        _ => 1,
1380    }
1381}
1382
1383#[inline(always)]
1384#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1385const fn min_step_35(bits: usize, is_signed: bool) -> usize {
1386    match bits {
1387        8 if is_signed => 1,
1388        8 if !is_signed => 1,
1389        16 if is_signed => 2,
1390        16 if !is_signed => 3,
1391        32 if is_signed => 6,
1392        32 if !is_signed => 6,
1393        64 if is_signed => 12,
1394        64 if !is_signed => 12,
1395        128 if is_signed => 24,
1396        128 if !is_signed => 24,
1397        _ => 1,
1398    }
1399}
1400
1401#[inline(always)]
1402#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1403const fn max_step_36(bits: usize, is_signed: bool) -> usize {
1404    match bits {
1405        8 if is_signed => 2,
1406        8 if !is_signed => 2,
1407        16 if is_signed => 3,
1408        16 if !is_signed => 4,
1409        32 if is_signed => 6,
1410        32 if !is_signed => 7,
1411        64 if is_signed => 13,
1412        64 if !is_signed => 13,
1413        128 if is_signed => 25,
1414        128 if !is_signed => 25,
1415        _ => 1,
1416    }
1417}
1418
1419#[inline(always)]
1420#[cfg_attr(not(feature = "radix"), allow(dead_code))]
1421const fn min_step_36(bits: usize, is_signed: bool) -> usize {
1422    match bits {
1423        8 if is_signed => 1,
1424        8 if !is_signed => 1,
1425        16 if is_signed => 2,
1426        16 if !is_signed => 3,
1427        32 if is_signed => 5,
1428        32 if !is_signed => 6,
1429        64 if is_signed => 12,
1430        64 if !is_signed => 12,
1431        128 if is_signed => 24,
1432        128 if !is_signed => 24,
1433        _ => 1,
1434    }
1435}