Skip to content

Commit 403dcd6

Browse files
committed
fix u128 for older Rust - 2nd try
1 parent 7f1db48 commit 403dcd6

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/power10.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@ static POWER10_HASH_U64: [u64;32] = [1, 100000000000, 10000000000000000, 0, 1000
3131
1000000000000000000, 100, 100000000, 100000000000000000, 0, 10000000000000000000,
3232
10000, 100000, 0, 1000000000, 0, 10000000000, 0];
3333

34-
#[cfg(has_i128)]
35-
mod pow10_u128 {
36-
static POWER10_HASH_U128: [u128; 64] = [100000000000000000000000000000000000, 0, 100000000000000000000000000000000,
37-
0, 1000, 0, 0, 0, 0,
38-
1000000000000000000000000000000000000, 1000000000, 0, 100000000000000, 100, 0, 0, 0, 100000, 0, 0,
39-
10000000000000, 100000000000, 10000000000000000000, 0, 0, 10000000000000000000000000000000000,
40-
100000000, 0, 1000000000000000000000000000000000, 1000000000000, 0, 100000000000000000000000000000000000000,
41-
10000000000000000, 100000000000000000000000000, 0, 10000000000000000000000000000000000000,
42-
1000000000000000000, 1, 10000000000000000000000000, 1000000000000000000000000, 100000000000000000000000000000,
43-
10000000, 10000000000000000000000000000, 0, 1000000000000000000000000000, 100000000000000000, 10000,
44-
0, 1000000, 1000000000000000000000000000000, 0, 100000000000000000000, 10, 0, 10000000000,
45-
10000000000000000000000, 0, 0, 10000000000000000000000000000000, 1000000000000000000000, 0,
46-
100000000000000000000000, 1000000000000000, 0];
47-
48-
#[inline]
49-
pub fn is_pow10_u128(v: u128) -> bool {
50-
let mut hash: u32 = v as u32 | (((v as u64) >> 32) as u32);
51-
hash = hash.wrapping_mul(1249991743).rotate_right(25);
52-
v == POWER10_HASH_U128[(hash & 63) as usize]
53-
}
54-
}
55-
5634
// implementation note: reverse search is a bit faster than hash lookup for u8
5735
#[inline]
5836
fn is_pow10_u8(v: u8) -> bool {
@@ -83,12 +61,6 @@ fn is_pow10_u64(v: u64) -> bool {
8361
v == POWER10_HASH_U64[(hash & 31) as usize]
8462
}
8563

86-
#[cfg(has_i128)]
87-
#[inline]
88-
fn is_pow10_u128(v: u128) -> bool {
89-
pow10_u128::is_pow10_u128(v)
90-
}
91-
9264
#[cfg(target_pointer_width = "64")]
9365
#[inline]
9466
fn is_pow10_usize(v: usize) -> bool {
@@ -101,6 +73,33 @@ fn is_pow10_usize(v: usize) -> bool {
10173
is_pow10_u32(v as u32)
10274
}
10375

76+
macro_rules! hide_u128 {
77+
($T:ty) => {
78+
static POWER10_HASH_U128: [$T; 64] = [100000000000000000000000000000000000, 0, 100000000000000000000000000000000,
79+
0, 1000, 0, 0, 0, 0,
80+
1000000000000000000000000000000000000, 1000000000, 0, 100000000000000, 100, 0, 0, 0, 100000, 0, 0,
81+
10000000000000, 100000000000, 10000000000000000000, 0, 0, 10000000000000000000000000000000000,
82+
100000000, 0, 1000000000000000000000000000000000, 1000000000000, 0, 100000000000000000000000000000000000000,
83+
10000000000000000, 100000000000000000000000000, 0, 10000000000000000000000000000000000000,
84+
1000000000000000000, 1, 10000000000000000000000000, 1000000000000000000000000, 100000000000000000000000000000,
85+
10000000, 10000000000000000000000000000, 0, 1000000000000000000000000000, 100000000000000000, 10000,
86+
0, 1000000, 1000000000000000000000000000000, 0, 100000000000000000000, 10, 0, 10000000000,
87+
10000000000000000000000, 0, 0, 10000000000000000000000000000000, 1000000000000000000000, 0,
88+
100000000000000000000000, 1000000000000000, 0];
89+
90+
#[inline]
91+
pub fn is_pow10_u128(v: $T) -> bool {
92+
let mut hash: u32 = v as u32 | (((v as u64) >> 32) as u32);
93+
hash = hash.wrapping_mul(1249991743).rotate_right(25);
94+
v == POWER10_HASH_U128[(hash & 63) as usize]
95+
}
96+
97+
}
98+
}
99+
100+
#[cfg(has_i128)]
101+
hide_u128!(u128);
102+
104103
macro_rules! unsigned_power10 {
105104
($T:ty, $pow_fn: ident) => {
106105
impl Power10 for $T {

0 commit comments

Comments
 (0)