Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion ext/bcmath/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ if test "$PHP_BCMATH" != "no"; then
libbcmath/src/raise.c
libbcmath/src/raisemod.c
libbcmath/src/recmul.c
libbcmath/src/rmzero.c
libbcmath/src/round.c
libbcmath/src/sqrt.c
libbcmath/src/str2num.c
Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (PHP_BCMATH == "yes") {
ADD_SOURCES("ext/bcmath/libbcmath/src", "add.c div.c init.c neg.c \
raisemod.c sub.c compare.c divmod.c int2num.c long2num.c \
num2long.c recmul.c sqrt.c zero.c doaddsub.c \
floor_or_ceil.c nearzero.c num2str.c raise.c rmzero.c str2num.c \
floor_or_ceil.c nearzero.c num2str.c raise.c str2num.c \
round.c convert.c", "bcmath");

AC_DEFINE('HAVE_BCMATH', 1, "Define to 1 if the PHP extension 'bcmath' is available.");
Expand Down
18 changes: 17 additions & 1 deletion ext/bcmath/libbcmath/src/bcmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,23 @@ bool bc_is_near_zero(bc_num num, size_t scale);

bool bc_is_neg(bc_num num);

void bc_rm_trailing_zeros(bc_num num);
static inline void bc_rm_leading_zeros(bc_num num)
{
/* We can move n_value to point to the first non-zero digit! */
while (*num->n_value == 0 && num->n_len > 1) {
num->n_value++;
num->n_len--;
}
}

static inline void bc_rm_trailing_zeros(bc_num num)
{
char *end = num->n_value + num->n_len + num->n_scale - 1;
while (*end == 0 && num->n_scale > 0) {
num->n_scale--;
end--;
}
}

bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min);

Expand Down
2 changes: 1 addition & 1 deletion ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
quot, quot_size
);

_bc_rm_leading_zeros(*quot);
bc_rm_leading_zeros(*quot);
if (bc_is_zero(*quot)) {
(*quot)->n_sign = PLUS;
(*quot)->n_scale = 0;
Expand Down
4 changes: 2 additions & 2 deletions ext/bcmath/libbcmath/src/doaddsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bc_num _bc_do_add(bc_num n1, bc_num n2)
*sumptr = carry;

/* Adjust sum and return. */
_bc_rm_leading_zeros(sum);
bc_rm_leading_zeros(sum);
return sum;
}

Expand Down Expand Up @@ -291,6 +291,6 @@ bc_num _bc_do_sub(bc_num n1, bc_num n2)
}

/* Clean up and return. */
_bc_rm_leading_zeros(diff);
bc_rm_leading_zeros(diff);
return diff;
}
1 change: 0 additions & 1 deletion ext/bcmath/libbcmath/src/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ static const BC_VECTOR BC_POW_10_LUT[9] = {
bcmath_compare_result _bc_do_compare (bc_num n1, bc_num n2, size_t scale, bool use_sign);
bc_num _bc_do_add (bc_num n1, bc_num n2);
bc_num _bc_do_sub (bc_num n1, bc_num n2);
void _bc_rm_leading_zeros (bc_num num);

#endif
4 changes: 2 additions & 2 deletions ext/bcmath/libbcmath/src/recmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale)
prod->n_sign = (n1->n_sign == n2->n_sign ? PLUS : MINUS);
prod->n_len -= full_scale;
prod->n_scale = prod_scale;
_bc_rm_leading_zeros(prod);
bc_rm_leading_zeros(prod);
if (bc_is_zero(prod)) {
prod->n_sign = PLUS;
prod->n_scale = 0;
Expand All @@ -286,7 +286,7 @@ bc_num bc_square(bc_num n1, size_t scale)
prod->n_sign = PLUS;
prod->n_len -= full_scale;
prod->n_scale = prod_scale;
_bc_rm_leading_zeros(prod);
bc_rm_leading_zeros(prod);

return prod;
}
59 changes: 0 additions & 59 deletions ext/bcmath/libbcmath/src/rmzero.c

This file was deleted.

Loading