Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ext/bcmath/libbcmath/src/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,29 @@ static inline void bc_convert_to_vector_with_zero_pad(BC_VECTOR *n_vector, const
bc_convert_to_vector(n_vector, nend, nlen);
}

static inline void bc_convert_vector_to_char(BC_VECTOR *vector, char *nptr, char *nend, size_t arr_size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector could be const.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nielsdos
Indeed.
However, I discovered that in the final loop of the function, I was rewriting the vectors.
This is not good, so I copied the values ​​to another variable and made the vectors const.

cf98eb1

{
size_t i = 0;
while (i < arr_size - 1) {
#if BC_VECTOR_SIZE == 4
bc_write_bcd_representation(vector[i], nend - 3);
nend -= 4;
#else
bc_write_bcd_representation(vector[i] / 10000, nend - 7);
bc_write_bcd_representation(vector[i] % 10000, nend - 3);
nend -= 8;
#endif
i++;
}

/*
* The last digit may carry over.
* Also need to fill it to the end with zeros, so loop until the end of the string.
*/
while (nend >= nptr) {
*nend-- = vector[i] % BASE;
vector[i] /= BASE;
}
}

#endif
17 changes: 1 addition & 16 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,7 @@ static void bc_do_div(
char *qptr = (*quot)->n_value;
char *qend = qptr + (*quot)->n_len + (*quot)->n_scale - 1;

size_t i;
for (i = 0; i < quot_real_arr_size - 1; i++) {
#if BC_VECTOR_SIZE == 4
bc_write_bcd_representation(quot_vectors[i], qend - 3);
qend -= 4;
#else
bc_write_bcd_representation(quot_vectors[i] / 10000, qend - 7);
bc_write_bcd_representation(quot_vectors[i] % 10000, qend - 3);
qend -= 8;
#endif
}

while (qend >= qptr) {
*qend-- = quot_vectors[i] % BASE;
quot_vectors[i] /= BASE;
}
bc_convert_vector_to_char(quot_vectors, qptr, qend, quot_real_arr_size);

if (allocation_arr_size > BC_STACK_VECTOR_SIZE) {
efree(numerator_vectors);
Expand Down
21 changes: 1 addition & 20 deletions ext/bcmath/libbcmath/src/recmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,8 @@ static inline void bc_mul_finish_from_vector(BC_VECTOR *prod_vector, size_t prod
*prod = bc_new_num_nonzeroed(prodlen, 0);
char *pptr = (*prod)->n_value;
char *pend = pptr + prodlen - 1;
size_t i = 0;
while (i < prod_arr_size - 1) {
#if BC_VECTOR_SIZE == 4
bc_write_bcd_representation(prod_vector[i], pend - 3);
pend -= 4;
#else
bc_write_bcd_representation(prod_vector[i] / 10000, pend - 7);
bc_write_bcd_representation(prod_vector[i] % 10000, pend - 3);
pend -= 8;
#endif
i++;
}

/*
* The last digit may carry over.
* Also need to fill it to the end with zeros, so loop until the end of the string.
*/
while (pend >= pptr) {
*pend-- = prod_vector[i] % BASE;
prod_vector[i] /= BASE;
}
bc_convert_vector_to_char(prod_vector, pptr, pend, prod_arr_size);
}

/*
Expand Down