mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-13 15:57:36 +02:00
Adding radix conversion for str2bignum
This commit is contained in:
parent
63b62751fc
commit
c2c637134f
1 changed files with 19 additions and 20 deletions
39
runtime.c
39
runtime.c
|
@ -2966,26 +2966,25 @@ object str_to_bignum(void *data, object bignum, char *str, char *str_end, int ra
|
||||||
*/
|
*/
|
||||||
radix_shift = nlz(radix) - 1;
|
radix_shift = nlz(radix) - 1;
|
||||||
if (((uint32_t)1 << radix_shift) == radix) { /* Power of two? */
|
if (((uint32_t)1 << radix_shift) == radix) { /* Power of two? */
|
||||||
// TODO:
|
int n = 0; /* Number of bits read so far into current big digit */
|
||||||
// int n = 0; /* Number of bits read so far into current big digit */
|
|
||||||
//
|
/* Read from least to most significant digit to avoid shifting or scaling */
|
||||||
// /* Read from least to most significant digit to avoid shifting or scaling */
|
while (str_end > str) {
|
||||||
// while (str_end > str) {
|
str_digit = hex_char_to_digit((int)*--str_end);
|
||||||
// str_digit = hex_char_to_digit((int)*--str_end);
|
|
||||||
//
|
big_digit |= (uint32_t)str_digit << n;
|
||||||
// big_digit |= (C_uword)str_digit << n;
|
n += radix_shift;
|
||||||
// n += radix_shift;
|
|
||||||
//
|
if (n >= C_BIGNUM_DIGIT_LENGTH) {
|
||||||
// if (n >= C_BIGNUM_DIGIT_LENGTH) {
|
n -= C_BIGNUM_DIGIT_LENGTH;
|
||||||
// n -= C_BIGNUM_DIGIT_LENGTH;
|
*digits++ = big_digit;
|
||||||
// *digits++ = big_digit;
|
big_digit = str_digit >> (radix_shift - n);
|
||||||
// big_digit = str_digit >> (radix_shift - n);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
assert(n < C_BIGNUM_DIGIT_LENGTH);
|
||||||
// assert(n < C_BIGNUM_DIGIT_LENGTH);
|
/* If radix isn't an exact divisor of digit length, write final digit */
|
||||||
// /* If radix isn't an exact divisor of digit length, write final digit */
|
if (n > 0) *digits++ = big_digit;
|
||||||
// if (n > 0) *digits++ = big_digit;
|
assert(digits == end_digits);
|
||||||
// assert(digits == end_digits);
|
|
||||||
} else { /* Not a power of two */
|
} else { /* Not a power of two */
|
||||||
uint32_t *last_digit = digits, factor; /* bignum starts as zero */
|
uint32_t *last_digit = digits, factor; /* bignum starts as zero */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue