Skip to content

Commit 839ef32

Browse files
committed
Removed the conversion process of bc_num and BC_VECTOR from bc_square, and renamed to bc_square_vector.
1 parent ee3fa02 commit 839ef32

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

ext/bcmath/libbcmath/src/bcmath.h

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale);
147147
*(result) = mul_ex; \
148148
} while (0)
149149

150-
bc_num bc_square(bc_num n1, size_t scale);
151-
152150
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, size_t scale);
153151

154152
bool bc_modulo(bc_num num1, bc_num num2, bc_num *resul, size_t scale);

ext/bcmath/libbcmath/src/private.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static const BC_VECTOR BC_POW_10_LUT[9] = {
8282
bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign);
8383
bc_num _bc_do_add (bc_num n1, bc_num n2);
8484
bc_num _bc_do_sub (bc_num n1, bc_num n2);
85+
void bc_square_vector(BC_VECTOR *n1_vector, size_t n1_arr_size, BC_VECTOR *prod_vector, size_t prod_arr_size);
8586
void _bc_rm_leading_zeros (bc_num num);
8687

8788
#endif

ext/bcmath/libbcmath/src/recmul.c

+8-17
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,15 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale)
210210
return prod;
211211
}
212212

213-
bc_num bc_square(bc_num n1, size_t scale)
213+
void bc_square_vector(BC_VECTOR *n1_vector, size_t n1_arr_size, BC_VECTOR *prod_vector, size_t prod_arr_size)
214214
{
215-
bc_num prod;
216-
217-
size_t len1 = n1->n_len + n1->n_scale;
218-
size_t full_scale = n1->n_scale + n1->n_scale;
219-
size_t prod_scale = MIN(full_scale, MAX(scale, n1->n_scale));
220-
221-
if (len1 <= BC_VECTOR_SIZE) {
222-
bc_fast_square(n1, len1, &prod);
215+
if (n1_arr_size == 1) {
216+
prod_vector[0] = *n1_vector * *n1_vector;
217+
if (prod_arr_size == 2) {
218+
prod_vector[1] = prod_vector[0] / BC_VECTOR_BOUNDARY_NUM;
219+
prod_vector[0] %= BC_VECTOR_BOUNDARY_NUM;
220+
}
223221
} else {
224-
bc_standard_square(n1, len1, &prod);
222+
bc_standard_vector_mul(n1_vector, n1_arr_size, n1_vector, n1_arr_size, prod_vector, prod_arr_size);
225223
}
226-
227-
prod->n_sign = PLUS;
228-
prod->n_len -= full_scale;
229-
prod->n_scale = prod_scale;
230-
_bc_rm_leading_zeros(prod);
231-
232-
return prod;
233224
}

0 commit comments

Comments
 (0)