Add fn to_radix() for radix > 36.
This commit is contained in:
parent
b1b034f438
commit
1ab07df709
|
@ -1033,6 +1033,26 @@ impl BigInt {
|
|||
unsafe { String::from_utf8_unchecked(v) }
|
||||
}
|
||||
|
||||
/// Returns the integer in a given base. Each digit is given as an u8
|
||||
/// number. Conversion to an alphabet has to be performed afterwards.
|
||||
/// In contrast to the usual arabic style of written numbers as returned by
|
||||
/// `to_str_radix`, the most significant digit comes last.
|
||||
/// `radix` must be in the range `[2, 256]`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use num_bigint::{BigInt, Sign};
|
||||
///
|
||||
/// assert_eq!(BigInt::from(-0xFFFFi64).to_radix(159),
|
||||
/// (Sign::Minus, vec![27, 94, 2]));
|
||||
/// // 0xFFFF = 65535 = 27 + 94*159 + 2*(159^2)
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn to_radix(&self, radix: u32) -> (Sign, Vec<u8>) {
|
||||
(self.sign, self.data.to_radix(radix))
|
||||
}
|
||||
|
||||
/// Returns the sign of the `BigInt` as a `Sign`.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
@ -887,14 +887,10 @@ fn to_radix_digits_le(u: &BigUint, radix: u32) -> Vec<u8> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn to_str_radix_reversed(u: &BigUint, radix: u32) -> Vec<u8> {
|
||||
assert!(2 <= radix && radix <= 36, "The radix must be within 2...36");
|
||||
|
||||
pub fn to_radix_reversed(u: &BigUint, radix: u32) -> Vec<u8> {
|
||||
if u.is_zero() {
|
||||
return vec![b'0'];
|
||||
}
|
||||
|
||||
let mut res = if radix.is_power_of_two() {
|
||||
vec![0]
|
||||
} else if radix.is_power_of_two() {
|
||||
// Powers of two can use bitwise masks and shifting instead of division
|
||||
let bits = ilog2(radix);
|
||||
if big_digit::BITS % bits == 0 {
|
||||
|
@ -908,7 +904,17 @@ pub fn to_str_radix_reversed(u: &BigUint, radix: u32) -> Vec<u8> {
|
|||
to_radix_digits_le(u, 10)
|
||||
} else {
|
||||
to_radix_digits_le(u, radix)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_str_radix_reversed(u: &BigUint, radix: u32) -> Vec<u8> {
|
||||
assert!(2 <= radix && radix <= 36, "The radix must be within 2...36");
|
||||
|
||||
if u.is_zero() {
|
||||
return vec![b'0'];
|
||||
}
|
||||
|
||||
let mut res = to_radix_reversed(u, radix);
|
||||
|
||||
// Now convert everything to ASCII digits.
|
||||
for r in &mut res {
|
||||
|
@ -1034,6 +1040,26 @@ impl BigUint {
|
|||
unsafe { String::from_utf8_unchecked(v) }
|
||||
}
|
||||
|
||||
/// Returns the integer in a given base. Each digit is given as an u8
|
||||
/// number. Conversion to an alphabet has to be performed afterwards.
|
||||
/// In contrast to the usual arabic style of written numbers as returned by
|
||||
/// `to_str_radix`, the most significant digit comes last.
|
||||
/// `radix` must be in the range `[2, 256]`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use num_bigint::BigUint;
|
||||
///
|
||||
/// assert_eq!(BigUint::from(0xFFFFu64).to_radix(159),
|
||||
/// vec![27, 94, 2]);
|
||||
/// // 0xFFFF = 65535 = 27 + 94*159 + 2*(159^2)
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn to_radix(&self, radix: u32) -> Vec<u8> {
|
||||
to_radix_reversed(self, radix)
|
||||
}
|
||||
|
||||
/// Creates and initializes a `BigUint`.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -1093,11 +1119,11 @@ impl serde::Deserialize for BigUint {
|
|||
/// Returns the greatest power of the radix <= big_digit::BASE
|
||||
#[inline]
|
||||
fn get_radix_base(radix: u32) -> (BigDigit, usize) {
|
||||
debug_assert!(2 <= radix && radix <= 36, "The radix must be within 2...36");
|
||||
debug_assert!(2 <= radix && radix <= 256, "The radix must be within 2...256");
|
||||
debug_assert!(!radix.is_power_of_two());
|
||||
|
||||
// To generate this table:
|
||||
// for radix in 2u64..37 {
|
||||
// for radix in 2u64..257 {
|
||||
// let mut power = big_digit::BITS / fls(radix as u64);
|
||||
// let mut base = radix.pow(power as u32);
|
||||
//
|
||||
|
@ -1111,87 +1137,542 @@ fn get_radix_base(radix: u32) -> (BigDigit, usize) {
|
|||
//
|
||||
// println!("({:10}, {:2}), // {:2}", base, power, radix);
|
||||
// }
|
||||
|
||||
// and
|
||||
// for radix in 2u64..257 {
|
||||
// let mut power = 64 / fls(radix as u64);
|
||||
// let mut base = radix.pow(power as u32);
|
||||
//
|
||||
// while let Some(b) = base.checked_mul(radix) {
|
||||
// base = b;
|
||||
// power += 1;
|
||||
// }
|
||||
//
|
||||
// println!("({:20}, {:2}), // {:2}", base, power, radix);
|
||||
// }
|
||||
match big_digit::BITS {
|
||||
32 => {
|
||||
const BASES: [(u32, usize); 37] = [(0, 0), (0, 0),
|
||||
(0, 0), // 2
|
||||
(3486784401, 20),// 3
|
||||
(0, 0), // 4
|
||||
(1220703125, 13),// 5
|
||||
(2176782336, 12),// 6
|
||||
(1977326743, 11),// 7
|
||||
(0, 0), // 8
|
||||
(3486784401, 10),// 9
|
||||
(1000000000, 9), // 10
|
||||
(2357947691, 9), // 11
|
||||
(429981696, 8), // 12
|
||||
(815730721, 8), // 13
|
||||
(1475789056, 8), // 14
|
||||
(2562890625, 8), // 15
|
||||
(0, 0), // 16
|
||||
(410338673, 7), // 17
|
||||
(612220032, 7), // 18
|
||||
(893871739, 7), // 19
|
||||
(1280000000, 7), // 20
|
||||
(1801088541, 7), // 21
|
||||
(2494357888, 7), // 22
|
||||
(3404825447, 7), // 23
|
||||
(191102976, 6), // 24
|
||||
(244140625, 6), // 25
|
||||
(308915776, 6), // 26
|
||||
(387420489, 6), // 27
|
||||
(481890304, 6), // 28
|
||||
(594823321, 6), // 29
|
||||
(729000000, 6), // 30
|
||||
(887503681, 6), // 31
|
||||
(0, 0), // 32
|
||||
(1291467969, 6), // 33
|
||||
(1544804416, 6), // 34
|
||||
(1838265625, 6), // 35
|
||||
(2176782336, 6) // 36
|
||||
const BASES: [(u32, usize); 257] = [
|
||||
( 0, 0),
|
||||
( 0, 0),
|
||||
( 0, 0), // 2
|
||||
(3486784401, 20), // 3
|
||||
( 0, 0), // 4
|
||||
(1220703125, 13), // 5
|
||||
(2176782336, 12), // 6
|
||||
(1977326743, 11), // 7
|
||||
( 0, 0), // 8
|
||||
(3486784401, 10), // 9
|
||||
(1000000000, 9), // 10
|
||||
(2357947691, 9), // 11
|
||||
( 429981696, 8), // 12
|
||||
( 815730721, 8), // 13
|
||||
(1475789056, 8), // 14
|
||||
(2562890625, 8), // 15
|
||||
( 0, 0), // 16
|
||||
( 410338673, 7), // 17
|
||||
( 612220032, 7), // 18
|
||||
( 893871739, 7), // 19
|
||||
(1280000000, 7), // 20
|
||||
(1801088541, 7), // 21
|
||||
(2494357888, 7), // 22
|
||||
(3404825447, 7), // 23
|
||||
( 191102976, 6), // 24
|
||||
( 244140625, 6), // 25
|
||||
( 308915776, 6), // 26
|
||||
( 387420489, 6), // 27
|
||||
( 481890304, 6), // 28
|
||||
( 594823321, 6), // 29
|
||||
( 729000000, 6), // 30
|
||||
( 887503681, 6), // 31
|
||||
( 0, 0), // 32
|
||||
(1291467969, 6), // 33
|
||||
(1544804416, 6), // 34
|
||||
(1838265625, 6), // 35
|
||||
(2176782336, 6), // 36
|
||||
(2565726409, 6), // 37
|
||||
(3010936384, 6), // 38
|
||||
(3518743761, 6), // 39
|
||||
(4096000000, 6), // 40
|
||||
( 115856201, 5), // 41
|
||||
( 130691232, 5), // 42
|
||||
( 147008443, 5), // 43
|
||||
( 164916224, 5), // 44
|
||||
( 184528125, 5), // 45
|
||||
( 205962976, 5), // 46
|
||||
( 229345007, 5), // 47
|
||||
( 254803968, 5), // 48
|
||||
( 282475249, 5), // 49
|
||||
( 312500000, 5), // 50
|
||||
( 345025251, 5), // 51
|
||||
( 380204032, 5), // 52
|
||||
( 418195493, 5), // 53
|
||||
( 459165024, 5), // 54
|
||||
( 503284375, 5), // 55
|
||||
( 550731776, 5), // 56
|
||||
( 601692057, 5), // 57
|
||||
( 656356768, 5), // 58
|
||||
( 714924299, 5), // 59
|
||||
( 777600000, 5), // 60
|
||||
( 844596301, 5), // 61
|
||||
( 916132832, 5), // 62
|
||||
( 992436543, 5), // 63
|
||||
( 0, 0), // 64
|
||||
(1160290625, 5), // 65
|
||||
(1252332576, 5), // 66
|
||||
(1350125107, 5), // 67
|
||||
(1453933568, 5), // 68
|
||||
(1564031349, 5), // 69
|
||||
(1680700000, 5), // 70
|
||||
(1804229351, 5), // 71
|
||||
(1934917632, 5), // 72
|
||||
(2073071593, 5), // 73
|
||||
(2219006624, 5), // 74
|
||||
(2373046875, 5), // 75
|
||||
(2535525376, 5), // 76
|
||||
(2706784157, 5), // 77
|
||||
(2887174368, 5), // 78
|
||||
(3077056399, 5), // 79
|
||||
(3276800000, 5), // 80
|
||||
(3486784401, 5), // 81
|
||||
(3707398432, 5), // 82
|
||||
(3939040643, 5), // 83
|
||||
(4182119424, 5), // 84
|
||||
( 52200625, 4), // 85
|
||||
( 54700816, 4), // 86
|
||||
( 57289761, 4), // 87
|
||||
( 59969536, 4), // 88
|
||||
( 62742241, 4), // 89
|
||||
( 65610000, 4), // 90
|
||||
( 68574961, 4), // 91
|
||||
( 71639296, 4), // 92
|
||||
( 74805201, 4), // 93
|
||||
( 78074896, 4), // 94
|
||||
( 81450625, 4), // 95
|
||||
( 84934656, 4), // 96
|
||||
( 88529281, 4), // 97
|
||||
( 92236816, 4), // 98
|
||||
( 96059601, 4), // 99
|
||||
( 100000000, 4), // 100
|
||||
( 104060401, 4), // 101
|
||||
( 108243216, 4), // 102
|
||||
( 112550881, 4), // 103
|
||||
( 116985856, 4), // 104
|
||||
( 121550625, 4), // 105
|
||||
( 126247696, 4), // 106
|
||||
( 131079601, 4), // 107
|
||||
( 136048896, 4), // 108
|
||||
( 141158161, 4), // 109
|
||||
( 146410000, 4), // 110
|
||||
( 151807041, 4), // 111
|
||||
( 157351936, 4), // 112
|
||||
( 163047361, 4), // 113
|
||||
( 168896016, 4), // 114
|
||||
( 174900625, 4), // 115
|
||||
( 181063936, 4), // 116
|
||||
( 187388721, 4), // 117
|
||||
( 193877776, 4), // 118
|
||||
( 200533921, 4), // 119
|
||||
( 207360000, 4), // 120
|
||||
( 214358881, 4), // 121
|
||||
( 221533456, 4), // 122
|
||||
( 228886641, 4), // 123
|
||||
( 236421376, 4), // 124
|
||||
( 244140625, 4), // 125
|
||||
( 252047376, 4), // 126
|
||||
( 260144641, 4), // 127
|
||||
( 0, 0), // 128
|
||||
( 276922881, 4), // 129
|
||||
( 285610000, 4), // 130
|
||||
( 294499921, 4), // 131
|
||||
( 303595776, 4), // 132
|
||||
( 312900721, 4), // 133
|
||||
( 322417936, 4), // 134
|
||||
( 332150625, 4), // 135
|
||||
( 342102016, 4), // 136
|
||||
( 352275361, 4), // 137
|
||||
( 362673936, 4), // 138
|
||||
( 373301041, 4), // 139
|
||||
( 384160000, 4), // 140
|
||||
( 395254161, 4), // 141
|
||||
( 406586896, 4), // 142
|
||||
( 418161601, 4), // 143
|
||||
( 429981696, 4), // 144
|
||||
( 442050625, 4), // 145
|
||||
( 454371856, 4), // 146
|
||||
( 466948881, 4), // 147
|
||||
( 479785216, 4), // 148
|
||||
( 492884401, 4), // 149
|
||||
( 506250000, 4), // 150
|
||||
( 519885601, 4), // 151
|
||||
( 533794816, 4), // 152
|
||||
( 547981281, 4), // 153
|
||||
( 562448656, 4), // 154
|
||||
( 577200625, 4), // 155
|
||||
( 592240896, 4), // 156
|
||||
( 607573201, 4), // 157
|
||||
( 623201296, 4), // 158
|
||||
( 639128961, 4), // 159
|
||||
( 655360000, 4), // 160
|
||||
( 671898241, 4), // 161
|
||||
( 688747536, 4), // 162
|
||||
( 705911761, 4), // 163
|
||||
( 723394816, 4), // 164
|
||||
( 741200625, 4), // 165
|
||||
( 759333136, 4), // 166
|
||||
( 777796321, 4), // 167
|
||||
( 796594176, 4), // 168
|
||||
( 815730721, 4), // 169
|
||||
( 835210000, 4), // 170
|
||||
( 855036081, 4), // 171
|
||||
( 875213056, 4), // 172
|
||||
( 895745041, 4), // 173
|
||||
( 916636176, 4), // 174
|
||||
( 937890625, 4), // 175
|
||||
( 959512576, 4), // 176
|
||||
( 981506241, 4), // 177
|
||||
(1003875856, 4), // 178
|
||||
(1026625681, 4), // 179
|
||||
(1049760000, 4), // 180
|
||||
(1073283121, 4), // 181
|
||||
(1097199376, 4), // 182
|
||||
(1121513121, 4), // 183
|
||||
(1146228736, 4), // 184
|
||||
(1171350625, 4), // 185
|
||||
(1196883216, 4), // 186
|
||||
(1222830961, 4), // 187
|
||||
(1249198336, 4), // 188
|
||||
(1275989841, 4), // 189
|
||||
(1303210000, 4), // 190
|
||||
(1330863361, 4), // 191
|
||||
(1358954496, 4), // 192
|
||||
(1387488001, 4), // 193
|
||||
(1416468496, 4), // 194
|
||||
(1445900625, 4), // 195
|
||||
(1475789056, 4), // 196
|
||||
(1506138481, 4), // 197
|
||||
(1536953616, 4), // 198
|
||||
(1568239201, 4), // 199
|
||||
(1600000000, 4), // 200
|
||||
(1632240801, 4), // 201
|
||||
(1664966416, 4), // 202
|
||||
(1698181681, 4), // 203
|
||||
(1731891456, 4), // 204
|
||||
(1766100625, 4), // 205
|
||||
(1800814096, 4), // 206
|
||||
(1836036801, 4), // 207
|
||||
(1871773696, 4), // 208
|
||||
(1908029761, 4), // 209
|
||||
(1944810000, 4), // 210
|
||||
(1982119441, 4), // 211
|
||||
(2019963136, 4), // 212
|
||||
(2058346161, 4), // 213
|
||||
(2097273616, 4), // 214
|
||||
(2136750625, 4), // 215
|
||||
(2176782336, 4), // 216
|
||||
(2217373921, 4), // 217
|
||||
(2258530576, 4), // 218
|
||||
(2300257521, 4), // 219
|
||||
(2342560000, 4), // 220
|
||||
(2385443281, 4), // 221
|
||||
(2428912656, 4), // 222
|
||||
(2472973441, 4), // 223
|
||||
(2517630976, 4), // 224
|
||||
(2562890625, 4), // 225
|
||||
(2608757776, 4), // 226
|
||||
(2655237841, 4), // 227
|
||||
(2702336256, 4), // 228
|
||||
(2750058481, 4), // 229
|
||||
(2798410000, 4), // 230
|
||||
(2847396321, 4), // 231
|
||||
(2897022976, 4), // 232
|
||||
(2947295521, 4), // 233
|
||||
(2998219536, 4), // 234
|
||||
(3049800625, 4), // 235
|
||||
(3102044416, 4), // 236
|
||||
(3154956561, 4), // 237
|
||||
(3208542736, 4), // 238
|
||||
(3262808641, 4), // 239
|
||||
(3317760000, 4), // 240
|
||||
(3373402561, 4), // 241
|
||||
(3429742096, 4), // 242
|
||||
(3486784401, 4), // 243
|
||||
(3544535296, 4), // 244
|
||||
(3603000625, 4), // 245
|
||||
(3662186256, 4), // 246
|
||||
(3722098081, 4), // 247
|
||||
(3782742016, 4), // 248
|
||||
(3844124001, 4), // 249
|
||||
(3906250000, 4), // 250
|
||||
(3969126001, 4), // 251
|
||||
(4032758016, 4), // 252
|
||||
(4097152081, 4), // 253
|
||||
(4162314256, 4), // 254
|
||||
(4228250625, 4), // 255
|
||||
( 0, 0), // 256
|
||||
];
|
||||
|
||||
let (base, power) = BASES[radix as usize];
|
||||
(base as BigDigit, power)
|
||||
}
|
||||
64 => {
|
||||
const BASES: [(u64, usize); 37] = [(0, 0), (0, 0),
|
||||
(9223372036854775808, 63), // 2
|
||||
(12157665459056928801, 40), // 3
|
||||
(4611686018427387904, 31), // 4
|
||||
(7450580596923828125, 27), // 5
|
||||
(4738381338321616896, 24), // 6
|
||||
(3909821048582988049, 22), // 7
|
||||
(9223372036854775808, 21), // 8
|
||||
(12157665459056928801, 20), // 9
|
||||
(10000000000000000000, 19), // 10
|
||||
(5559917313492231481, 18), // 11
|
||||
(2218611106740436992, 17), // 12
|
||||
(8650415919381337933, 17), // 13
|
||||
(2177953337809371136, 16), // 14
|
||||
(6568408355712890625, 16), // 15
|
||||
(1152921504606846976, 15), // 16
|
||||
(2862423051509815793, 15), // 17
|
||||
(6746640616477458432, 15), // 18
|
||||
(15181127029874798299, 15), // 19
|
||||
(1638400000000000000, 14), // 20
|
||||
(3243919932521508681, 14), // 21
|
||||
(6221821273427820544, 14), // 22
|
||||
(11592836324538749809, 14), // 23
|
||||
(876488338465357824, 13), // 24
|
||||
(1490116119384765625, 13), // 25
|
||||
(2481152873203736576, 13), // 26
|
||||
(4052555153018976267, 13), // 27
|
||||
(6502111422497947648, 13), // 28
|
||||
(10260628712958602189, 13), // 29
|
||||
(15943230000000000000, 13), // 30
|
||||
(787662783788549761, 12), // 31
|
||||
(1152921504606846976, 12), // 32
|
||||
(1667889514952984961, 12), // 33
|
||||
(2386420683693101056, 12), // 34
|
||||
(3379220508056640625, 12), // 35
|
||||
(4738381338321616896, 12), // 36
|
||||
const BASES: [(u64, usize); 257] = [
|
||||
( 0, 0),
|
||||
( 0, 0),
|
||||
( 9223372036854775808, 63), // 2
|
||||
(12157665459056928801, 40), // 3
|
||||
( 4611686018427387904, 31), // 4
|
||||
( 7450580596923828125, 27), // 5
|
||||
( 4738381338321616896, 24), // 6
|
||||
( 3909821048582988049, 22), // 7
|
||||
( 9223372036854775808, 21), // 8
|
||||
(12157665459056928801, 20), // 9
|
||||
(10000000000000000000, 19), // 10
|
||||
( 5559917313492231481, 18), // 11
|
||||
( 2218611106740436992, 17), // 12
|
||||
( 8650415919381337933, 17), // 13
|
||||
( 2177953337809371136, 16), // 14
|
||||
( 6568408355712890625, 16), // 15
|
||||
( 1152921504606846976, 15), // 16
|
||||
( 2862423051509815793, 15), // 17
|
||||
( 6746640616477458432, 15), // 18
|
||||
(15181127029874798299, 15), // 19
|
||||
( 1638400000000000000, 14), // 20
|
||||
( 3243919932521508681, 14), // 21
|
||||
( 6221821273427820544, 14), // 22
|
||||
(11592836324538749809, 14), // 23
|
||||
( 876488338465357824, 13), // 24
|
||||
( 1490116119384765625, 13), // 25
|
||||
( 2481152873203736576, 13), // 26
|
||||
( 4052555153018976267, 13), // 27
|
||||
( 6502111422497947648, 13), // 28
|
||||
(10260628712958602189, 13), // 29
|
||||
(15943230000000000000, 13), // 30
|
||||
( 787662783788549761, 12), // 31
|
||||
( 1152921504606846976, 12), // 32
|
||||
( 1667889514952984961, 12), // 33
|
||||
( 2386420683693101056, 12), // 34
|
||||
( 3379220508056640625, 12), // 35
|
||||
( 4738381338321616896, 12), // 36
|
||||
( 6582952005840035281, 12), // 37
|
||||
( 9065737908494995456, 12), // 38
|
||||
(12381557655576425121, 12), // 39
|
||||
(16777216000000000000, 12), // 40
|
||||
( 550329031716248441, 11), // 41
|
||||
( 717368321110468608, 11), // 42
|
||||
( 929293739471222707, 11), // 43
|
||||
( 1196683881290399744, 11), // 44
|
||||
( 1532278301220703125, 11), // 45
|
||||
( 1951354384207722496, 11), // 46
|
||||
( 2472159215084012303, 11), // 47
|
||||
( 3116402981210161152, 11), // 48
|
||||
( 3909821048582988049, 11), // 49
|
||||
( 4882812500000000000, 11), // 50
|
||||
( 6071163615208263051, 11), // 51
|
||||
( 7516865509350965248, 11), // 52
|
||||
( 9269035929372191597, 11), // 53
|
||||
(11384956040305711104, 11), // 54
|
||||
(13931233916552734375, 11), // 55
|
||||
(16985107389382393856, 11), // 56
|
||||
( 362033331456891249, 10), // 57
|
||||
( 430804206899405824, 10), // 58
|
||||
( 511116753300641401, 10), // 59
|
||||
( 604661760000000000, 10), // 60
|
||||
( 713342911662882601, 10), // 61
|
||||
( 839299365868340224, 10), // 62
|
||||
( 984930291881790849, 10), // 63
|
||||
( 1152921504606846976, 10), // 64
|
||||
( 1346274334462890625, 10), // 65
|
||||
( 1568336880910795776, 10), // 66
|
||||
( 1822837804551761449, 10), // 67
|
||||
( 2113922820157210624, 10), // 68
|
||||
( 2446194060654759801, 10), // 69
|
||||
( 2824752490000000000, 10), // 70
|
||||
( 3255243551009881201, 10), // 71
|
||||
( 3743906242624487424, 10), // 72
|
||||
( 4297625829703557649, 10), // 73
|
||||
( 4923990397355877376, 10), // 74
|
||||
( 5631351470947265625, 10), // 75
|
||||
( 6428888932339941376, 10), // 76
|
||||
( 7326680472586200649, 10), // 77
|
||||
( 8335775831236199424, 10), // 78
|
||||
( 9468276082626847201, 10), // 79
|
||||
(10737418240000000000, 10), // 80
|
||||
(12157665459056928801, 10), // 81
|
||||
(13744803133596058624, 10), // 82
|
||||
(15516041187205853449, 10), // 83
|
||||
(17490122876598091776, 10), // 84
|
||||
( 231616946283203125, 9), // 85
|
||||
( 257327417311663616, 9), // 86
|
||||
( 285544154243029527, 9), // 87
|
||||
( 316478381828866048, 9), // 88
|
||||
( 350356403707485209, 9), // 89
|
||||
( 387420489000000000, 9), // 90
|
||||
( 427929800129788411, 9), // 91
|
||||
( 472161363286556672, 9), // 92
|
||||
( 520411082988487293, 9), // 93
|
||||
( 572994802228616704, 9), // 94
|
||||
( 630249409724609375, 9), // 95
|
||||
( 692533995824480256, 9), // 96
|
||||
( 760231058654565217, 9), // 97
|
||||
( 833747762130149888, 9), // 98
|
||||
( 913517247483640899, 9), // 99
|
||||
( 1000000000000000000, 9), // 100
|
||||
( 1093685272684360901, 9), // 101
|
||||
( 1195092568622310912, 9), // 102
|
||||
( 1304773183829244583, 9), // 103
|
||||
( 1423311812421484544, 9), // 104
|
||||
( 1551328215978515625, 9), // 105
|
||||
( 1689478959002692096, 9), // 106
|
||||
( 1838459212420154507, 9), // 107
|
||||
( 1999004627104432128, 9), // 108
|
||||
( 2171893279442309389, 9), // 109
|
||||
( 2357947691000000000, 9), // 110
|
||||
( 2558036924386500591, 9), // 111
|
||||
( 2773078757450186752, 9), // 112
|
||||
( 3004041937984268273, 9), // 113
|
||||
( 3251948521156637184, 9), // 114
|
||||
( 3517876291919921875, 9), // 115
|
||||
( 3802961274698203136, 9), // 116
|
||||
( 4108400332687853397, 9), // 117
|
||||
( 4435453859151328768, 9), // 118
|
||||
( 4785448563124474679, 9), // 119
|
||||
( 5159780352000000000, 9), // 120
|
||||
( 5559917313492231481, 9), // 121
|
||||
( 5987402799531080192, 9), // 122
|
||||
( 6443858614676334363, 9), // 123
|
||||
( 6930988311686938624, 9), // 124
|
||||
( 7450580596923828125, 9), // 125
|
||||
( 8004512848309157376, 9), // 126
|
||||
( 8594754748609397887, 9), // 127
|
||||
( 9223372036854775808, 9), // 128
|
||||
( 9892530380752880769, 9), // 129
|
||||
(10604499373000000000, 9), // 130
|
||||
(11361656654439817571, 9), // 131
|
||||
(12166492167065567232, 9), // 132
|
||||
(13021612539908538853, 9), // 133
|
||||
(13929745610903012864, 9), // 134
|
||||
(14893745087865234375, 9), // 135
|
||||
(15916595351771938816, 9), // 136
|
||||
(17001416405572203977, 9), // 137
|
||||
(18151468971815029248, 9), // 138
|
||||
( 139353667211683681, 8), // 139
|
||||
( 147578905600000000, 8), // 140
|
||||
( 156225851787813921, 8), // 141
|
||||
( 165312903998914816, 8), // 142
|
||||
( 174859124550883201, 8), // 143
|
||||
( 184884258895036416, 8), // 144
|
||||
( 195408755062890625, 8), // 145
|
||||
( 206453783524884736, 8), // 146
|
||||
( 218041257467152161, 8), // 147
|
||||
( 230193853492166656, 8), // 148
|
||||
( 242935032749128801, 8), // 149
|
||||
( 256289062500000000, 8), // 150
|
||||
( 270281038127131201, 8), // 151
|
||||
( 284936905588473856, 8), // 152
|
||||
( 300283484326400961, 8), // 153
|
||||
( 316348490636206336, 8), // 154
|
||||
( 333160561500390625, 8), // 155
|
||||
( 350749278894882816, 8), // 156
|
||||
( 369145194573386401, 8), // 157
|
||||
( 388379855336079616, 8), // 158
|
||||
( 408485828788939521, 8), // 159
|
||||
( 429496729600000000, 8), // 160
|
||||
( 451447246258894081, 8), // 161
|
||||
( 474373168346071296, 8), // 162
|
||||
( 498311414318121121, 8), // 163
|
||||
( 523300059815673856, 8), // 164
|
||||
( 549378366500390625, 8), // 165
|
||||
( 576586811427594496, 8), // 166
|
||||
( 604967116961135041, 8), // 167
|
||||
( 634562281237118976, 8), // 168
|
||||
( 665416609183179841, 8), // 169
|
||||
( 697575744100000000, 8), // 170
|
||||
( 731086699811838561, 8), // 171
|
||||
( 765997893392859136, 8), // 172
|
||||
( 802359178476091681, 8), // 173
|
||||
( 840221879151902976, 8), // 174
|
||||
( 879638824462890625, 8), // 175
|
||||
( 920664383502155776, 8), // 176
|
||||
( 963354501121950081, 8), // 177
|
||||
( 1007766734259732736, 8), // 178
|
||||
( 1053960288888713761, 8), // 179
|
||||
( 1101996057600000000, 8), // 180
|
||||
( 1151936657823500641, 8), // 181
|
||||
( 1203846470694789376, 8), // 182
|
||||
( 1257791680575160641, 8), // 183
|
||||
( 1313840315232157696, 8), // 184
|
||||
( 1372062286687890625, 8), // 185
|
||||
( 1432529432742502656, 8), // 186
|
||||
( 1495315559180183521, 8), // 187
|
||||
( 1560496482665168896, 8), // 188
|
||||
( 1628150074335205281, 8), // 189
|
||||
( 1698356304100000000, 8), // 190
|
||||
( 1771197285652216321, 8), // 191
|
||||
( 1846757322198614016, 8), // 192
|
||||
( 1925122952918976001, 8), // 193
|
||||
( 2006383000160502016, 8), // 194
|
||||
( 2090628617375390625, 8), // 195
|
||||
( 2177953337809371136, 8), // 196
|
||||
( 2268453123948987361, 8), // 197
|
||||
( 2362226417735475456, 8), // 198
|
||||
( 2459374191553118401, 8), // 199
|
||||
( 2560000000000000000, 8), // 200
|
||||
( 2664210032449121601, 8), // 201
|
||||
( 2772113166407885056, 8), // 202
|
||||
( 2883821021683985761, 8), // 203
|
||||
( 2999448015365799936, 8), // 204
|
||||
( 3119111417625390625, 8), // 205
|
||||
( 3242931408352297216, 8), // 206
|
||||
( 3371031134626313601, 8), // 207
|
||||
( 3503536769037500416, 8), // 208
|
||||
( 3640577568861717121, 8), // 209
|
||||
( 3782285936100000000, 8), // 210
|
||||
( 3928797478390152481, 8), // 211
|
||||
( 4080251070798954496, 8), // 212
|
||||
( 4236788918503437921, 8), // 213
|
||||
( 4398556620369715456, 8), // 214
|
||||
( 4565703233437890625, 8), // 215
|
||||
( 4738381338321616896, 8), // 216
|
||||
( 4916747105530914241, 8), // 217
|
||||
( 5100960362726891776, 8), // 218
|
||||
( 5291184662917065441, 8), // 219
|
||||
( 5487587353600000000, 8), // 220
|
||||
( 5690339646868044961, 8), // 221
|
||||
( 5899616690476974336, 8), // 222
|
||||
( 6115597639891380481, 8), // 223
|
||||
( 6338465731314712576, 8), // 224
|
||||
( 6568408355712890625, 8), // 225
|
||||
( 6805617133840466176, 8), // 226
|
||||
( 7050287992278341281, 8), // 227
|
||||
( 7302621240492097536, 8), // 228
|
||||
( 7562821648920027361, 8), // 229
|
||||
( 7831098528100000000, 8), // 230
|
||||
( 8107665808844335041, 8), // 231
|
||||
( 8392742123471896576, 8), // 232
|
||||
( 8686550888106661441, 8), // 233
|
||||
( 8989320386052055296, 8), // 234
|
||||
( 9301283852250390625, 8), // 235
|
||||
( 9622679558836781056, 8), // 236
|
||||
( 9953750901796946721, 8), // 237
|
||||
(10294746488738365696, 8), // 238
|
||||
(10645920227784266881, 8), // 239
|
||||
(11007531417600000000, 8), // 240
|
||||
(11379844838561358721, 8), // 241
|
||||
(11763130845074473216, 8), // 242
|
||||
(12157665459056928801, 8), // 243
|
||||
(12563730464589807616, 8), // 244
|
||||
(12981613503750390625, 8), // 245
|
||||
(13411608173635297536, 8), // 246
|
||||
(13854014124583882561, 8), // 247
|
||||
(14309137159611744256, 8), // 248
|
||||
(14777289335064248001, 8), // 249
|
||||
(15258789062500000000, 8), // 250
|
||||
(15753961211814252001, 8), // 251
|
||||
(16263137215612256256, 8), // 252
|
||||
(16786655174842630561, 8), // 253
|
||||
(17324859965700833536, 8), // 254
|
||||
(17878103347812890625, 8), // 255
|
||||
( 72057594037927936, 7), // 256
|
||||
];
|
||||
|
||||
let (base, power) = BASES[radix as usize];
|
||||
|
|
|
@ -1020,6 +1020,278 @@ fn test_to_str_radix() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_radix() {
|
||||
const GROUND_TRUTH : &[(&[u8], u32, &[u8])] = &[
|
||||
(b"0", 42, &[0]),
|
||||
(b"ffffeeffbb", 2, &[1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
|
||||
(b"ffffeeffbb", 3, &[2, 2, 1, 1, 2, 1, 1, 2, 0, 0, 0, 0, 0, 1, 2,
|
||||
0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 1]),
|
||||
(b"ffffeeffbb", 4, &[3, 2, 3, 2, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3]),
|
||||
(b"ffffeeffbb", 5, &[0, 4, 3, 3, 1, 4, 2, 4, 1, 4, 4, 2, 3, 0, 0,
|
||||
1, 2, 1]),
|
||||
(b"ffffeeffbb", 6, &[5, 5, 4, 5, 5, 0, 0, 1, 2, 5, 3, 0, 1, 0, 2, 2]),
|
||||
(b"ffffeeffbb", 7, &[4, 2, 3, 6, 0, 1, 6, 1, 6, 2, 0, 3, 2, 4, 1]),
|
||||
(b"ffffeeffbb", 8, &[3, 7, 6, 7, 7, 5, 3, 7, 7, 7, 7, 7, 7, 1]),
|
||||
(b"ffffeeffbb", 9, &[8, 4, 5, 7, 0, 0, 3, 2, 0, 3, 0, 8, 3]),
|
||||
(b"ffffeeffbb", 10, &[5, 9, 5, 3, 1, 5, 0, 1, 5, 9, 9, 0, 1]),
|
||||
(b"ffffeeffbb", 11, &[10, 7, 6, 5, 2, 0, 3, 3, 3, 4, 9, 3]),
|
||||
(b"ffffeeffbb", 12, &[11, 8, 5, 10, 1, 10, 3, 1, 1, 9, 5, 1]),
|
||||
(b"ffffeeffbb", 13, &[0, 5, 7, 4, 6, 5, 6, 11, 8, 12, 7]),
|
||||
(b"ffffeeffbb", 14, &[11, 4, 4, 11, 8, 4, 6, 0, 3, 11, 3]),
|
||||
(b"ffffeeffbb", 15, &[5, 11, 13, 2, 1, 10, 2, 0, 9, 13, 1]),
|
||||
(b"ffffeeffbb", 16, &[11, 11, 15, 15, 14, 14, 15, 15, 15, 15]),
|
||||
(b"ffffeeffbb", 17, &[0, 2, 14, 12, 2, 14, 8, 10, 4, 9]),
|
||||
(b"ffffeeffbb", 18, &[17, 15, 5, 13, 10, 16, 16, 13, 9, 5]),
|
||||
(b"ffffeeffbb", 19, &[14, 13, 2, 8, 9, 0, 1, 14, 7, 3]),
|
||||
(b"ffffeeffbb", 20, &[15, 19, 3, 14, 0, 17, 19, 18, 2, 2]),
|
||||
(b"ffffeeffbb", 21, &[11, 5, 4, 13, 5, 18, 9, 1, 8, 1]),
|
||||
(b"ffffeeffbb", 22, &[21, 3, 7, 21, 15, 12, 17, 0, 20]),
|
||||
(b"ffffeeffbb", 23, &[21, 21, 6, 9, 10, 7, 21, 0, 14]),
|
||||
(b"ffffeeffbb", 24, &[11, 10, 19, 14, 22, 11, 17, 23, 9]),
|
||||
(b"ffffeeffbb", 25, &[20, 18, 21, 22, 21, 14, 3, 5, 7]),
|
||||
(b"ffffeeffbb", 26, &[13, 15, 24, 11, 17, 6, 23, 6, 5]),
|
||||
(b"ffffeeffbb", 27, &[17, 16, 7, 0, 21, 0, 3, 24, 3]),
|
||||
(b"ffffeeffbb", 28, &[11, 16, 11, 15, 14, 18, 13, 25, 2]),
|
||||
(b"ffffeeffbb", 29, &[6, 8, 7, 19, 14, 13, 21, 5, 2]),
|
||||
(b"ffffeeffbb", 30, &[5, 13, 18, 11, 10, 7, 8, 20, 1]),
|
||||
(b"ffffeeffbb", 31, &[22, 26, 15, 19, 8, 27, 29, 8, 1]),
|
||||
(b"ffffeeffbb", 32, &[27, 29, 31, 29, 30, 31, 31, 31]),
|
||||
(b"ffffeeffbb", 33, &[32, 20, 27, 12, 1, 12, 26, 25]),
|
||||
(b"ffffeeffbb", 34, &[17, 9, 16, 33, 13, 25, 31, 20]),
|
||||
(b"ffffeeffbb", 35, &[25, 32, 2, 25, 11, 4, 3, 17]),
|
||||
(b"ffffeeffbb", 36, &[35, 34, 5, 6, 32, 3, 1, 14]),
|
||||
(b"ffffeeffbb", 37, &[16, 21, 18, 4, 33, 19, 21, 11]),
|
||||
(b"ffffeeffbb", 38, &[33, 25, 19, 29, 20, 6, 23, 9]),
|
||||
(b"ffffeeffbb", 39, &[26, 27, 29, 23, 16, 18, 0, 8]),
|
||||
(b"ffffeeffbb", 40, &[35, 39, 30, 11, 16, 17, 28, 6]),
|
||||
(b"ffffeeffbb", 41, &[36, 30, 9, 18, 12, 19, 26, 5]),
|
||||
(b"ffffeeffbb", 42, &[11, 34, 37, 27, 1, 13, 32, 4]),
|
||||
(b"ffffeeffbb", 43, &[3, 24, 11, 2, 10, 40, 1, 4]),
|
||||
(b"ffffeeffbb", 44, &[43, 12, 40, 32, 3, 23, 19, 3]),
|
||||
(b"ffffeeffbb", 45, &[35, 38, 44, 18, 22, 18, 42, 2]),
|
||||
(b"ffffeeffbb", 46, &[21, 45, 18, 41, 17, 2, 24, 2]),
|
||||
(b"ffffeeffbb", 47, &[37, 37, 11, 12, 6, 0, 8, 2]),
|
||||
(b"ffffeeffbb", 48, &[11, 41, 40, 43, 5, 43, 41, 1]),
|
||||
(b"ffffeeffbb", 49, &[18, 45, 7, 13, 20, 21, 30, 1]),
|
||||
(b"ffffeeffbb", 50, &[45, 21, 5, 34, 21, 18, 20, 1]),
|
||||
(b"ffffeeffbb", 51, &[17, 6, 26, 22, 38, 24, 11, 1]),
|
||||
(b"ffffeeffbb", 52, &[39, 33, 38, 30, 46, 31, 3, 1]),
|
||||
(b"ffffeeffbb", 53, &[31, 7, 44, 23, 9, 32, 49]),
|
||||
(b"ffffeeffbb", 54, &[17, 35, 8, 37, 31, 18, 44]),
|
||||
(b"ffffeeffbb", 55, &[10, 52, 9, 48, 36, 39, 39]),
|
||||
(b"ffffeeffbb", 56, &[11, 50, 51, 22, 25, 36, 35]),
|
||||
(b"ffffeeffbb", 57, &[14, 55, 12, 43, 20, 3, 32]),
|
||||
(b"ffffeeffbb", 58, &[35, 18, 45, 56, 9, 51, 28]),
|
||||
(b"ffffeeffbb", 59, &[51, 28, 20, 26, 55, 3, 26]),
|
||||
(b"ffffeeffbb", 60, &[35, 6, 27, 46, 58, 33, 23]),
|
||||
(b"ffffeeffbb", 61, &[58, 7, 6, 54, 49, 20, 21]),
|
||||
(b"ffffeeffbb", 62, &[53, 59, 3, 14, 10, 22, 19]),
|
||||
(b"ffffeeffbb", 63, &[53, 50, 23, 4, 56, 36, 17]),
|
||||
(b"ffffeeffbb", 64, &[59, 62, 47, 59, 63, 63, 15]),
|
||||
(b"ffffeeffbb", 65, &[0, 53, 39, 4, 40, 37, 14]),
|
||||
(b"ffffeeffbb", 66, &[65, 59, 39, 1, 64, 19, 13]),
|
||||
(b"ffffeeffbb", 67, &[35, 14, 19, 16, 25, 10, 12]),
|
||||
(b"ffffeeffbb", 68, &[51, 38, 63, 50, 15, 8, 11]),
|
||||
(b"ffffeeffbb", 69, &[44, 45, 18, 58, 68, 12, 10]),
|
||||
(b"ffffeeffbb", 70, &[25, 51, 0, 60, 13, 24, 9]),
|
||||
(b"ffffeeffbb", 71, &[54, 30, 9, 65, 28, 41, 8]),
|
||||
(b"ffffeeffbb", 72, &[35, 35, 55, 54, 17, 64, 7]),
|
||||
(b"ffffeeffbb", 73, &[34, 4, 48, 40, 27, 19, 7]),
|
||||
(b"ffffeeffbb", 74, &[53, 47, 4, 56, 36, 51, 6]),
|
||||
(b"ffffeeffbb", 75, &[20, 56, 10, 72, 24, 13, 6]),
|
||||
(b"ffffeeffbb", 76, &[71, 31, 52, 60, 48, 53, 5]),
|
||||
(b"ffffeeffbb", 77, &[32, 73, 14, 63, 15, 21, 5]),
|
||||
(b"ffffeeffbb", 78, &[65, 13, 17, 32, 64, 68, 4]),
|
||||
(b"ffffeeffbb", 79, &[37, 56, 2, 56, 25, 41, 4]),
|
||||
(b"ffffeeffbb", 80, &[75, 59, 37, 41, 43, 15, 4]),
|
||||
(b"ffffeeffbb", 81, &[44, 68, 0, 21, 27, 72, 3]),
|
||||
(b"ffffeeffbb", 82, &[77, 35, 2, 74, 46, 50, 3]),
|
||||
(b"ffffeeffbb", 83, &[52, 51, 19, 76, 10, 30, 3]),
|
||||
(b"ffffeeffbb", 84, &[11, 80, 19, 19, 76, 10, 3]),
|
||||
(b"ffffeeffbb", 85, &[0, 82, 20, 14, 68, 77, 2]),
|
||||
(b"ffffeeffbb", 86, &[3, 12, 78, 37, 62, 61, 2]),
|
||||
(b"ffffeeffbb", 87, &[35, 12, 20, 8, 52, 46, 2]),
|
||||
(b"ffffeeffbb", 88, &[43, 6, 54, 42, 30, 32, 2]),
|
||||
(b"ffffeeffbb", 89, &[49, 52, 85, 21, 80, 18, 2]),
|
||||
(b"ffffeeffbb", 90, &[35, 64, 78, 24, 18, 6, 2]),
|
||||
(b"ffffeeffbb", 91, &[39, 17, 83, 63, 17, 85, 1]),
|
||||
(b"ffffeeffbb", 92, &[67, 22, 85, 79, 75, 74, 1]),
|
||||
(b"ffffeeffbb", 93, &[53, 60, 39, 29, 4, 65, 1]),
|
||||
(b"ffffeeffbb", 94, &[37, 89, 2, 72, 76, 55, 1]),
|
||||
(b"ffffeeffbb", 95, &[90, 74, 89, 9, 9, 47, 1]),
|
||||
(b"ffffeeffbb", 96, &[59, 20, 46, 35, 81, 38, 1]),
|
||||
(b"ffffeeffbb", 97, &[94, 87, 60, 71, 3, 31, 1]),
|
||||
(b"ffffeeffbb", 98, &[67, 22, 63, 50, 62, 23, 1]),
|
||||
(b"ffffeeffbb", 99, &[98, 6, 69, 12, 61, 16, 1]),
|
||||
(b"ffffeeffbb", 100, &[95, 35, 51, 10, 95, 9, 1]),
|
||||
(b"ffffeeffbb", 101, &[87, 27, 7, 8, 62, 3, 1]),
|
||||
(b"ffffeeffbb", 102, &[17, 3, 32, 79, 59, 99]),
|
||||
(b"ffffeeffbb", 103, &[30, 22, 90, 0, 87, 94]),
|
||||
(b"ffffeeffbb", 104, &[91, 68, 87, 68, 38, 90]),
|
||||
(b"ffffeeffbb", 105, &[95, 80, 54, 73, 15, 86]),
|
||||
(b"ffffeeffbb", 106, &[31, 30, 24, 16, 17, 82]),
|
||||
(b"ffffeeffbb", 107, &[51, 50, 10, 12, 42, 78]),
|
||||
(b"ffffeeffbb", 108, &[71, 71, 96, 78, 89, 74]),
|
||||
(b"ffffeeffbb", 109, &[33, 18, 93, 22, 50, 71]),
|
||||
(b"ffffeeffbb", 110, &[65, 53, 57, 88, 29, 68]),
|
||||
(b"ffffeeffbb", 111, &[53, 93, 67, 90, 27, 65]),
|
||||
(b"ffffeeffbb", 112, &[11, 109, 96, 65, 43, 62]),
|
||||
(b"ffffeeffbb", 113, &[27, 23, 106, 56, 76, 59]),
|
||||
(b"ffffeeffbb", 114, &[71, 84, 31, 112, 11, 57]),
|
||||
(b"ffffeeffbb", 115, &[90, 22, 1, 56, 76, 54]),
|
||||
(b"ffffeeffbb", 116, &[35, 38, 98, 57, 40, 52]),
|
||||
(b"ffffeeffbb", 117, &[26, 113, 115, 62, 17, 50]),
|
||||
(b"ffffeeffbb", 118, &[51, 14, 5, 18, 7, 48]),
|
||||
(b"ffffeeffbb", 119, &[102, 31, 110, 108, 8, 46]),
|
||||
(b"ffffeeffbb", 120, &[35, 93, 96, 50, 22, 44]),
|
||||
(b"ffffeeffbb", 121, &[87, 61, 2, 36, 47, 42]),
|
||||
(b"ffffeeffbb", 122, &[119, 64, 1, 22, 83, 40]),
|
||||
(b"ffffeeffbb", 123, &[77, 119, 32, 90, 6, 39]),
|
||||
(b"ffffeeffbb", 124, &[115, 122, 31, 79, 62, 37]),
|
||||
(b"ffffeeffbb", 125, &[95, 108, 47, 74, 3, 36]),
|
||||
(b"ffffeeffbb", 126, &[53, 25, 116, 39, 78, 34]),
|
||||
(b"ffffeeffbb", 127, &[22, 23, 125, 67, 35, 33]),
|
||||
(b"ffffeeffbb", 128, &[59, 127, 59, 127, 127, 31]),
|
||||
(b"ffffeeffbb", 129, &[89, 36, 1, 59, 100, 30]),
|
||||
(b"ffffeeffbb", 130, &[65, 91, 123, 89, 79, 29]),
|
||||
(b"ffffeeffbb", 131, &[58, 72, 39, 63, 65, 28]),
|
||||
(b"ffffeeffbb", 132, &[131, 62, 92, 82, 57, 27]),
|
||||
(b"ffffeeffbb", 133, &[109, 31, 51, 123, 55, 26]),
|
||||
(b"ffffeeffbb", 134, &[35, 74, 21, 27, 60, 25]),
|
||||
(b"ffffeeffbb", 135, &[125, 132, 49, 37, 70, 24]),
|
||||
(b"ffffeeffbb", 136, &[51, 121, 117, 133, 85, 23]),
|
||||
(b"ffffeeffbb", 137, &[113, 60, 135, 22, 107, 22]),
|
||||
(b"ffffeeffbb", 138, &[113, 91, 73, 93, 133, 21]),
|
||||
(b"ffffeeffbb", 139, &[114, 75, 102, 51, 26, 21]),
|
||||
(b"ffffeeffbb", 140, &[95, 25, 35, 16, 62, 20]),
|
||||
(b"ffffeeffbb", 141, &[131, 137, 16, 110, 102, 19]),
|
||||
(b"ffffeeffbb", 142, &[125, 121, 108, 34, 6, 19]),
|
||||
(b"ffffeeffbb", 143, &[65, 78, 138, 55, 55, 18]),
|
||||
(b"ffffeeffbb", 144, &[107, 125, 121, 15, 109, 17]),
|
||||
(b"ffffeeffbb", 145, &[35, 13, 122, 42, 22, 17]),
|
||||
(b"ffffeeffbb", 146, &[107, 38, 103, 123, 83, 16]),
|
||||
(b"ffffeeffbb", 147, &[116, 96, 71, 98, 2, 16]),
|
||||
(b"ffffeeffbb", 148, &[127, 23, 75, 99, 71, 15]),
|
||||
(b"ffffeeffbb", 149, &[136, 110, 53, 114, 144, 14]),
|
||||
(b"ffffeeffbb", 150, &[95, 140, 133, 130, 71, 14]),
|
||||
(b"ffffeeffbb", 151, &[15, 50, 29, 137, 0, 14]),
|
||||
(b"ffffeeffbb", 152, &[147, 15, 89, 121, 83, 13]),
|
||||
(b"ffffeeffbb", 153, &[17, 87, 93, 72, 17, 13]),
|
||||
(b"ffffeeffbb", 154, &[109, 113, 3, 133, 106, 12]),
|
||||
(b"ffffeeffbb", 155, &[115, 141, 120, 139, 44, 12]),
|
||||
(b"ffffeeffbb", 156, &[143, 45, 4, 82, 140, 11]),
|
||||
(b"ffffeeffbb", 157, &[149, 92, 15, 106, 82, 11]),
|
||||
(b"ffffeeffbb", 158, &[37, 107, 79, 46, 26, 11]),
|
||||
(b"ffffeeffbb", 159, &[137, 37, 146, 51, 130, 10]),
|
||||
(b"ffffeeffbb", 160, &[155, 69, 29, 115, 77, 10]),
|
||||
(b"ffffeeffbb", 161, &[67, 98, 46, 68, 26, 10]),
|
||||
(b"ffffeeffbb", 162, &[125, 155, 60, 63, 138, 9]),
|
||||
(b"ffffeeffbb", 163, &[96, 43, 118, 93, 90, 9]),
|
||||
(b"ffffeeffbb", 164, &[159, 99, 123, 152, 43, 9]),
|
||||
(b"ffffeeffbb", 165, &[65, 17, 1, 69, 163, 8]),
|
||||
(b"ffffeeffbb", 166, &[135, 108, 25, 165, 119, 8]),
|
||||
(b"ffffeeffbb", 167, &[165, 116, 164, 103, 77, 8]),
|
||||
(b"ffffeeffbb", 168, &[11, 166, 67, 44, 36, 8]),
|
||||
(b"ffffeeffbb", 169, &[65, 59, 71, 149, 164, 7]),
|
||||
(b"ffffeeffbb", 170, &[85, 83, 26, 76, 126, 7]),
|
||||
(b"ffffeeffbb", 171, &[71, 132, 140, 157, 88, 7]),
|
||||
(b"ffffeeffbb", 172, &[3, 6, 127, 47, 52, 7]),
|
||||
(b"ffffeeffbb", 173, &[122, 66, 53, 83, 16, 7]),
|
||||
(b"ffffeeffbb", 174, &[35, 6, 5, 88, 155, 6]),
|
||||
(b"ffffeeffbb", 175, &[95, 20, 84, 56, 122, 6]),
|
||||
(b"ffffeeffbb", 176, &[43, 91, 57, 159, 89, 6]),
|
||||
(b"ffffeeffbb", 177, &[110, 127, 54, 40, 58, 6]),
|
||||
(b"ffffeeffbb", 178, &[49, 115, 43, 47, 27, 6]),
|
||||
(b"ffffeeffbb", 179, &[130, 91, 4, 178, 175, 5]),
|
||||
(b"ffffeeffbb", 180, &[35, 122, 109, 70, 147, 5]),
|
||||
(b"ffffeeffbb", 181, &[94, 94, 4, 79, 119, 5]),
|
||||
(b"ffffeeffbb", 182, &[39, 54, 66, 19, 92, 5]),
|
||||
(b"ffffeeffbb", 183, &[119, 2, 143, 69, 65, 5]),
|
||||
(b"ffffeeffbb", 184, &[67, 57, 90, 44, 39, 5]),
|
||||
(b"ffffeeffbb", 185, &[90, 63, 141, 123, 13, 5]),
|
||||
(b"ffffeeffbb", 186, &[53, 123, 172, 119, 174, 4]),
|
||||
(b"ffffeeffbb", 187, &[153, 21, 68, 28, 151, 4]),
|
||||
(b"ffffeeffbb", 188, &[131, 138, 94, 32, 128, 4]),
|
||||
(b"ffffeeffbb", 189, &[179, 121, 156, 130, 105, 4]),
|
||||
(b"ffffeeffbb", 190, &[185, 179, 164, 131, 83, 4]),
|
||||
(b"ffffeeffbb", 191, &[118, 123, 37, 31, 62, 4]),
|
||||
(b"ffffeeffbb", 192, &[59, 106, 83, 16, 41, 4]),
|
||||
(b"ffffeeffbb", 193, &[57, 37, 47, 86, 20, 4]),
|
||||
(b"ffffeeffbb", 194, &[191, 140, 63, 45, 0, 4]),
|
||||
(b"ffffeeffbb", 195, &[65, 169, 83, 84, 175, 3]),
|
||||
(b"ffffeeffbb", 196, &[67, 158, 64, 6, 157, 3]),
|
||||
(b"ffffeeffbb", 197, &[121, 26, 167, 3, 139, 3]),
|
||||
(b"ffffeeffbb", 198, &[197, 151, 165, 75, 121, 3]),
|
||||
(b"ffffeeffbb", 199, &[55, 175, 36, 22, 104, 3]),
|
||||
(b"ffffeeffbb", 200, &[195, 167, 162, 38, 87, 3]),
|
||||
(b"ffffeeffbb", 201, &[35, 27, 136, 124, 70, 3]),
|
||||
(b"ffffeeffbb", 202, &[87, 64, 153, 76, 54, 3]),
|
||||
(b"ffffeeffbb", 203, &[151, 191, 14, 94, 38, 3]),
|
||||
(b"ffffeeffbb", 204, &[119, 103, 135, 175, 22, 3]),
|
||||
(b"ffffeeffbb", 205, &[200, 79, 123, 115, 7, 3]),
|
||||
(b"ffffeeffbb", 206, &[133, 165, 202, 115, 198, 2]),
|
||||
(b"ffffeeffbb", 207, &[44, 153, 193, 175, 184, 2]),
|
||||
(b"ffffeeffbb", 208, &[91, 190, 125, 86, 171, 2]),
|
||||
(b"ffffeeffbb", 209, &[109, 151, 34, 53, 158, 2]),
|
||||
(b"ffffeeffbb", 210, &[95, 40, 171, 74, 145, 2]),
|
||||
(b"ffffeeffbb", 211, &[84, 195, 162, 150, 132, 2]),
|
||||
(b"ffffeeffbb", 212, &[31, 15, 59, 68, 120, 2]),
|
||||
(b"ffffeeffbb", 213, &[125, 57, 127, 36, 108, 2]),
|
||||
(b"ffffeeffbb", 214, &[51, 132, 2, 55, 96, 2]),
|
||||
(b"ffffeeffbb", 215, &[175, 133, 177, 122, 84, 2]),
|
||||
(b"ffffeeffbb", 216, &[179, 35, 78, 23, 73, 2]),
|
||||
(b"ffffeeffbb", 217, &[53, 101, 208, 186, 61, 2]),
|
||||
(b"ffffeeffbb", 218, &[33, 9, 214, 179, 50, 2]),
|
||||
(b"ffffeeffbb", 219, &[107, 147, 175, 217, 39, 2]),
|
||||
(b"ffffeeffbb", 220, &[175, 81, 179, 79, 29, 2]),
|
||||
(b"ffffeeffbb", 221, &[0, 76, 95, 204, 18, 2]),
|
||||
(b"ffffeeffbb", 222, &[53, 213, 16, 150, 8, 2]),
|
||||
(b"ffffeeffbb", 223, &[158, 161, 42, 136, 221, 1]),
|
||||
(b"ffffeeffbb", 224, &[123, 54, 52, 162, 212, 1]),
|
||||
(b"ffffeeffbb", 225, &[170, 43, 151, 2, 204, 1]),
|
||||
(b"ffffeeffbb", 226, &[27, 68, 224, 105, 195, 1]),
|
||||
(b"ffffeeffbb", 227, &[45, 69, 157, 20, 187, 1]),
|
||||
(b"ffffeeffbb", 228, &[71, 213, 64, 199, 178, 1]),
|
||||
(b"ffffeeffbb", 229, &[129, 203, 66, 186, 170, 1]),
|
||||
(b"ffffeeffbb", 230, &[205, 183, 57, 208, 162, 1]),
|
||||
(b"ffffeeffbb", 231, &[32, 50, 164, 33, 155, 1]),
|
||||
(b"ffffeeffbb", 232, &[35, 135, 53, 123, 147, 1]),
|
||||
(b"ffffeeffbb", 233, &[209, 47, 89, 13, 140, 1]),
|
||||
(b"ffffeeffbb", 234, &[143, 56, 175, 168, 132, 1]),
|
||||
(b"ffffeeffbb", 235, &[225, 157, 216, 121, 125, 1]),
|
||||
(b"ffffeeffbb", 236, &[51, 66, 119, 105, 118, 1]),
|
||||
(b"ffffeeffbb", 237, &[116, 150, 26, 119, 111, 1]),
|
||||
(b"ffffeeffbb", 238, &[221, 15, 87, 162, 104, 1]),
|
||||
(b"ffffeeffbb", 239, &[234, 155, 214, 234, 97, 1]),
|
||||
(b"ffffeeffbb", 240, &[155, 46, 84, 96, 91, 1]),
|
||||
(b"ffffeeffbb", 241, &[187, 48, 90, 225, 84, 1]),
|
||||
(b"ffffeeffbb", 242, &[87, 212, 151, 140, 78, 1]),
|
||||
(b"ffffeeffbb", 243, &[206, 22, 189, 81, 72, 1]),
|
||||
(b"ffffeeffbb", 244, &[119, 93, 122, 48, 66, 1]),
|
||||
(b"ffffeeffbb", 245, &[165, 224, 117, 40, 60, 1]),
|
||||
(b"ffffeeffbb", 246, &[77, 121, 100, 57, 54, 1]),
|
||||
(b"ffffeeffbb", 247, &[52, 128, 242, 98, 48, 1]),
|
||||
(b"ffffeeffbb", 248, &[115, 247, 224, 164, 42, 1]),
|
||||
(b"ffffeeffbb", 249, &[218, 127, 223, 5, 37, 1]),
|
||||
(b"ffffeeffbb", 250, &[95, 54, 168, 118, 31, 1]),
|
||||
(b"ffffeeffbb", 251, &[121, 204, 240, 3, 26, 1]),
|
||||
(b"ffffeeffbb", 252, &[179, 138, 123, 162, 20, 1]),
|
||||
(b"ffffeeffbb", 253, &[21, 50, 1, 91, 15, 1]),
|
||||
(b"ffffeeffbb", 254, &[149, 11, 63, 40, 10, 1]),
|
||||
(b"ffffeeffbb", 255, &[170, 225, 247, 9, 5, 1]),
|
||||
(b"ffffeeffbb", 256, &[187, 255, 238, 255, 255]),
|
||||
];
|
||||
|
||||
for &(bigint, radix, solution) in GROUND_TRUTH.iter() {
|
||||
let bigint = BigUint::parse_bytes(bigint, 16).unwrap();
|
||||
assert_eq!(bigint.to_radix(radix), solution);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str_radix() {
|
||||
let r = to_str_pairs();
|
||||
|
|
Loading…
Reference in New Issue