Skip to content

Commit c1568f1

Browse files
committed
Removed the conversion process of bc_num and BC_VECTOR from bc_square, and renamed to bc_square_vector.
1 parent 186214b commit c1568f1

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
@@ -84,6 +84,7 @@ static const BC_VECTOR BC_POW_10_LUT[9] = {
8484
bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign);
8585
bc_num _bc_do_add (bc_num n1, bc_num n2);
8686
bc_num _bc_do_sub (bc_num n1, bc_num n2);
87+
void bc_square_vector(BC_VECTOR *n1_vector, size_t n1_arr_size, BC_VECTOR *prod_vector, size_t prod_arr_size);
8788
void _bc_rm_leading_zeros (bc_num num);
8889

8990
#endif

ext/bcmath/libbcmath/src/recmul.c

+8-17
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,15 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale)
186186
return prod;
187187
}
188188

189-
bc_num bc_square(bc_num n1, size_t scale)
189+
void bc_square_vector(BC_VECTOR *n1_vector, size_t n1_arr_size, BC_VECTOR *prod_vector, size_t prod_arr_size)
190190
{
191-
bc_num prod;
192-
193-
size_t len1 = n1->n_len + n1->n_scale;
194-
size_t full_scale = n1->n_scale + n1->n_scale;
195-
size_t prod_scale = MIN(full_scale, MAX(scale, n1->n_scale));
196-
197-
if (len1 <= BC_VECTOR_SIZE) {
198-
bc_fast_square(n1, len1, &prod);
191+
if (n1_arr_size == 1) {
192+
prod_vector[0] = *n1_vector * *n1_vector;
193+
if (prod_arr_size == 2) {
194+
prod_vector[1] = prod_vector[0] / BC_VECTOR_BOUNDARY_NUM;
195+
prod_vector[0] %= BC_VECTOR_BOUNDARY_NUM;
196+
}
199197
} else {
200-
bc_standard_square(n1, len1, &prod);
198+
bc_standard_vector_mul(n1_vector, n1_arr_size, n1_vector, n1_arr_size, prod_vector, prod_arr_size);
201199
}
202-
203-
prod->n_sign = PLUS;
204-
prod->n_len -= full_scale;
205-
prod->n_scale = prod_scale;
206-
_bc_rm_leading_zeros(prod);
207-
208-
return prod;
209200
}

0 commit comments

Comments
 (0)