1#![doc(hidden)]
4#![cfg(not(feature = "compact"))]
5
6use static_assertions::const_assert;
7
8#[cfg(not(feature = "radix"))]
9use crate::bigint::Limb;
10use crate::limits::{f32_exponent_limit, f64_exponent_limit, f64_mantissa_limit, u64_power_limit};
11
12#[must_use]
17#[inline(always)]
18#[cfg(not(feature = "power-of-two"))]
19pub const fn get_small_int_power(exponent: usize, radix: u32) -> u64 {
20 match radix {
22 5 => get_small_int_power5(exponent),
23 10 => get_small_int_power10(exponent),
24 _ => unreachable!(),
25 }
26}
27
28#[must_use]
30#[inline(always)]
31#[cfg(not(feature = "power-of-two"))]
32pub const fn get_small_f32_power(exponent: usize, radix: u32) -> f32 {
33 _ = radix;
34 get_small_f32_power10(exponent)
35}
36
37#[must_use]
39#[inline(always)]
40#[cfg(not(feature = "power-of-two"))]
41pub const fn get_small_f64_power(exponent: usize, radix: u32) -> f64 {
42 _ = radix;
43 get_small_f64_power10(exponent)
44}
45
46#[must_use]
48#[inline(always)]
49#[cfg(not(feature = "radix"))]
50pub const fn get_large_int_power(_: u32) -> (&'static [Limb], u32) {
51 (&LARGE_POW5, LARGE_POW5_STEP)
52}
53
54#[must_use]
56#[inline(always)]
57pub const fn get_small_int_power5(exponent: usize) -> u64 {
58 SMALL_INT_POW5[exponent]
59}
60
61#[must_use]
63#[inline(always)]
64pub const fn get_small_int_power10(exponent: usize) -> u64 {
65 SMALL_INT_POW10[exponent]
66}
67
68#[must_use]
70#[inline(always)]
71pub const fn get_small_f32_power10(exponent: usize) -> f32 {
72 SMALL_F32_POW10[exponent]
73}
74
75#[must_use]
77#[inline(always)]
78pub const fn get_small_f64_power10(exponent: usize) -> f64 {
79 SMALL_F64_POW10[exponent]
80}
81
82pub const SMALL_INT_POW5: [u64; 28] = [
87 1,
88 5,
89 25,
90 125,
91 625,
92 3125,
93 15625,
94 78125,
95 390625,
96 1953125,
97 9765625,
98 48828125,
99 244140625,
100 1220703125,
101 6103515625,
102 30517578125,
103 152587890625,
104 762939453125,
105 3814697265625,
106 19073486328125,
107 95367431640625,
108 476837158203125,
109 2384185791015625,
110 11920928955078125,
111 59604644775390625,
112 298023223876953125,
113 1490116119384765625,
114 7450580596923828125,
115];
116const_assert!(SMALL_INT_POW5.len() > f64_mantissa_limit(5) as usize);
117const_assert!(SMALL_INT_POW5.len() == u64_power_limit(5) as usize + 1);
118
119pub const SMALL_INT_POW10: [u64; 20] = [
121 1,
122 10,
123 100,
124 1000,
125 10000,
126 100000,
127 1000000,
128 10000000,
129 100000000,
130 1000000000,
131 10000000000,
132 100000000000,
133 1000000000000,
134 10000000000000,
135 100000000000000,
136 1000000000000000,
137 10000000000000000,
138 100000000000000000,
139 1000000000000000000,
140 10000000000000000000,
141];
142const_assert!(SMALL_INT_POW10.len() > f64_mantissa_limit(10) as usize);
143const_assert!(SMALL_INT_POW10.len() == u64_power_limit(10) as usize + 1);
144
145pub const SMALL_F32_POW10: [f32; 16] =
147 [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 0., 0., 0., 0., 0.];
148const_assert!(SMALL_F32_POW10.len() > f32_exponent_limit(10).1 as usize);
149
150pub const SMALL_F64_POW10: [f64; 32] = [
152 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16,
153 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 0., 0., 0., 0., 0., 0., 0., 0., 0.,
154];
155const_assert!(SMALL_F64_POW10.len() > f64_exponent_limit(10).1 as usize);
156
157#[cfg(not(all(target_pointer_width = "64", not(target_arch = "sparc"))))]
159pub const LARGE_POW5: [u32; 10] = [
160 4279965485, 329373468, 4020270615, 2137533757, 4287402176, 1057042919, 1071430142, 2440757623,
161 381945767, 46164893,
162];
163
164#[cfg(all(target_pointer_width = "64", not(target_arch = "sparc")))]
166pub const LARGE_POW5: [u64; 5] = [
167 1414648277510068013,
168 9180637584431281687,
169 4539964771860779200,
170 10482974169319127550,
171 198276706040285095,
172];
173
174pub const LARGE_POW5_STEP: u32 = 135;