@@ -14,7 +14,7 @@ static int32_t s_floor_ilog2(int32_t value)
14
14
}
15
15
16
16
/* Exponentiation with small footprint */
17
- /*
17
+
18
18
static int32_t s_pow (int32_t base , int32_t exponent )
19
19
{
20
20
int32_t result = 1 ;
@@ -23,11 +23,14 @@ static int32_t s_pow(int32_t base, int32_t exponent)
23
23
result *= base ;
24
24
}
25
25
exponent /= 2 ;
26
+ if (exponent == 0 ) {
27
+ break ;
28
+ }
26
29
base *= base ;
27
30
}
28
31
return result ;
29
32
}
30
- */
33
+
31
34
static mp_err s_mp_to_radix_recursive (const mp_int * a , char * * str , size_t * part_maxlen , size_t * part_written ,
32
35
int radix , int32_t k , int32_t t , bool pad , mp_int * P , mp_int * R )
33
36
{
@@ -101,20 +104,13 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w
101
104
size_t part_written = 0 ;
102
105
size_t part_maxlen = maxlen ;
103
106
104
- mp_int N ;
105
-
106
107
/* List of reciprocals */
107
108
mp_int * R = NULL ;
108
109
/* List of moduli */
109
110
mp_int * P = NULL ;
110
111
111
112
/* Denominator for the reciprocal: b^y */
112
- /*n = s_pow((int32_t)radix, (int32_t)s_mp_radix_exponent_y[radix]);*/
113
- /* FIXME: either do it full in bigint or fix the problem with the sanitizer */
114
- if ((err = mp_init_i32 (& N ,(int32_t )radix )) != MP_OKAY ) goto LTM_ERR ;
115
- if ((err = mp_expt_n (& N , (int )s_mp_radix_exponent_y [radix ], & N )) != MP_OKAY ) goto LTM_ERR ;
116
- n = mp_get_i32 (& N );
117
- mp_clear (& N );
113
+ n = s_pow ((int32_t )radix , (int32_t )s_mp_radix_exponent_y [radix ]);
118
114
119
115
/* Numerator of the reciprocal: ceil(log_2(n)) */
120
116
k = s_floor_ilog2 (n ) + 1 ;
0 commit comments