diff --git a/ext/bcmath/config.m4 b/ext/bcmath/config.m4 index a29f2af75ca8e..9e7d97b289fc9 100644 --- a/ext/bcmath/config.m4 +++ b/ext/bcmath/config.m4 @@ -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 diff --git a/ext/bcmath/config.w32 b/ext/bcmath/config.w32 index 74d1b38802eea..d423b1b48cf19 100644 --- a/ext/bcmath/config.w32 +++ b/ext/bcmath/config.w32 @@ -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."); diff --git a/ext/bcmath/libbcmath/src/bcmath.h b/ext/bcmath/libbcmath/src/bcmath.h index 1f05ad51f7f26..18b29aff5867e 100644 --- a/ext/bcmath/libbcmath/src/bcmath.h +++ b/ext/bcmath/libbcmath/src/bcmath.h @@ -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); diff --git a/ext/bcmath/libbcmath/src/div.c b/ext/bcmath/libbcmath/src/div.c index ec7619fb77090..dcbd8ad325c42 100644 --- a/ext/bcmath/libbcmath/src/div.c +++ b/ext/bcmath/libbcmath/src/div.c @@ -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; diff --git a/ext/bcmath/libbcmath/src/doaddsub.c b/ext/bcmath/libbcmath/src/doaddsub.c index feb50120c70c3..070d0309dea0f 100644 --- a/ext/bcmath/libbcmath/src/doaddsub.c +++ b/ext/bcmath/libbcmath/src/doaddsub.c @@ -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; } @@ -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; } diff --git a/ext/bcmath/libbcmath/src/private.h b/ext/bcmath/libbcmath/src/private.h index 1a911442dc9a1..05999fe19b136 100644 --- a/ext/bcmath/libbcmath/src/private.h +++ b/ext/bcmath/libbcmath/src/private.h @@ -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 diff --git a/ext/bcmath/libbcmath/src/recmul.c b/ext/bcmath/libbcmath/src/recmul.c index de06a4ca037ec..0fabea1b795d3 100644 --- a/ext/bcmath/libbcmath/src/recmul.c +++ b/ext/bcmath/libbcmath/src/recmul.c @@ -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; @@ -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; } diff --git a/ext/bcmath/libbcmath/src/rmzero.c b/ext/bcmath/libbcmath/src/rmzero.c deleted file mode 100644 index 9440785d80653..0000000000000 --- a/ext/bcmath/libbcmath/src/rmzero.c +++ /dev/null @@ -1,59 +0,0 @@ -/* rmzero.c: bcmath library file. */ -/* - Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc. - Copyright (C) 2000 Philip A. Nelson - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. (LICENSE) - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to: - - The Free Software Foundation, Inc. - 59 Temple Place, Suite 330 - Boston, MA 02111-1307 USA. - - You may contact the author by: - e-mail: philnelson@acm.org - us-mail: Philip A. Nelson - Computer Science Department, 9062 - Western Washington University - Bellingham, WA 98226-9062 - -*************************************************************************/ - -#include "bcmath.h" -#include "private.h" - -/* For many things, we may have leading zeros in a number NUM. - _bc_rm_leading_zeros just moves the data "value" pointer to the - correct place and adjusts the length. */ - -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--; - } -} - -void bc_rm_trailing_zeros(bc_num num) -{ - if (num->n_scale == 0) { - return; - } - - char *end = num->n_value + num->n_len + num->n_scale - 1; - while (*end == 0 && num->n_scale > 0) { - num->n_scale--; - end--; - } -}