Skip to content

ext/bcmath: Performance improvement bcsqrt() #18771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Removed bc_add_ex, bc_int2num, and bc_raise_bc_exponent as they…
… are no longer used.
  • Loading branch information
SakiTakamachi committed Jun 12, 2025
commit 7555b2f35620530c68374fbfa448d8fd5027bd85
1 change: 0 additions & 1 deletion ext/bcmath/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if test "$PHP_BCMATH" != "no"; then
libbcmath/src/floor_or_ceil.c
libbcmath/src/long2num.c
libbcmath/src/init.c
libbcmath/src/int2num.c
libbcmath/src/neg.c
libbcmath/src/num2long.c
libbcmath/src/num2str.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 @@ -5,7 +5,7 @@ ARG_ENABLE("bcmath", "bc style precision math functions", "yes");
if (PHP_BCMATH == "yes") {
EXTENSION("bcmath", "bcmath.c", null, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
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 \
raisemod.c sub.c compare.c divmod.c long2num.c \
num2long.c recmul.c sqrt.c zero.c doaddsub.c \
floor_or_ceil.c num2str.c raise.c rmzero.c str2num.c \
round.c convert.c", "bcmath");
Expand Down
8 changes: 0 additions & 8 deletions ext/bcmath/libbcmath/src/bcmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ void bc_rm_trailing_zeros(bc_num num);

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

#define bc_add_ex(n1, n2, result, scale_min) do { \
bc_num add_ex = bc_add(n1, n2, scale_min); \
bc_free_num (result); \
*(result) = add_ex; \
} while (0)

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

#define bc_sub_ex(n1, n2, result, scale_min) do { \
Expand Down Expand Up @@ -176,8 +170,6 @@ raise_mod_status bc_raisemod(bc_num base, bc_num exponent, bc_num mod, bc_num *r

bc_raise_status bc_raise(bc_num base, long exponent, bc_num *result, size_t scale);

void bc_raise_bc_exponent(bc_num base, bc_num exponent, bc_num *resul, size_t scale);

bool bc_sqrt(bc_num *num, size_t scale);

/* Prototypes needed for external utility routines. */
Expand Down
74 changes: 0 additions & 74 deletions ext/bcmath/libbcmath/src/int2num.c

This file was deleted.

16 changes: 0 additions & 16 deletions ext/bcmath/libbcmath/src/raise.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,3 @@ bc_raise_status bc_raise(bc_num base, long exponent, bc_num *result, size_t scal
}
return BC_RAISE_STATUS_OK;
}

/* This is used internally by BCMath */
void bc_raise_bc_exponent(bc_num base, bc_num expo, bc_num *result, size_t scale) {
/* Exponent must not have fractional part */
assert(expo->n_scale == 0);

long exponent = bc_num2long(expo);
/* Exponent must be properly convertable to long */
if (exponent == 0 && (expo->n_len > 1 || expo->n_value[0] != 0)) {
assert(false && "Exponent is not well formed in internal call");
//assert(exponent != 0 || (expo->n_len == 0 && expo->n_value[0] == 0));
}
//assert(exponent != 0 || (expo->n_len == 0 && expo->n_value[0] == 0));
bc_raise(base, exponent, result, scale);
}