19
19
* This algorithm uses Newton's approximation
20
20
* x[i+1] = x[i] - f(x[i])/f'(x[i])
21
21
* which will find the root in log(N) time where
22
- * each step involves a fair bit. This is not meant to
23
- * find huge roots [square and cube, etc].
22
+ * each step involves a fair bit.
24
23
*/
25
24
int mp_n_root_ex (const mp_int * a , mp_digit b , mp_int * c , int fast )
26
25
{
@@ -52,13 +51,13 @@ int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
52
51
/* Compute seed: 2^(log_2(n)/b + 2)*/
53
52
ilog2 = mp_count_bits (a );
54
53
55
- /*
56
- GCC and clang do not understand the sizeof tests and complain,
57
- icc (the Intel compiler) seems to understand, at least it doesn't complain.
58
- 2 of 3 say these macros are necessary, so there they are.
59
- */
54
+ /*
55
+ GCC and clang do not understand the sizeof tests and complain,
56
+ icc (the Intel compiler) seems to understand, at least it doesn't complain.
57
+ 2 of 3 say these macros are necessary, so there they are.
58
+ */
60
59
#if ( !(defined MP_8BIT ) && !(defined MP_16BIT ) )
61
- /*
60
+ /*
62
61
The type of mp_digit might be larger than an int.
63
62
If "b" is larger than INT_MAX it is also larger than
64
63
log_2(n) because the bit-length of the "n" is measured
@@ -89,7 +88,7 @@ int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
89
88
}
90
89
/* Start value must be larger than root */
91
90
ilog2 += 2 ;
92
- if (( res = mp_2expt (& t2 ,ilog2 )) != MP_OKAY ) {
91
+ if ((res = mp_2expt (& t2 ,ilog2 )) != MP_OKAY ) {
93
92
goto LBL_T3 ;
94
93
}
95
94
do {
@@ -129,7 +128,7 @@ int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
129
128
if ((res = mp_sub (& t1 , & t3 , & t2 )) != MP_OKAY ) {
130
129
goto LBL_T3 ;
131
130
}
132
- /*
131
+ /*
133
132
Number of rounds is at most log_2(root). If it is more it
134
133
got stuck, so break out of the loop and do the rest manually.
135
134
*/
@@ -139,7 +138,7 @@ int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
139
138
} while (mp_cmp (& t1 , & t2 ) != MP_EQ );
140
139
141
140
/* result can be off by a few so check */
142
- /* Overshoot by one if root is smaller */
141
+ /* Loop beneath can overshoot by one if found root is smaller than actual root */
143
142
for (;;) {
144
143
if ((res = mp_expt_d_ex (& t1 , b , & t2 , fast )) != MP_OKAY ) {
145
144
goto LBL_T3 ;
0 commit comments