Skip to content

ext/bcmath: optimized divmod() and mod() take 2 #18058

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 13 commits into
base: master
Choose a base branch
from
Open
Next Next commit
Added bc_divide_copy_numerator()
  • Loading branch information
SakiTakamachi committed May 23, 2025
commit 03955d6b9b786fccf1d7e9df5bac066bd7a856db
12 changes: 8 additions & 4 deletions ext/bcmath/libbcmath/src/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,16 @@ static void bc_do_div(
}
}

static inline void bc_divide_copy_numerator(bc_num numerator, bc_num *num, size_t scale)
{
scale = MIN(numerator->n_scale, scale);
*num = bc_new_num_nonzeroed(numerator->n_len, scale);
memcpy((*num)->n_value, numerator->n_value, numerator->n_len + scale);
}

static inline void bc_divide_by_one(bc_num numerator, bc_num *quot, size_t quot_scale)
{
quot_scale = MIN(numerator->n_scale, quot_scale);
*quot = bc_new_num_nonzeroed(numerator->n_len, quot_scale);
char *qptr = (*quot)->n_value;
memcpy(qptr, numerator->n_value, numerator->n_len + quot_scale);
bc_divide_copy_numerator(numerator, quot, quot_scale);
}

static inline void bc_divide_by_pow_10(
Expand Down