Skip to content

Commit 7f1db48

Browse files
committed
fix u128 for older Rust
1 parent 5be6ea1 commit 7f1db48

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/power10.rs

+22-14
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,28 @@ static POWER10_HASH_U64: [u64;32] = [1, 100000000000, 10000000000000000, 0, 1000
3030
0, 1000, 0, 0, 0, 1000000000000, 0, 1000000000000000, 0, 100000000000000,
3131
1000000000000000000, 100, 100000000, 100000000000000000, 0, 10000000000000000000,
3232
10000, 100000, 0, 1000000000, 0, 10000000000, 0];
33+
3334
#[cfg(has_i128)]
34-
static POWER10_HASH_U128: [u128;64] = [100000000000000000000000000000000000, 0, 100000000000000000000000000000000,
35-
0, 1000, 0, 0, 0, 0,
36-
1000000000000000000000000000000000000, 1000000000, 0, 100000000000000, 100, 0, 0, 0, 100000, 0, 0,
37-
10000000000000, 100000000000, 10000000000000000000, 0, 0, 10000000000000000000000000000000000,
38-
100000000, 0, 1000000000000000000000000000000000, 1000000000000, 0, 100000000000000000000000000000000000000,
39-
10000000000000000, 100000000000000000000000000, 0, 10000000000000000000000000000000000000,
40-
1000000000000000000, 1, 10000000000000000000000000, 1000000000000000000000000, 100000000000000000000000000000,
41-
10000000, 10000000000000000000000000000, 0, 1000000000000000000000000000, 100000000000000000, 10000,
42-
0, 1000000, 1000000000000000000000000000000, 0, 100000000000000000000, 10, 0, 10000000000,
43-
10000000000000000000000, 0, 0, 10000000000000000000000000000000, 1000000000000000000000, 0,
44-
100000000000000000000000, 1000000000000000, 0];
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+
}
4555

4656
// implementation note: reverse search is a bit faster than hash lookup for u8
4757
#[inline]
@@ -76,9 +86,7 @@ fn is_pow10_u64(v: u64) -> bool {
7686
#[cfg(has_i128)]
7787
#[inline]
7888
fn is_pow10_u128(v: u128) -> bool {
79-
let mut hash: u32 = v as u32 | (((v as u64) >> 32) as u32);
80-
hash = hash.wrapping_mul(1249991743).rotate_right(25);
81-
v == POWER10_HASH_U128[(hash & 63) as usize]
89+
pow10_u128::is_pow10_u128(v)
8290
}
8391

8492
#[cfg(target_pointer_width = "64")]

0 commit comments

Comments
 (0)